mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 17:40:23 +03:00
43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
import { shallow, ShallowWrapper } from 'enzyme';
|
|
import { Mock } from 'ts-mockery';
|
|
import { DropdownItem, InputGroup } from 'reactstrap';
|
|
import { DomainSelector } from '../../src/domains/DomainSelector';
|
|
import { DomainsList } from '../../src/domains/reducers/domainsList';
|
|
import { ShlinkDomain } from '../../src/api/types';
|
|
import { Dropdown } from '../../src/utils/Dropdown';
|
|
|
|
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);
|
|
const dropdown = wrapper.find(Dropdown);
|
|
|
|
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);
|
|
expect(wrapper.find(Dropdown)).toHaveLength(0);
|
|
|
|
wrapper.find('.domains-dropdown__back-btn').simulate('click');
|
|
expect(wrapper.find(InputGroup)).toHaveLength(0);
|
|
expect(wrapper.find(Dropdown)).toHaveLength(1);
|
|
});
|
|
});
|