mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #40317 # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. ## Testing - [ ] Added/updated automated tests With the current router we have in place, we can't really test `<Link>` elements, so our ability to make useful automated tests is pretty limited here. I extracted the fleet name sorting code into an exported function and added some tests for that. - [X] QA'd all new/changed functionality manually - [X] verified that when All Fleets is selected in dropdown, navigating to Controls switches to Workstations - [X] verified that when another fleet is selected in dropdown, navigating to Controls maintains that selection - [X] verified that when a fleet is selected in dropdown, navigating to the dashboard changes to All Fleets - [X] verified that when "Unassigned" is present in the fleets dropdown, it is at the bottom - [X] verified that when using a permalink to the dashboard with a fleet selected (e.g. `?fleet_id=1`), the correct fleet shows as selected
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import createMockUser from "__mocks__/userMock";
|
|
|
|
import { sortAvailableTeams } from "./app";
|
|
|
|
describe("sortAvailableTeams", () => {
|
|
it("places Unassigned last for global team users", () => {
|
|
const teams = [
|
|
{ id: 0, name: "Unassigned" },
|
|
{ id: 2, name: "Zebra" },
|
|
{ id: 1, name: "Alpha" },
|
|
{ id: -1, name: "All fleets" },
|
|
];
|
|
const result = sortAvailableTeams(teams, createMockUser());
|
|
expect(result.map((t) => t.name)).toEqual([
|
|
"All fleets",
|
|
"Alpha",
|
|
"Zebra",
|
|
"Unassigned",
|
|
]);
|
|
});
|
|
|
|
it("does not include All fleets or Unassigned for non-global users", () => {
|
|
const teams = [
|
|
{ id: 0, name: "Unassigned" },
|
|
{ id: 2, name: "Zebra" },
|
|
{ id: 1, name: "Alpha" },
|
|
{ id: -1, name: "All fleets" },
|
|
];
|
|
const result = sortAvailableTeams(
|
|
teams,
|
|
createMockUser({ global_role: null })
|
|
);
|
|
expect(result.map((t) => t.name)).toEqual(["Alpha", "Zebra"]);
|
|
});
|
|
|
|
it("sorts named teams alphabetically (case-insensitive)", () => {
|
|
const teams = [
|
|
{ id: 3, name: "charlie" },
|
|
{ id: 1, name: "Alpha" },
|
|
{ id: 2, name: "Bravo" },
|
|
];
|
|
const result = sortAvailableTeams(
|
|
teams,
|
|
createMockUser({ global_role: null })
|
|
);
|
|
expect(result.map((t) => t.name)).toEqual(["Alpha", "Bravo", "charlie"]);
|
|
});
|
|
});
|