shlink-web-client/test/domains/DomainRow.test.tsx

48 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-08-24 20:53:28 +03:00
import { shallow, ShallowWrapper } from 'enzyme';
import { Mock } from 'ts-mockery';
import { ShlinkDomainRedirects } from '../../src/api/types';
2021-08-24 20:53:28 +03:00
import { DomainRow } from '../../src/domains/DomainRow';
import { SelectedServer } from '../../src/servers/data';
import { Domain } from '../../src/domains/data';
2021-08-24 20:53:28 +03:00
describe('<DomainRow />', () => {
let wrapper: ShallowWrapper;
const createWrapper = (domain: Domain, selectedServer = Mock.all<SelectedServer>()) => {
wrapper = shallow(
<DomainRow
domain={domain}
selectedServer={selectedServer}
editDomainRedirects={jest.fn()}
checkDomainHealth={jest.fn()}
/>,
);
2021-08-24 20:53:28 +03:00
return wrapper;
};
afterEach(() => wrapper?.unmount());
it.each([
2022-03-26 14:17:42 +03:00
[undefined, 3],
[Mock.of<ShlinkDomainRedirects>(), 3],
[Mock.of<ShlinkDomainRedirects>({ baseUrlRedirect: 'foo' }), 2],
[Mock.of<ShlinkDomainRedirects>({ invalidShortUrlRedirect: 'foo' }), 2],
[Mock.of<ShlinkDomainRedirects>({ baseUrlRedirect: 'foo', regular404Redirect: 'foo' }), 1],
2021-08-24 20:53:28 +03:00
[
Mock.of<ShlinkDomainRedirects>(
{ baseUrlRedirect: 'foo', regular404Redirect: 'foo', invalidShortUrlRedirect: 'foo' },
),
0,
],
])('shows expected redirects', (redirects, expectedNoRedirects) => {
const wrapper = createWrapper(Mock.of<Domain>({ domain: '', isDefault: true, redirects }));
2021-08-24 20:53:28 +03:00
const noRedirects = wrapper.find('Nr');
const cells = wrapper.find('td');
expect(noRedirects).toHaveLength(expectedNoRedirects);
redirects?.baseUrlRedirect && expect(cells.at(1).html()).toContain(redirects.baseUrlRedirect);
redirects?.regular404Redirect && expect(cells.at(2).html()).toContain(redirects.regular404Redirect);
redirects?.invalidShortUrlRedirect && expect(cells.at(3).html()).toContain(redirects.invalidShortUrlRedirect);
});
});