2021-04-12 13:32:25 +00:00
|
|
|
import React from "react";
|
2022-03-31 16:49:50 +00:00
|
|
|
import { fireEvent, render, screen } from "@testing-library/react";
|
2016-10-27 16:14:30 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
import { hostStub, labelStub } from "test/stubs";
|
|
|
|
|
import TargetOption from "./TargetOption";
|
2016-10-27 16:14:30 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
describe("TargetOption - component", () => {
|
2022-03-31 16:49:50 +00:00
|
|
|
const onMoreInfoClickSpy = jest.fn();
|
|
|
|
|
const onMoreInfoClick = () => {
|
|
|
|
|
return onMoreInfoClickSpy;
|
|
|
|
|
};
|
2021-04-12 13:32:25 +00:00
|
|
|
it("renders a label option for label targets", () => {
|
2017-01-20 17:02:13 +00:00
|
|
|
const count = 5;
|
2022-03-31 16:49:50 +00:00
|
|
|
const { container } = render(
|
|
|
|
|
<TargetOption
|
|
|
|
|
onMoreInfoClick={onMoreInfoClick}
|
|
|
|
|
target={{ ...labelStub, count }}
|
|
|
|
|
/>
|
2021-04-12 13:32:25 +00:00
|
|
|
);
|
2022-03-31 16:49:50 +00:00
|
|
|
expect(container.querySelectorAll(".is-label").length).toEqual(1);
|
|
|
|
|
expect(screen.getByText(`${count} hosts`)).toBeInTheDocument();
|
2016-10-27 16:14:30 +00:00
|
|
|
});
|
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
it("renders a host option for host targets", () => {
|
2022-03-31 16:49:50 +00:00
|
|
|
const { container } = render(
|
2021-04-12 13:32:25 +00:00
|
|
|
<TargetOption
|
2022-03-31 16:49:50 +00:00
|
|
|
onMoreInfoClick={onMoreInfoClick}
|
2021-04-12 13:32:25 +00:00
|
|
|
target={{ ...hostStub, platform: "windows" }}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2022-03-31 16:49:50 +00:00
|
|
|
expect(container.querySelectorAll(".is-host").length).toEqual(1);
|
|
|
|
|
expect(container.querySelectorAll("i.fleeticon-windows").length).toEqual(1);
|
|
|
|
|
expect(screen.getByText(hostStub.primary_ip)).toBeInTheDocument();
|
2016-10-27 16:14:30 +00:00
|
|
|
});
|
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
it("calls the onSelect prop when + icon button is clicked", () => {
|
2020-12-01 18:15:12 +00:00
|
|
|
const onSelectSpy = jest.fn();
|
2022-03-31 16:49:50 +00:00
|
|
|
const { container } = render(
|
2016-10-27 16:14:30 +00:00
|
|
|
<TargetOption
|
2022-03-31 16:49:50 +00:00
|
|
|
onMoreInfoClick={onMoreInfoClick}
|
2016-10-27 16:14:30 +00:00
|
|
|
onSelect={onSelectSpy}
|
2017-01-20 17:02:13 +00:00
|
|
|
target={hostStub}
|
2021-04-12 13:32:25 +00:00
|
|
|
/>
|
2016-10-27 16:14:30 +00:00
|
|
|
);
|
2022-03-31 16:49:50 +00:00
|
|
|
fireEvent.click(container.querySelector(".target-option__add-btn"));
|
2016-10-27 16:14:30 +00:00
|
|
|
expect(onSelectSpy).toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
it("calls the onMoreInfoClick prop when the item content is clicked", () => {
|
2022-03-31 16:49:50 +00:00
|
|
|
const { container } = render(
|
2021-04-12 13:32:25 +00:00
|
|
|
<TargetOption onMoreInfoClick={onMoreInfoClick} target={hostStub} />
|
2016-10-27 16:14:30 +00:00
|
|
|
);
|
2022-03-31 16:49:50 +00:00
|
|
|
fireEvent.click(container.querySelector(".target-option__target-content"));
|
2016-10-27 16:14:30 +00:00
|
|
|
expect(onMoreInfoClickSpy).toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
});
|