2021-04-12 13:32:25 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import { mount } from "enzyme";
|
|
|
|
|
import { noop } from "lodash";
|
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", () => {
|
|
|
|
|
it("renders a label option for label targets", () => {
|
2017-01-20 17:02:13 +00:00
|
|
|
const count = 5;
|
2021-04-12 13:32:25 +00:00
|
|
|
const component = mount(
|
|
|
|
|
<TargetOption onMoreInfoClick={noop} target={{ ...labelStub, count }} />
|
|
|
|
|
);
|
|
|
|
|
expect(component.find(".is-label").length).toEqual(1);
|
2017-01-20 17:02:13 +00:00
|
|
|
expect(component.text()).toContain(`${count} hosts`);
|
2016-10-27 16:14:30 +00:00
|
|
|
});
|
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
it("renders a host option for host targets", () => {
|
|
|
|
|
const component = mount(
|
|
|
|
|
<TargetOption
|
|
|
|
|
onMoreInfoClick={noop}
|
|
|
|
|
target={{ ...hostStub, platform: "windows" }}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
expect(component.find(".is-host").length).toEqual(1);
|
2021-06-07 01:56:30 +00:00
|
|
|
expect(component.find("i.fleeticon-windows").length).toEqual(1);
|
2020-03-11 20:38:44 +00:00
|
|
|
expect(component.text()).toContain(hostStub.primary_ip);
|
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();
|
2016-10-27 16:14:30 +00:00
|
|
|
const component = mount(
|
|
|
|
|
<TargetOption
|
|
|
|
|
onMoreInfoClick={noop}
|
|
|
|
|
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
|
|
|
);
|
2021-04-12 13:32:25 +00:00
|
|
|
component.find(".target-option__add-btn").simulate("click");
|
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", () => {
|
2020-12-01 18:15:12 +00:00
|
|
|
const onMoreInfoClickSpy = jest.fn();
|
2016-10-27 16:14:30 +00:00
|
|
|
const onMoreInfoClick = () => {
|
|
|
|
|
return onMoreInfoClickSpy;
|
|
|
|
|
};
|
|
|
|
|
const component = mount(
|
2021-04-12 13:32:25 +00:00
|
|
|
<TargetOption onMoreInfoClick={onMoreInfoClick} target={hostStub} />
|
2016-10-27 16:14:30 +00:00
|
|
|
);
|
2021-04-12 13:32:25 +00:00
|
|
|
component.find(".target-option__target-content").simulate("click");
|
2016-10-27 16:14:30 +00:00
|
|
|
expect(onMoreInfoClickSpy).toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
});
|