import { shallow, ShallowWrapper } from 'enzyme';
import { Mock } from 'ts-mockery';
import { ShlinkDomainRedirects } from '../../src/api/types';
import { DomainRow } from '../../src/domains/DomainRow';
import { SelectedServer } from '../../src/servers/data';
import { Domain } from '../../src/domains/data';
describe('', () => {
let wrapper: ShallowWrapper;
const createWrapper = (domain: Domain, selectedServer = Mock.all()) => {
wrapper = shallow(
,
);
return wrapper;
};
afterEach(() => wrapper?.unmount());
it.each([
[undefined, 3],
[Mock.of(), 3],
[Mock.of({ baseUrlRedirect: 'foo' }), 2],
[Mock.of({ invalidShortUrlRedirect: 'foo' }), 2],
[Mock.of({ baseUrlRedirect: 'foo', regular404Redirect: 'foo' }), 1],
[
Mock.of(
{ baseUrlRedirect: 'foo', regular404Redirect: 'foo', invalidShortUrlRedirect: 'foo' },
),
0,
],
])('shows expected redirects', (redirects, expectedNoRedirects) => {
const wrapper = createWrapper(Mock.of({ domain: '', isDefault: true, redirects }));
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);
});
});