Add some tests; minor cleaning (#10582)

This commit is contained in:
Jacob Shandling 2023-03-20 08:38:44 -07:00 committed by GitHub
parent bbc16ef180
commit def8fd1309
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 90 additions and 14 deletions

View File

@ -347,4 +347,77 @@ describe("Activity Feed", () => {
const forAllTeams = screen.queryByText("for all teams.");
expect(forAllTeams).toBeNull();
});
it("renders an 'enabled_macos_disk_encryption' type activity for a team", () => {
const activity = createMockActivity({
type: ActivityType.EnabledMacDiskEncryption,
details: { team_name: "Alphas" },
});
render(<ActivityItem activity={activity} isPremiumTier />);
expect(
screen.getByText(
"enforced disk encryption for macOS hosts assigned to the",
{
exact: false,
}
)
).toBeInTheDocument();
expect(screen.getByText("Alphas")).toBeInTheDocument();
expect(screen.getByText(" team.", { exact: false })).toBeInTheDocument();
const withNoTeams = screen.queryByText("with no team");
expect(withNoTeams).toBeNull();
});
it("renders a 'disabled_macos_disk_encryption' type activity for a team", () => {
const activity = createMockActivity({
type: ActivityType.DisabledMacDiskEncryption,
details: { team_name: "Alphas" },
});
render(<ActivityItem activity={activity} isPremiumTier />);
expect(
screen.getByText(
"removed disk encryption enforcement for macOS hosts assigned to the",
{
exact: false,
}
)
).toBeInTheDocument();
expect(screen.getByText("Alphas")).toBeInTheDocument();
expect(screen.getByText(" team.", { exact: false })).toBeInTheDocument();
const withNoTeams = screen.queryByText("with no team");
expect(withNoTeams).toBeNull();
});
it("renders an 'enabled_macos_disk_encryption' type activity for hosts with no team.", () => {
const activity = createMockActivity({
type: ActivityType.EnabledMacDiskEncryption,
details: {},
});
render(<ActivityItem activity={activity} isPremiumTier />);
expect(
screen.getByText("enforced disk encryption for macOS hosts with no team.")
).toBeInTheDocument();
expect(screen.queryByText("assigned to the")).toBeNull();
});
it("renders a 'disabled_macos_disk_encryption' type activity for hosts with no team.", () => {
const activity = createMockActivity({
type: ActivityType.DisabledMacDiskEncryption,
details: {},
});
render(<ActivityItem activity={activity} isPremiumTier />);
expect(
screen.getByText(
"removed disk encryption enforcement for macOS hosts with no team.",
{
exact: false,
}
)
).toBeInTheDocument();
expect(screen.queryByText("assigned to the")).toBeNull();
});
});

View File

@ -286,22 +286,12 @@ const TAGGED_TEMPLATES = {
);
},
enableMacDiskEncryption: (activity: IActivity) => {
return (
<>
{" "}
enforced disk encryption for macOS hosts{" "}
{getDiskEncryptionMessageSuffix(activity.details?.team_name)}.
</>
);
const suffix = getDiskEncryptionMessageSuffix(activity.details?.team_name);
return <> enforced disk encryption for macOS hosts {suffix}.</>;
},
disableMacDiskEncryption: (activity: IActivity) => {
return (
<>
{" "}
removed disk encryption enforcement for macOS hosts{" "}
{getDiskEncryptionMessageSuffix(activity.details?.team_name)}.
</>
);
const suffix = getDiskEncryptionMessageSuffix(activity.details?.team_name);
return <>removed disk encryption enforcement for macOS hosts {suffix}.</>;
},
defaultActivityTemplate: (activity: IActivity) => {
const entityName = find(activity.details, (_, key) =>

View File

@ -14,6 +14,19 @@ describe("url utilities > reconcileMutuallyInclusiveHostParams", () => {
});
});
it("leaves macSettingsStatus and teamId unchanged when both are present, teamId=0", () => {
const [macSettingsStatus, teamId] = ["pending" as const, 0];
expect(
reconcileMutuallyInclusiveHostParams({
macSettingsStatus,
teamId,
})
).toEqual({
macos_settings: "pending",
team_id: 0,
});
});
it("adds team_id: 0 when macSettingsStatus is present and teamId is not", () => {
const [macSettingsStatus, teamId] = ["pending" as const, undefined];
expect(