mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
Covers #36760, #36758. # 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. - [x] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) ## Testing - [x] Added/updated automated tests - [x] Where appropriate, [automated tests simulate multiple hosts and test for host isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing) (updates to one hosts's records do not affect another) - [ ] QA'd all new/changed functionality manually
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import React from "react";
|
|
import { noop } from "lodash";
|
|
import { screen } from "@testing-library/react";
|
|
|
|
import { createCustomRenderer } from "test/test-utils";
|
|
import createMockHost from "__mocks__/hostMock";
|
|
|
|
import ManualLabelForm, {
|
|
LABEL_TARGET_HOSTS_INPUT_LABEL,
|
|
} from "./ManualLabelForm";
|
|
|
|
describe("ManualLabelForm", () => {
|
|
it("should render a Select Hosts input", () => {
|
|
const render = createCustomRenderer({ withBackendMock: true });
|
|
|
|
render(<ManualLabelForm onSave={noop} onCancel={noop} teamName={null} />);
|
|
|
|
expect(
|
|
screen.getByText(LABEL_TARGET_HOSTS_INPUT_LABEL)
|
|
).toBeInTheDocument();
|
|
});
|
|
|
|
it("should pass up the form data when the form is submitted and valid", async () => {
|
|
const render = createCustomRenderer({ withBackendMock: true });
|
|
const onSave = jest.fn();
|
|
|
|
const name = "Test Name";
|
|
const description = "Test Description";
|
|
const targetedHosts = [createMockHost()];
|
|
|
|
const { user } = render(
|
|
<ManualLabelForm
|
|
onSave={onSave}
|
|
onCancel={noop}
|
|
defaultTargetedHosts={targetedHosts}
|
|
teamName={null}
|
|
/>
|
|
);
|
|
|
|
await user.type(screen.getByLabelText("Name"), name);
|
|
await user.type(screen.getByLabelText("Description"), description);
|
|
await user.click(screen.getByRole("button", { name: "Save" }));
|
|
|
|
expect(onSave).toHaveBeenCalledWith({
|
|
name,
|
|
description,
|
|
targetedHosts,
|
|
});
|
|
});
|
|
});
|