mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-10 18:27:25 +03:00
Added DomainSelector test
This commit is contained in:
parent
02c7125236
commit
ff48c0cd45
2 changed files with 43 additions and 1 deletions
|
@ -21,7 +21,7 @@ import './DomainSelector.scss';
|
|||
|
||||
export interface DomainSelectorProps extends Omit<InputProps, 'onChange'> {
|
||||
value?: string;
|
||||
onChange: (domain?: string) => void;
|
||||
onChange: (domain: string) => void;
|
||||
}
|
||||
|
||||
interface DomainSelectorConnectProps extends DomainSelectorProps {
|
||||
|
|
42
test/domains/DomainSelector.test.tsx
Normal file
42
test/domains/DomainSelector.test.tsx
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { shallow, ShallowWrapper } from 'enzyme';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { DropdownItem, DropdownMenu, InputGroup } from 'reactstrap';
|
||||
import { DomainSelector } from '../../src/domains/DomainSelector';
|
||||
import { DomainsList } from '../../src/domains/reducers/domainsList';
|
||||
import { ShlinkDomain } from '../../src/utils/services/types';
|
||||
|
||||
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(DropdownMenu);
|
||||
|
||||
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(DropdownMenu)).toHaveLength(0);
|
||||
|
||||
wrapper.find('.domains-dropdown__back-btn').simulate('click');
|
||||
expect(wrapper.find(InputGroup)).toHaveLength(0);
|
||||
expect(wrapper.find(DropdownMenu)).toHaveLength(1);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue