-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fleet UI: Disable install/uninstall actions if scripts are disabled (#…
- Loading branch information
1 parent
fc8b1d6
commit d7594d1
Showing
5 changed files
with
156 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
frontend/pages/hosts/details/cards/Software/HostSoftwareTableConfig.tests.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { | ||
generateActions, | ||
DEFAULT_ACTION_OPTIONS, | ||
generateActionsProps, | ||
} from "./HostSoftwareTableConfig"; | ||
|
||
describe("generateActions", () => { | ||
const defaultProps: generateActionsProps = { | ||
userHasSWWritePermission: true, | ||
hostScriptsEnabled: true, | ||
hostCanWriteSoftware: true, | ||
softwareIdActionPending: null, | ||
softwareId: 1, | ||
status: null, | ||
software_package: null, | ||
app_store_app: null, | ||
}; | ||
|
||
it("returns default actions when user has write permission and scripts are enabled", () => { | ||
const actions = generateActions(defaultProps); | ||
expect(actions).toEqual(DEFAULT_ACTION_OPTIONS); | ||
}); | ||
|
||
it("removes install and uninstall actions when user has no write permission", () => { | ||
const props = { ...defaultProps, userHasSWWritePermission: false }; | ||
const actions = generateActions(props); | ||
expect(actions.find((a) => a.value === "install")).toBeUndefined(); | ||
expect(actions.find((a) => a.value === "uninstall")).toBeUndefined(); | ||
}); | ||
|
||
it("disables install and uninstall actions when host scripts are disabled", () => { | ||
const props = { ...defaultProps, hostScriptsEnabled: false }; | ||
const actions = generateActions(props); | ||
expect(actions.find((a) => a.value === "install")?.disabled).toBe(true); | ||
expect(actions.find((a) => a.value === "uninstall")?.disabled).toBe(true); | ||
}); | ||
|
||
it("disables install and uninstall actions when locally pending (waiting for API response)", () => { | ||
const props = { | ||
...defaultProps, | ||
softwareIdActionPending: 1, | ||
softwareId: 1, | ||
}; | ||
const actions = generateActions(props); | ||
expect(actions.find((a) => a.value === "install")?.disabled).toBe(true); | ||
expect(actions.find((a) => a.value === "uninstall")?.disabled).toBe(true); | ||
}); | ||
|
||
it("disables install and uninstall actions when pending install status", () => { | ||
const props: generateActionsProps = { | ||
...defaultProps, | ||
status: "pending_install", | ||
}; | ||
const actions = generateActions(props); | ||
expect(actions.find((a) => a.value === "install")?.disabled).toBe(true); | ||
expect(actions.find((a) => a.value === "uninstall")?.disabled).toBe(true); | ||
}); | ||
|
||
it("disables install and uninstall actions when pending uninstall status", () => { | ||
const props: generateActionsProps = { | ||
...defaultProps, | ||
status: "pending_uninstall", | ||
}; | ||
const actions = generateActions(props); | ||
expect(actions.find((a) => a.value === "install")?.disabled).toBe(true); | ||
expect(actions.find((a) => a.value === "uninstall")?.disabled).toBe(true); | ||
}); | ||
|
||
it("removes uninstall action for VPP apps", () => { | ||
const props: generateActionsProps = { | ||
...defaultProps, | ||
app_store_app: { | ||
app_store_id: "1", | ||
self_service: false, | ||
icon_url: "", | ||
version: "", | ||
last_install: { command_uuid: "", installed_at: "" }, | ||
}, | ||
}; | ||
const actions = generateActions(props); | ||
expect(actions.find((a) => a.value === "uninstall")).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters