fleet/frontend/components/forms/fields/SelectTargetsDropdown/TargetOption/TargetOption.tests.jsx
Zach Wasserman 0670db66c4
Migrate JS tests to Jest and update libraries (#74)
- Move from Mocha to Jest for JS testing (Jest seems to have better support for
 'watching' tests and a more active community these days).
- Codemod existing tests to Jest syntax (using https://github.com/skovhus/jest-codemods)
- Fix some errors in tests that were previously hidden.
- Update Babel.
2020-12-01 10:15:12 -08:00

50 lines
1.7 KiB
JavaScript

import React from 'react';
import { mount } from 'enzyme';
import { noop } from 'lodash';
import { hostStub, labelStub } from 'test/stubs';
import TargetOption from './TargetOption';
describe('TargetOption - component', () => {
it('renders a label option for label targets', () => {
const count = 5;
const component = mount(<TargetOption onMoreInfoClick={noop} target={{ ...labelStub, count }} />);
expect(component.find('.is-label').length).toEqual(1);
expect(component.text()).toContain(`${count} hosts`);
});
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);
expect(component.find('i.kolidecon-windows').length).toEqual(1);
expect(component.text()).toContain(hostStub.primary_ip);
});
it('calls the onSelect prop when + icon button is clicked', () => {
const onSelectSpy = jest.fn();
const component = mount(
<TargetOption
onMoreInfoClick={noop}
onSelect={onSelectSpy}
target={hostStub}
/>,
);
component.find('.target-option__add-btn').simulate('click');
expect(onSelectSpy).toHaveBeenCalled();
});
it('calls the onMoreInfoClick prop when the item content is clicked', () => {
const onMoreInfoClickSpy = jest.fn();
const onMoreInfoClick = () => {
return onMoreInfoClickSpy;
};
const component = mount(
<TargetOption
onMoreInfoClick={onMoreInfoClick}
target={hostStub}
/>,
);
component.find('.target-option__target-content').simulate('click');
expect(onMoreInfoClickSpy).toHaveBeenCalled();
});
});