2020-11-28 14:36:40 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
|
|
|
import { Mock } from 'ts-mockery';
|
2020-12-25 12:29:25 +03:00
|
|
|
import { DropdownItem, InputGroup } from 'reactstrap';
|
2020-11-28 14:36:40 +03:00
|
|
|
import { DomainSelector } from '../../src/domains/DomainSelector';
|
|
|
|
import { DomainsList } from '../../src/domains/reducers/domainsList';
|
2020-12-22 11:49:13 +03:00
|
|
|
import { ShlinkDomain } from '../../src/api/types';
|
2020-12-25 12:43:36 +03:00
|
|
|
import { DropdownBtn } from '../../src/utils/DropdownBtn';
|
2020-11-28 14:36:40 +03:00
|
|
|
|
|
|
|
describe('<DomainSelector />', () => {
|
|
|
|
let wrapper: ShallowWrapper;
|
|
|
|
const domainsList = Mock.of<DomainsList>({
|
|
|
|
domains: [
|
|
|
|
Mock.of<ShlinkDomain>({ domain: 'foo.com' }),
|
|
|
|
Mock.of<ShlinkDomain>({ domain: 'bar.com' }),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = shallow(<DomainSelector domainsList={domainsList} listDomains={jest.fn()} onChange={jest.fn()} />);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(jest.clearAllMocks);
|
|
|
|
afterEach(() => wrapper.unmount());
|
|
|
|
|
|
|
|
it('shows dropdown by default', () => {
|
|
|
|
const input = wrapper.find(InputGroup);
|
2020-12-25 12:43:36 +03:00
|
|
|
const dropdown = wrapper.find(DropdownBtn);
|
2020-11-28 14:36:40 +03:00
|
|
|
|
|
|
|
expect(input).toHaveLength(0);
|
|
|
|
expect(dropdown).toHaveLength(1);
|
|
|
|
expect(dropdown.find(DropdownItem)).toHaveLength(4);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('allows to toggle between dropdown and input', () => {
|
|
|
|
wrapper.find(DropdownItem).last().simulate('click');
|
|
|
|
expect(wrapper.find(InputGroup)).toHaveLength(1);
|
2020-12-25 12:43:36 +03:00
|
|
|
expect(wrapper.find(DropdownBtn)).toHaveLength(0);
|
2020-11-28 14:36:40 +03:00
|
|
|
|
|
|
|
wrapper.find('.domains-dropdown__back-btn').simulate('click');
|
|
|
|
expect(wrapper.find(InputGroup)).toHaveLength(0);
|
2020-12-25 12:43:36 +03:00
|
|
|
expect(wrapper.find(DropdownBtn)).toHaveLength(1);
|
2020-11-28 14:36:40 +03:00
|
|
|
});
|
|
|
|
});
|