fleet/frontend/pages/hosts/details/cards/Software/HostSoftwareTable/HostSoftwareTable.tests.tsx
jacobshandling 166e5ed663
UI: Batch script run detail page (#32333)
## For #31226 

New features:
- Dynamic header for each possible state of a batch script run: Started,
Scheduled, and Finished (corresponds to tabs at
`/controls/scripts/progress`
- Unique tabs for each possible status of hosts targeted by a batch
script run: Ran, Errored, Pending, Incompatible, Canceled.
- Within each tab, sortable, paginated host results with output preview
and execution time.
- View script/run details, cancel a batch, view manage hosts page
filtered for the script batch run and a status.
- Global script batch runs activities and and Scripts progress rows now
navigate to this details page.

Cleanups and improvements:
- Expand tab count badge options using “alert”/“pending” variants across
hosts, policies, and query results.
- Misc cleanups and improvements


![ezgif-1438d4041f694f](https://github.com/user-attachments/assets/2d93127b-dea4-4ca6-abcc-7c888b2e0b93)


- [x] Changes file added for user-visible changes in `changes/`,


- [x] Updated automated tests - new tests tracked for follow-up work
- [x] QA'd all new/changed functionality manually

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-08-29 09:37:05 -06:00

94 lines
2.8 KiB
TypeScript

import React from "react";
import { screen } from "@testing-library/react";
import { createCustomRenderer, createMockRouter } from "test/test-utils";
import { noop } from "lodash";
import { HostPlatform } from "interfaces/platform";
import createMockUser from "__mocks__/userMock";
import { createMockGetHostSoftwareResponse } from "__mocks__/hostMock";
import HostSoftwareTable from "./HostSoftwareTable";
const mockRouter = createMockRouter();
describe("HostSoftwareTable", () => {
const baseProps = {
tableConfig: [],
data: createMockGetHostSoftwareResponse(),
platform: "windows" as HostPlatform,
isLoading: false,
router: mockRouter,
sortHeader: "name",
sortDirection: "asc" as "asc" | "desc",
searchQuery: "",
page: 0,
pagePath: "/hosts/1/software",
vulnFilters: {},
onAddFiltersClick: noop,
onShowInventoryVersions: noop,
};
const renderWithContext = (props = {}) =>
createCustomRenderer({
context: {
app: {
isGlobalAdmin: true,
currentUser: createMockUser(),
},
},
})(<HostSoftwareTable {...baseProps} {...props} />);
it("renders the empty state when no software is detected", () => {
renderWithContext({
data: createMockGetHostSoftwareResponse({
count: 0,
software: [],
}),
});
expect(screen.getByText(/no software detected/i)).toBeInTheDocument();
});
it("renders the Android not supported state", () => {
renderWithContext({ platform: "android" });
expect(
screen.getByText(/software is not supported for this host/i)
).toBeInTheDocument();
expect(screen.getByText(/let us know/i)).toBeInTheDocument();
expect(
screen.queryByText(/Software installed on this host/i)
).not.toBeInTheDocument();
});
it("renders custom filter button when filters are applied", () => {
renderWithContext({
vulnFilters: { vulnerable: true },
});
expect(screen.getByRole("button", { name: /filter/i })).toBeInTheDocument();
});
it("renders VulnsNotSupported when vulns filter applied and platform is iPad/iPhone", () => {
renderWithContext({
platform: "ipados",
vulnFilters: { vulnerable: true },
data: createMockGetHostSoftwareResponse({
count: 0,
software: [],
}),
});
expect(
screen.getByText(/vulnerabilities are not supported/i)
).toBeInTheDocument();
});
// This includes empty state for BYOD iphone/ipads
it("renders generic empty state when no filters are applied and platform is iPad/iPhone", () => {
renderWithContext({
platform: "ipados",
data: createMockGetHostSoftwareResponse({
count: 0,
software: [],
}),
});
expect(screen.getByText(/no software detected/i)).toBeInTheDocument();
});
});