Add UI templates for activities related to macos_setup_assistant (#11323)

This commit is contained in:
Roberto Dip 2023-04-26 13:02:40 -03:00 committed by GitHub
parent 1208c0151e
commit 902c80b116
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 115 additions and 1 deletions

View File

@ -39,6 +39,8 @@ export enum ActivityType {
EditedMacOSProfile = "edited_macos_profile",
EnabledMacDiskEncryption = "enabled_macos_disk_encryption",
DisabledMacDiskEncryption = "disabled_macos_disk_encryption",
ChangedMacOSSetupAssistant = "changed_macos_setup_assistant",
DeletedMacOSSetupAssistant = "deleted_macos_setup_assistant",
}
export interface IActivity {
created_at: string;
@ -75,4 +77,5 @@ export interface IActivityDetails {
deadline?: string;
profile_name?: string;
profile_identifier?: string;
name?: string;
}

View File

@ -1,5 +1,5 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import { render, screen, getDefaultNormalizer } from "@testing-library/react";
import createMockActivity from "__mocks__/activityMock";
import createMockQuery from "__mocks__/queryMock";
@ -420,4 +420,72 @@ describe("Activity Feed", () => {
).toBeInTheDocument();
expect(screen.queryByText("assigned to the")).toBeNull();
});
it("renders a 'changed_macos_setup_assistant' type activity for no team", () => {
const activity = createMockActivity({
type: ActivityType.ChangedMacOSSetupAssistant,
details: { name: "dep-profile.json" },
});
render(<ActivityItem activity={activity} isPremiumTier />);
expect(
screen.getByText((content, node) => {
return (
node?.innerHTML ===
"<b>Test User </b> changed the macOS Setup Assistant (added <b>dep-profile.json</b>) for hosts that automatically enroll to no team."
);
})
).toBeInTheDocument();
});
it("renders a 'changed_macos_setup_assistant' type activity for a team", () => {
const activity = createMockActivity({
type: ActivityType.ChangedMacOSSetupAssistant,
details: { name: "dep-profile.json", team_name: "Workstations" },
});
render(<ActivityItem activity={activity} isPremiumTier />);
expect(
screen.getByText((content, node) => {
return (
node?.innerHTML ===
"<b>Test User </b> changed the macOS Setup Assistant (added <b>dep-profile.json</b>) for hosts that automatically enroll to the <b>Workstations</b> team."
);
})
).toBeInTheDocument();
});
it("renders a 'deleted_macos_setup_assistant' type activity for no team", () => {
const activity = createMockActivity({
type: ActivityType.DeletedMacOSSetupAssistant,
details: { name: "dep-profile.json" },
});
render(<ActivityItem activity={activity} isPremiumTier />);
expect(
screen.getByText((content, node) => {
return (
node?.innerHTML ===
"<b>Test User </b> changed the macOS Setup Assistant (deleted <b>dep-profile.json</b>) for hosts that automatically enroll to no team."
);
})
).toBeInTheDocument();
});
it("renders a 'deleted_macos_setup_assistant' type activity for a team", () => {
const activity = createMockActivity({
type: ActivityType.DeletedMacOSSetupAssistant,
details: { name: "dep-profile.json", team_name: "Workstations" },
});
render(<ActivityItem activity={activity} isPremiumTier />);
expect(
screen.getByText((content, node) => {
return (
node?.innerHTML ===
"<b>Test User </b> changed the macOS Setup Assistant (deleted <b>dep-profile.json</b>) for hosts that automatically enroll to the <b>Workstations</b> team."
);
})
).toBeInTheDocument();
});
});

View File

@ -40,6 +40,29 @@ const getDiskEncryptionMessageSuffix = (teamName?: string | null) => {
);
};
const getMacOSSetupAssistantMessage = (
action: "added" | "deleted",
name?: string,
teamName?: string | null
) => {
const suffix = teamName ? (
<>
{" "}
that automatically enroll to the <b>{teamName}</b> team
</>
) : (
<>that automatically enroll to no team</>
);
return (
<>
{" "}
changed the macOS Setup Assistant ({action} <b>{name}</b>) for hosts{" "}
{suffix}.
</>
);
};
const TAGGED_TEMPLATES = {
liveQueryActivityTemplate: (
activity: IActivity,
@ -293,6 +316,20 @@ const TAGGED_TEMPLATES = {
const suffix = getDiskEncryptionMessageSuffix(activity.details?.team_name);
return <>removed disk encryption enforcement for macOS hosts {suffix}.</>;
},
changedMacOSSetupAssistant: (activity: IActivity) => {
return getMacOSSetupAssistantMessage(
"added",
activity.details?.name,
activity.details?.team_name
);
},
deletedMacOSSetupAssistant: (activity: IActivity) => {
return getMacOSSetupAssistantMessage(
"deleted",
activity.details?.name,
activity.details?.team_name
);
},
defaultActivityTemplate: (activity: IActivity) => {
const entityName = find(activity.details, (_, key) =>
key.includes("_name")
@ -391,6 +428,12 @@ const getDetail = (
case ActivityType.DisabledMacDiskEncryption: {
return TAGGED_TEMPLATES.disableMacDiskEncryption(activity);
}
case ActivityType.ChangedMacOSSetupAssistant: {
return TAGGED_TEMPLATES.changedMacOSSetupAssistant(activity);
}
case ActivityType.DeletedMacOSSetupAssistant: {
return TAGGED_TEMPLATES.deletedMacOSSetupAssistant(activity);
}
default: {
return TAGGED_TEMPLATES.defaultActivityTemplate(activity);
}