mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-25 07:56:28 +00:00
Moved common test set-up code to helper function
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { render, screen, waitFor } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { screen, waitFor } from '@testing-library/react';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { DomainSelector } from '../../src/domains/DomainSelector';
|
||||
import { DomainsList } from '../../src/domains/reducers/domainsList';
|
||||
import { ShlinkDomain } from '../../src/api/types';
|
||||
import { renderWithEvents } from '../__mocks__/setUpTest';
|
||||
|
||||
describe('<DomainSelector />', () => {
|
||||
const domainsList = Mock.of<DomainsList>({
|
||||
@@ -13,10 +13,9 @@ describe('<DomainSelector />', () => {
|
||||
Mock.of<ShlinkDomain>({ domain: 'bar.com' }),
|
||||
],
|
||||
});
|
||||
const setUp = (value = '') => ({
|
||||
user: userEvent.setup(),
|
||||
...render(<DomainSelector value={value} domainsList={domainsList} listDomains={jest.fn()} onChange={jest.fn()} />),
|
||||
});
|
||||
const setUp = (value = '') => renderWithEvents(
|
||||
<DomainSelector value={value} domainsList={domainsList} listDomains={jest.fn()} onChange={jest.fn()} />,
|
||||
);
|
||||
|
||||
afterEach(jest.clearAllMocks);
|
||||
|
||||
|
||||
@@ -1,27 +1,24 @@
|
||||
import { render, screen, waitFor } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { screen, waitFor } from '@testing-library/react';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { DomainsList } from '../../src/domains/reducers/domainsList';
|
||||
import { ManageDomains } from '../../src/domains/ManageDomains';
|
||||
import { ProblemDetailsError, ShlinkDomain } from '../../src/api/types';
|
||||
import { SelectedServer } from '../../src/servers/data';
|
||||
import { renderWithEvents } from '../__mocks__/setUpTest';
|
||||
|
||||
describe('<ManageDomains />', () => {
|
||||
const listDomains = jest.fn();
|
||||
const filterDomains = jest.fn();
|
||||
const setUp = (domainsList: DomainsList) => ({
|
||||
user: userEvent.setup(),
|
||||
...render(
|
||||
<ManageDomains
|
||||
listDomains={listDomains}
|
||||
filterDomains={filterDomains}
|
||||
editDomainRedirects={jest.fn()}
|
||||
checkDomainHealth={jest.fn()}
|
||||
domainsList={domainsList}
|
||||
selectedServer={Mock.all<SelectedServer>()}
|
||||
/>,
|
||||
),
|
||||
});
|
||||
const setUp = (domainsList: DomainsList) => renderWithEvents(
|
||||
<ManageDomains
|
||||
listDomains={listDomains}
|
||||
filterDomains={filterDomains}
|
||||
editDomainRedirects={jest.fn()}
|
||||
checkDomainHealth={jest.fn()}
|
||||
domainsList={domainsList}
|
||||
selectedServer={Mock.all<SelectedServer>()}
|
||||
/>,
|
||||
);
|
||||
|
||||
afterEach(jest.clearAllMocks);
|
||||
|
||||
|
||||
@@ -1,26 +1,23 @@
|
||||
import { render, screen, waitForElementToBeRemoved } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { screen, waitForElementToBeRemoved } from '@testing-library/react';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { DomainDropdown } from '../../../src/domains/helpers/DomainDropdown';
|
||||
import { Domain } from '../../../src/domains/data';
|
||||
import { ReachableServer, SelectedServer } from '../../../src/servers/data';
|
||||
import { SemVer } from '../../../src/utils/helpers/version';
|
||||
import { renderWithEvents } from '../../__mocks__/setUpTest';
|
||||
|
||||
describe('<DomainDropdown />', () => {
|
||||
const editDomainRedirects = jest.fn().mockResolvedValue(undefined);
|
||||
const setUp = (domain?: Domain, selectedServer?: SelectedServer) => ({
|
||||
user: userEvent.setup(),
|
||||
...render(
|
||||
<MemoryRouter>
|
||||
<DomainDropdown
|
||||
domain={domain ?? Mock.all<Domain>()}
|
||||
selectedServer={selectedServer ?? Mock.all<SelectedServer>()}
|
||||
editDomainRedirects={editDomainRedirects}
|
||||
/>
|
||||
</MemoryRouter>,
|
||||
),
|
||||
});
|
||||
const setUp = (domain?: Domain, selectedServer?: SelectedServer) => renderWithEvents(
|
||||
<MemoryRouter>
|
||||
<DomainDropdown
|
||||
domain={domain ?? Mock.all<Domain>()}
|
||||
selectedServer={selectedServer ?? Mock.all<SelectedServer>()}
|
||||
editDomainRedirects={editDomainRedirects}
|
||||
/>
|
||||
</MemoryRouter>,
|
||||
);
|
||||
|
||||
afterEach(jest.clearAllMocks);
|
||||
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { screen } from '@testing-library/react';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { DomainStatus } from '../../../src/domains/data';
|
||||
import { DomainStatusIcon } from '../../../src/domains/helpers/DomainStatusIcon';
|
||||
import { renderWithEvents } from '../../__mocks__/setUpTest';
|
||||
|
||||
describe('<DomainStatusIcon />', () => {
|
||||
const matchMedia = jest.fn().mockReturnValue(Mock.of<MediaQueryList>({ matches: false }));
|
||||
const setUp = (status: DomainStatus) => ({
|
||||
user: userEvent.setup(),
|
||||
...render(<DomainStatusIcon status={status} matchMedia={matchMedia} />),
|
||||
});
|
||||
const setUp = (status: DomainStatus) => renderWithEvents(
|
||||
<DomainStatusIcon status={status} matchMedia={matchMedia} />,
|
||||
);
|
||||
|
||||
beforeEach(jest.clearAllMocks);
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { fireEvent, screen, waitFor } from '@testing-library/react';
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { ShlinkDomain } from '../../../src/api/types';
|
||||
import { EditDomainRedirectsModal } from '../../../src/domains/helpers/EditDomainRedirectsModal';
|
||||
import { renderWithEvents } from '../../__mocks__/setUpTest';
|
||||
|
||||
describe('<EditDomainRedirectsModal />', () => {
|
||||
const editDomainRedirects = jest.fn().mockResolvedValue(undefined);
|
||||
@@ -13,12 +13,9 @@ describe('<EditDomainRedirectsModal />', () => {
|
||||
baseUrlRedirect: 'baz',
|
||||
},
|
||||
});
|
||||
const setUp = () => ({
|
||||
user: userEvent.setup(),
|
||||
...render(
|
||||
<EditDomainRedirectsModal domain={domain} isOpen toggle={toggle} editDomainRedirects={editDomainRedirects} />,
|
||||
),
|
||||
});
|
||||
const setUp = () => renderWithEvents(
|
||||
<EditDomainRedirectsModal domain={domain} isOpen toggle={toggle} editDomainRedirects={editDomainRedirects} />,
|
||||
);
|
||||
|
||||
afterEach(jest.clearAllMocks);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user