mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
[Unreleased bug and Unit tests] Test all disabled dropdown options on host actions dropdown (#18231)
This commit is contained in:
parent
41ef4e3ac0
commit
6b3b159827
3 changed files with 381 additions and 11 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import React from "react";
|
||||
import { noop } from "lodash";
|
||||
import { screen } from "@testing-library/react";
|
||||
import { screen, waitFor } from "@testing-library/react";
|
||||
import { createCustomRenderer } from "test/test-utils";
|
||||
|
||||
import createMockUser from "__mocks__/userMock";
|
||||
|
|
@ -64,6 +64,126 @@ describe("Host Actions Dropdown", () => {
|
|||
expect(screen.getByText("Transfer")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
describe("Query action", () => {
|
||||
it("renders the Query action when the user is a global admin and the host is online", async () => {
|
||||
const render = createCustomRenderer({
|
||||
context: {
|
||||
app: {
|
||||
isGlobalAdmin: true,
|
||||
currentUser: createMockUser(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { user } = render(
|
||||
<HostActionsDropdown
|
||||
hostTeamId={null}
|
||||
onSelect={noop}
|
||||
hostStatus="online"
|
||||
hostMdmEnrollmentStatus={null}
|
||||
hostMdmDeviceStatus="unlocked"
|
||||
hostScriptsEnabled
|
||||
/>
|
||||
);
|
||||
|
||||
await user.click(screen.getByText("Actions"));
|
||||
|
||||
expect(screen.getByText("Query")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the Query action as disabled with a tooltip when a host is offline", async () => {
|
||||
const render = createCustomRenderer({
|
||||
context: {
|
||||
app: {
|
||||
isGlobalAdmin: true,
|
||||
currentUser: createMockUser(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { user } = render(
|
||||
<HostActionsDropdown
|
||||
hostTeamId={null}
|
||||
onSelect={noop}
|
||||
hostStatus="offline"
|
||||
hostMdmEnrollmentStatus={null}
|
||||
hostMdmDeviceStatus="unlocked"
|
||||
hostScriptsEnabled
|
||||
/>
|
||||
);
|
||||
|
||||
await user.click(screen.getByText("Actions"));
|
||||
|
||||
expect(
|
||||
screen.getByText("Query").parentElement?.parentElement?.parentElement
|
||||
).toHaveClass("is-disabled");
|
||||
|
||||
await waitFor(() => {
|
||||
waitFor(() => {
|
||||
user.hover(screen.getByText("Query"));
|
||||
});
|
||||
|
||||
expect(
|
||||
screen.getByText(/You can't query an offline host./i)
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it("renders the Query action as disabled when a host is locked", async () => {
|
||||
const render = createCustomRenderer({
|
||||
context: {
|
||||
app: {
|
||||
isGlobalAdmin: true,
|
||||
currentUser: createMockUser(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { user } = render(
|
||||
<HostActionsDropdown
|
||||
hostTeamId={null}
|
||||
onSelect={noop}
|
||||
hostStatus="offline"
|
||||
hostMdmEnrollmentStatus={null}
|
||||
hostMdmDeviceStatus="locked"
|
||||
hostScriptsEnabled
|
||||
/>
|
||||
);
|
||||
|
||||
await user.click(screen.getByText("Actions"));
|
||||
expect(
|
||||
screen.getByText("Query").parentElement?.parentElement?.parentElement
|
||||
).toHaveClass("is-disabled");
|
||||
});
|
||||
|
||||
it("renders the Query action as disabled when a host is updating", async () => {
|
||||
const render = createCustomRenderer({
|
||||
context: {
|
||||
app: {
|
||||
isGlobalAdmin: true,
|
||||
currentUser: createMockUser(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { user } = render(
|
||||
<HostActionsDropdown
|
||||
hostTeamId={null}
|
||||
onSelect={noop}
|
||||
hostStatus="online"
|
||||
hostMdmEnrollmentStatus={null}
|
||||
hostMdmDeviceStatus="locking"
|
||||
hostScriptsEnabled
|
||||
/>
|
||||
);
|
||||
|
||||
await user.click(screen.getByText("Actions"));
|
||||
|
||||
expect(screen.getByText("Query").parentElement).toHaveClass(
|
||||
"is-disabled"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("renders the Show Disk Encryption Key action when on premium tier and we store the disk encryption key", async () => {
|
||||
const render = createCustomRenderer({
|
||||
|
|
@ -267,7 +387,7 @@ describe("Host Actions Dropdown", () => {
|
|||
|
||||
debug();
|
||||
|
||||
expect(screen.getByText("Turn off MDM").parentNode).toHaveClass(
|
||||
expect(screen.getByText("Turn off MDM").parentElement).toHaveClass(
|
||||
"is-disabled"
|
||||
);
|
||||
});
|
||||
|
|
@ -441,6 +561,48 @@ describe("Host Actions Dropdown", () => {
|
|||
expect(screen.getByText("Lock")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders as disabled with a tooltip when scripts_enabled is set to false for windows/linux", async () => {
|
||||
const render = createCustomRenderer({
|
||||
context: {
|
||||
app: {
|
||||
isPremiumTier: true,
|
||||
isMacMdmEnabledAndConfigured: true,
|
||||
isGlobalAdmin: true,
|
||||
currentUser: createMockUser(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { user } = render(
|
||||
<HostActionsDropdown
|
||||
hostTeamId={null}
|
||||
onSelect={noop}
|
||||
hostStatus="online"
|
||||
hostMdmEnrollmentStatus="On (automatic)"
|
||||
mdmName="Fleet"
|
||||
hostPlatform="debian"
|
||||
hostMdmDeviceStatus="unlocked"
|
||||
hostScriptsEnabled={false}
|
||||
/>
|
||||
);
|
||||
|
||||
await user.click(screen.getByText("Actions"));
|
||||
|
||||
expect(
|
||||
screen.getByText("Lock").parentElement?.parentElement?.parentElement
|
||||
).toHaveClass("is-disabled");
|
||||
|
||||
await waitFor(() => {
|
||||
waitFor(() => {
|
||||
user.hover(screen.getByText("Lock"));
|
||||
});
|
||||
|
||||
expect(
|
||||
screen.getByText(/fleetd agent with --enable-scripts/i)
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it("does not render when the host is not enrolled in mdm", async () => {
|
||||
const render = createCustomRenderer({
|
||||
context: {
|
||||
|
|
@ -653,6 +815,48 @@ describe("Host Actions Dropdown", () => {
|
|||
|
||||
expect(screen.queryByText("Unlock")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders as disabled with a tooltip when scripts_enabled is set to false for windows/linux", async () => {
|
||||
const render = createCustomRenderer({
|
||||
context: {
|
||||
app: {
|
||||
isPremiumTier: true,
|
||||
isMacMdmEnabledAndConfigured: true,
|
||||
isGlobalAdmin: true,
|
||||
currentUser: createMockUser(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { user } = render(
|
||||
<HostActionsDropdown
|
||||
hostTeamId={null}
|
||||
onSelect={noop}
|
||||
hostStatus="offline"
|
||||
hostMdmEnrollmentStatus="On (automatic)"
|
||||
mdmName="Fleet"
|
||||
hostPlatform="windows"
|
||||
hostMdmDeviceStatus="locked"
|
||||
hostScriptsEnabled={false}
|
||||
/>
|
||||
);
|
||||
|
||||
await user.click(screen.getByText("Actions"));
|
||||
|
||||
expect(
|
||||
screen.getByText("Unlock").parentElement?.parentElement?.parentElement
|
||||
).toHaveClass("is-disabled");
|
||||
|
||||
await waitFor(() => {
|
||||
waitFor(() => {
|
||||
user.hover(screen.getByText("Unlock"));
|
||||
});
|
||||
|
||||
expect(
|
||||
screen.getByText(/fleetd agent with --enable-scripts/i)
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Wipe action", () => {
|
||||
|
|
@ -747,5 +951,145 @@ describe("Host Actions Dropdown", () => {
|
|||
|
||||
expect(screen.queryByText("Wipe")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders as disabled with a tooltip when scripts_enabled is set to false for linux", async () => {
|
||||
const render = createCustomRenderer({
|
||||
context: {
|
||||
app: {
|
||||
isPremiumTier: true,
|
||||
isMacMdmEnabledAndConfigured: true,
|
||||
isGlobalAdmin: true,
|
||||
currentUser: createMockUser(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { user } = render(
|
||||
<HostActionsDropdown
|
||||
hostTeamId={null}
|
||||
onSelect={noop}
|
||||
hostStatus="online"
|
||||
hostMdmEnrollmentStatus="On (automatic)"
|
||||
mdmName="Fleet"
|
||||
hostPlatform="debian"
|
||||
hostMdmDeviceStatus="unlocked"
|
||||
hostScriptsEnabled={false}
|
||||
/>
|
||||
);
|
||||
|
||||
await user.click(screen.getByText("Actions"));
|
||||
|
||||
expect(
|
||||
screen.getByText("Wipe").parentElement?.parentElement?.parentElement
|
||||
).toHaveClass("is-disabled");
|
||||
|
||||
await waitFor(() => {
|
||||
waitFor(() => {
|
||||
user.hover(screen.getByText("Wipe"));
|
||||
});
|
||||
|
||||
expect(
|
||||
screen.getByText(/fleetd agent with --enable-scripts/i)
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Run script action", () => {
|
||||
it("renders the Run script action when scripts_enabled is set to true", async () => {
|
||||
const render = createCustomRenderer({
|
||||
context: {
|
||||
app: {
|
||||
isGlobalAdmin: true,
|
||||
currentUser: createMockUser(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { user } = render(
|
||||
<HostActionsDropdown
|
||||
hostTeamId={null}
|
||||
onSelect={noop}
|
||||
hostStatus="offline"
|
||||
mdmName="Fleet"
|
||||
hostPlatform="windows"
|
||||
hostMdmEnrollmentStatus={null}
|
||||
hostMdmDeviceStatus="unlocked"
|
||||
hostScriptsEnabled
|
||||
/>
|
||||
);
|
||||
|
||||
await user.click(screen.getByText("Actions"));
|
||||
|
||||
expect(screen.getByText("Run script")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the Run script action as disabled with a tooltip when scripts_enabled is set to false", async () => {
|
||||
const render = createCustomRenderer({
|
||||
context: {
|
||||
app: {
|
||||
isGlobalAdmin: true,
|
||||
currentUser: createMockUser(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { user } = render(
|
||||
<HostActionsDropdown
|
||||
hostTeamId={null}
|
||||
onSelect={noop}
|
||||
hostStatus="online"
|
||||
mdmName="Fleet"
|
||||
hostPlatform="darwin"
|
||||
hostMdmEnrollmentStatus={null}
|
||||
hostMdmDeviceStatus="unlocked"
|
||||
hostScriptsEnabled={false}
|
||||
/>
|
||||
);
|
||||
|
||||
await user.click(screen.getByText("Actions"));
|
||||
|
||||
expect(
|
||||
screen.getByText("Run script").parentElement?.parentElement
|
||||
?.parentElement
|
||||
).toHaveClass("is-disabled");
|
||||
|
||||
await waitFor(() => {
|
||||
waitFor(() => {
|
||||
user.hover(screen.getByText("Run script"));
|
||||
});
|
||||
|
||||
expect(
|
||||
screen.getByText(/fleetd agent with --enable-scripts/i)
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it("does not render the Run script action for ChromeOS", async () => {
|
||||
const render = createCustomRenderer({
|
||||
context: {
|
||||
app: {
|
||||
isGlobalAdmin: true,
|
||||
currentUser: createMockUser(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { user } = render(
|
||||
<HostActionsDropdown
|
||||
hostTeamId={null}
|
||||
onSelect={noop}
|
||||
hostStatus="online"
|
||||
hostPlatform="chrome"
|
||||
hostMdmEnrollmentStatus={null}
|
||||
hostMdmDeviceStatus={"unlocked"}
|
||||
hostScriptsEnabled={false}
|
||||
/>
|
||||
);
|
||||
|
||||
await user.click(screen.getByText("Actions"));
|
||||
|
||||
expect(screen.queryByText("Run script")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -290,6 +290,7 @@ const setOptionsAsDisabled = (
|
|||
isSandboxMode,
|
||||
hostMdmDeviceStatus,
|
||||
hostScriptsEnabled,
|
||||
hostPlatform,
|
||||
}: IHostActionConfigOptions
|
||||
) => {
|
||||
// Available tooltips for disabled options
|
||||
|
|
@ -339,6 +340,23 @@ const setOptionsAsDisabled = (
|
|||
optionsToDisable = optionsToDisable.concat(
|
||||
options.filter((option) => option.value === "runScript")
|
||||
);
|
||||
if (isLinuxLike(hostPlatform)) {
|
||||
optionsToDisable = optionsToDisable.concat(
|
||||
options.filter(
|
||||
(option) =>
|
||||
option.value === "lock" ||
|
||||
option.value === "unlock" ||
|
||||
option.value === "wipe"
|
||||
)
|
||||
);
|
||||
}
|
||||
if (hostPlatform === "windows") {
|
||||
optionsToDisable = optionsToDisable.concat(
|
||||
options.filter(
|
||||
(option) => option.value === "lock" || option.value === "unlock"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
if (isSandboxMode) {
|
||||
optionsToDisable = optionsToDisable.concat(
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import React from "react";
|
||||
import { screen } from "@testing-library/react";
|
||||
import { screen, waitFor } from "@testing-library/react";
|
||||
import { createCustomRenderer } from "test/test-utils";
|
||||
|
||||
import createMockPolicy from "__mocks__/policyMock";
|
||||
|
|
@ -123,11 +123,15 @@ describe("PolicyForm - component", () => {
|
|||
expect(screen.getByRole("button", { name: "Save" })).toBeDisabled();
|
||||
expect(screen.getByRole("button", { name: "Run" })).toBeDisabled();
|
||||
|
||||
await user.hover(screen.getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => {
|
||||
waitFor(() => {
|
||||
user.hover(screen.getByRole("button", { name: "Save" }));
|
||||
});
|
||||
|
||||
expect(container.querySelector("#save-policy-button")).toHaveTextContent(
|
||||
/to save or run the policy/i
|
||||
);
|
||||
expect(container.querySelector("#save-policy-button")).toHaveTextContent(
|
||||
/to save or run the policy/i
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("disables run button with tooltip when live queries are globally disabled", async () => {
|
||||
|
|
@ -190,11 +194,15 @@ describe("PolicyForm - component", () => {
|
|||
|
||||
expect(screen.getByRole("button", { name: "Run" })).toBeDisabled();
|
||||
|
||||
await user.hover(screen.getByRole("button", { name: "Run" }));
|
||||
await waitFor(() => {
|
||||
waitFor(() => {
|
||||
user.hover(screen.getByRole("button", { name: "Run" }));
|
||||
});
|
||||
|
||||
expect(container.querySelector("#run-policy-button")).toHaveTextContent(
|
||||
/live queries are disabled/i
|
||||
);
|
||||
expect(
|
||||
screen.getByText(/live queries are disabled/i)
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: Consider testing save button is disabled for a sql error
|
||||
|
|
|
|||
Loading…
Reference in a new issue