mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-11 18:13:47 +00:00
Move shlink-web-component tests to their own folder
This commit is contained in:
22
shlink-web-component/test/common/AsideMenu.test.tsx
Normal file
22
shlink-web-component/test/common/AsideMenu.test.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { fromPartial } from '@total-typescript/shoehorn';
|
||||
import { MemoryRouter } from 'react-router';
|
||||
import { AsideMenu } from '../../src/common/AsideMenu';
|
||||
|
||||
describe('<AsideMenu />', () => {
|
||||
const setUp = () => render(
|
||||
<MemoryRouter>
|
||||
<AsideMenu selectedServer={fromPartial({ id: 'abc123', version: '2.8.0' })} />
|
||||
</MemoryRouter>,
|
||||
);
|
||||
|
||||
it('contains links to different sections', () => {
|
||||
setUp();
|
||||
|
||||
const links = screen.getAllByRole('link');
|
||||
|
||||
expect.assertions(links.length + 1);
|
||||
expect(links).toHaveLength(5);
|
||||
links.forEach((link) => expect(link.getAttribute('href')).toContain('abc123'));
|
||||
});
|
||||
});
|
||||
31
shlink-web-component/test/common/ShlinkApiError.test.tsx
Normal file
31
shlink-web-component/test/common/ShlinkApiError.test.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { fromPartial } from '@total-typescript/shoehorn';
|
||||
import type { InvalidArgumentError, ProblemDetailsError } from '../../src/api/types/errors';
|
||||
import { ErrorTypeV2, ErrorTypeV3 } from '../../src/api/types/errors';
|
||||
import type { ShlinkApiErrorProps } from '../../src/common/ShlinkApiError';
|
||||
import { ShlinkApiError } from '../../src/common/ShlinkApiError';
|
||||
|
||||
describe('<ShlinkApiError />', () => {
|
||||
const setUp = (props: ShlinkApiErrorProps) => render(<ShlinkApiError {...props} />);
|
||||
|
||||
it.each([
|
||||
[undefined, 'the fallback', 'the fallback'],
|
||||
[fromPartial<ProblemDetailsError>({}), 'the fallback', 'the fallback'],
|
||||
[fromPartial<ProblemDetailsError>({ detail: 'the detail' }), 'the fallback', 'the detail'],
|
||||
])('renders proper message', (errorData, fallbackMessage, expectedMessage) => {
|
||||
const { container } = setUp({ errorData, fallbackMessage });
|
||||
|
||||
expect(container.firstChild).toHaveTextContent(expectedMessage);
|
||||
expect(screen.queryByRole('paragraph')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it.each([
|
||||
[undefined, 0],
|
||||
[fromPartial<ProblemDetailsError>({}), 0],
|
||||
[fromPartial<InvalidArgumentError>({ type: ErrorTypeV2.INVALID_ARGUMENT, invalidElements: [] }), 1],
|
||||
[fromPartial<InvalidArgumentError>({ type: ErrorTypeV3.INVALID_ARGUMENT, invalidElements: [] }), 1],
|
||||
])('renders list of invalid elements when provided error is an InvalidError', (errorData, expectedElementsCount) => {
|
||||
setUp({ errorData });
|
||||
expect(screen.queryAllByText(/^Invalid elements/)).toHaveLength(expectedElementsCount);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user