fleet/frontend/pages/labels/components/DynamicLabelForm/DynamicLabelForm.tests.tsx
Ian Littman 8e4e89f4e9
API + auth + UI changes for team labels (#37208)
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
2025-12-29 21:28:45 -06:00

46 lines
1.3 KiB
TypeScript

import React from "react";
import { noop } from "lodash";
import { render, screen } from "@testing-library/react";
import { renderWithSetup } from "test/test-utils";
import DynamicLabelForm from "./DynamicLabelForm";
describe("DynamicLabelForm", () => {
it("should render the Fleet Ace and Select Platform input", () => {
render(<DynamicLabelForm onSave={noop} onCancel={noop} teamName={null} />);
expect(screen.getByText("Query")).toBeInTheDocument();
expect(screen.getByText("All platforms")).toBeInTheDocument();
});
it("should pass up the form data when the form is submitted and valid", async () => {
const onSave = jest.fn();
const name = "Test Name";
const description = "Test Description";
const query = "SELECT * FROM users;";
const platform = "darwin";
const { user } = renderWithSetup(
<DynamicLabelForm
onSave={onSave}
onCancel={noop}
defaultQuery={query}
defaultPlatform={platform}
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,
query,
platform,
});
});
});