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 #35459 # 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 working on these - [X] QA'd all new/changed functionality manually ## Screenshots | Option does not appear for FMA apps | | --- | | <img width="723" height="419" alt="image" src="https://github.com/user-attachments/assets/f9f1328e-e38c-452c-b06e-337a69c13e71" /> | | Option does not appear for custom packages | | --- | | <img width="731" height="416" alt="image" src="https://github.com/user-attachments/assets/3de78f15-d7ce-45c7-875f-a250fc00a160" /> | | Option does not appear for macOS VPP apps | | --- | | <img width="725" height="454" alt="image" src="https://github.com/user-attachments/assets/07dcb074-f57d-4cc4-a746-20b80c821fb6" /> | | Option appears iOS VPP apps | | --- | | <img width="727" height="420" alt="image" src="https://github.com/user-attachments/assets/ec4ce503-0300-437c-b3f2-248928fcfe7b" /> | | Option appears iPadOS VPP apps | | --- | | <img width="727" height="422" alt="image" src="https://github.com/user-attachments/assets/0030c6cc-3d93-480c-af93-740fca4d5b57" /> | | Form with auto-updates disabled | | --- | | <img width="668" height="517" alt="image" src="https://github.com/user-attachments/assets/d59a7ba4-dc83-4a80-ba94-0befc7635f05" /> | | Start / end time validation | | --- | | <img width="668" height="679" alt="image" src="https://github.com/user-attachments/assets/939fd09a-76f6-42de-9c71-fe4982f3f84b" /> | | Maintenance window length validation | | --- | | <img width="664" height="681" alt="image" src="https://github.com/user-attachments/assets/a2eab676-5166-42a9-9043-2565014e33cb" /> | | Badge and banner appears after saving | | --- | | <img width="766" height="529" alt="image" src="https://github.com/user-attachments/assets/48d89e1d-4430-4dd7-b8e6-d5b04ebad47f" /> | --------- Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com> Co-authored-by: Nico <32375741+nulmete@users.noreply.github.com>
210 lines
6.7 KiB
TypeScript
210 lines
6.7 KiB
TypeScript
import React from "react";
|
|
import { render, screen } from "@testing-library/react";
|
|
import { noop } from "lodash";
|
|
|
|
import TargetLabelSelector from "./TargetLabelSelector";
|
|
|
|
describe("TargetLabelSelector component", () => {
|
|
describe("renders the custom target selector when the target type is 'Custom'", () => {
|
|
it("with a dropdown when there are custom options to choose from", () => {
|
|
render(
|
|
<TargetLabelSelector
|
|
selectedTargetType="Custom"
|
|
selectedCustomTarget="labelIncludeAny"
|
|
customTargetOptions={[
|
|
{ value: "labelIncludeAny", label: "Include any" },
|
|
]}
|
|
selectedLabels={{}}
|
|
labels={[
|
|
{ id: 1, name: "label 1", label_type: "regular" },
|
|
{ id: 2, name: "label 2", label_type: "regular" },
|
|
]}
|
|
onSelectCustomTarget={noop}
|
|
onSelectLabel={noop}
|
|
onSelectTargetType={noop}
|
|
/>
|
|
);
|
|
|
|
// custom target selector is rendering
|
|
expect(screen.getByRole("option", { name: "Include any" })).toBeVisible();
|
|
|
|
// lables are rendering
|
|
expect(screen.getByRole("checkbox", { name: "label 1" })).toBeVisible();
|
|
expect(screen.getByRole("checkbox", { name: "label 2" })).toBeVisible();
|
|
});
|
|
|
|
it("with an optional message and no dropdown when there are no custom options to choose from", () => {
|
|
const HELP_TEXT = "go boldly where no target has gone before";
|
|
render(
|
|
<TargetLabelSelector
|
|
selectedTargetType="Custom"
|
|
selectedCustomTarget="labelIncludeAny"
|
|
customHelpText={<span>{HELP_TEXT}</span>}
|
|
selectedLabels={{}}
|
|
labels={[
|
|
{ id: 1, name: "label 1", label_type: "regular" },
|
|
{ id: 2, name: "label 2", label_type: "regular" },
|
|
]}
|
|
onSelectCustomTarget={noop}
|
|
onSelectLabel={noop}
|
|
onSelectTargetType={noop}
|
|
/>
|
|
);
|
|
|
|
// custom target help text is visible
|
|
expect(screen.getByText(HELP_TEXT)).toBeVisible();
|
|
|
|
expect(screen.queryByRole("option")).not.toBeInTheDocument();
|
|
|
|
// lables are rendering
|
|
expect(screen.getByRole("checkbox", { name: "label 1" })).toBeVisible();
|
|
expect(screen.getByRole("checkbox", { name: "label 2" })).toBeVisible();
|
|
});
|
|
});
|
|
|
|
it("does not render the custom target selector when the target type is 'All hosts'", () => {
|
|
render(
|
|
<TargetLabelSelector
|
|
selectedTargetType="All hosts"
|
|
selectedCustomTarget="labelIncludeAny"
|
|
customTargetOptions={[
|
|
{ value: "labelIncludeAny", label: "Include any" },
|
|
]}
|
|
selectedLabels={{}}
|
|
labels={[
|
|
{ id: 1, name: "label 1", label_type: "regular" },
|
|
{ id: 2, name: "label 2", label_type: "regular" },
|
|
]}
|
|
onSelectCustomTarget={noop}
|
|
onSelectLabel={noop}
|
|
onSelectTargetType={noop}
|
|
/>
|
|
);
|
|
|
|
// custom target selector is not rendering
|
|
expect(screen.queryByRole("option", { name: "Include any" })).toBeNull();
|
|
|
|
// lables are not rendering
|
|
expect(screen.queryByRole("checkbox", { name: "label 1" })).toBeNull();
|
|
expect(screen.queryByRole("checkbox", { name: "label 2" })).toBeNull();
|
|
});
|
|
|
|
it("renders selected labels as checked", () => {
|
|
render(
|
|
<TargetLabelSelector
|
|
selectedTargetType="Custom"
|
|
selectedCustomTarget="labelIncludeAny"
|
|
customTargetOptions={[
|
|
{ value: "labelIncludeAny", label: "Include any" },
|
|
]}
|
|
selectedLabels={{ "label 1": true, "label 2": false }}
|
|
labels={[
|
|
{ id: 1, name: "label 1", label_type: "regular" },
|
|
{ id: 2, name: "label 2", label_type: "regular" },
|
|
]}
|
|
onSelectCustomTarget={noop}
|
|
onSelectLabel={noop}
|
|
onSelectTargetType={noop}
|
|
/>
|
|
);
|
|
|
|
// lables are rendering
|
|
expect(screen.getByRole("checkbox", { name: "label 1" })).toBeChecked();
|
|
expect(screen.getByRole("checkbox", { name: "label 2" })).not.toBeChecked();
|
|
});
|
|
|
|
it("sets the title to Target by default", () => {
|
|
const TITLE = "Target";
|
|
render(
|
|
<TargetLabelSelector
|
|
selectedTargetType="Custom"
|
|
selectedCustomTarget="labelIncludeAny"
|
|
customTargetOptions={[
|
|
{ value: "labelIncludeAny", label: "Include any" },
|
|
]}
|
|
selectedLabels={{}}
|
|
labels={[
|
|
{ id: 1, name: "label 1", label_type: "regular" },
|
|
{ id: 2, name: "label 2", label_type: "regular" },
|
|
]}
|
|
onSelectCustomTarget={noop}
|
|
onSelectLabel={noop}
|
|
onSelectTargetType={noop}
|
|
title={TITLE}
|
|
/>
|
|
);
|
|
|
|
expect(screen.getByText(TITLE)).toBeVisible();
|
|
});
|
|
|
|
it("allows a custom title to be passed in", () => {
|
|
const TITLE = "Choose a target";
|
|
render(
|
|
<TargetLabelSelector
|
|
selectedTargetType="Custom"
|
|
selectedCustomTarget="labelIncludeAny"
|
|
customTargetOptions={[
|
|
{ value: "labelIncludeAny", label: "Include any" },
|
|
]}
|
|
selectedLabels={{}}
|
|
labels={[
|
|
{ id: 1, name: "label 1", label_type: "regular" },
|
|
{ id: 2, name: "label 2", label_type: "regular" },
|
|
]}
|
|
onSelectCustomTarget={noop}
|
|
onSelectLabel={noop}
|
|
onSelectTargetType={noop}
|
|
title={TITLE}
|
|
/>
|
|
);
|
|
|
|
expect(screen.getByText(TITLE)).toBeVisible();
|
|
});
|
|
|
|
it("suppresses the title when suppressTitle is true", () => {
|
|
render(
|
|
<TargetLabelSelector
|
|
selectedTargetType="Custom"
|
|
selectedCustomTarget="labelIncludeAny"
|
|
customTargetOptions={[
|
|
{ value: "labelIncludeAny", label: "Include any" },
|
|
]}
|
|
selectedLabels={{}}
|
|
labels={[
|
|
{ id: 1, name: "label 1", label_type: "regular" },
|
|
{ id: 2, name: "label 2", label_type: "regular" },
|
|
]}
|
|
onSelectCustomTarget={noop}
|
|
onSelectLabel={noop}
|
|
onSelectTargetType={noop}
|
|
suppressTitle
|
|
/>
|
|
);
|
|
|
|
expect(screen.queryByText("Target")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("allows a subtitle to be passed in", () => {
|
|
const SUBTITLE = "Select one of the following options";
|
|
render(
|
|
<TargetLabelSelector
|
|
selectedTargetType="Custom"
|
|
selectedCustomTarget="labelIncludeAny"
|
|
customTargetOptions={[
|
|
{ value: "labelIncludeAny", label: "Include any" },
|
|
]}
|
|
selectedLabels={{}}
|
|
labels={[
|
|
{ id: 1, name: "label 1", label_type: "regular" },
|
|
{ id: 2, name: "label 2", label_type: "regular" },
|
|
]}
|
|
onSelectCustomTarget={noop}
|
|
onSelectLabel={noop}
|
|
onSelectTargetType={noop}
|
|
subTitle={SUBTITLE}
|
|
/>
|
|
);
|
|
|
|
expect(screen.getByText(SUBTITLE)).toBeVisible();
|
|
});
|
|
});
|