mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 01:20:24 +03:00
Created ShlinkApiError test
This commit is contained in:
parent
b2abfd543e
commit
9eb9182c21
2 changed files with 37 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
||||||
import { ProblemDetailsError } from './types';
|
import { ProblemDetailsError } from './types';
|
||||||
import { isInvalidArgumentError } from './utils';
|
import { isInvalidArgumentError } from './utils';
|
||||||
|
|
||||||
interface ShlinkApiErrorProps {
|
export interface ShlinkApiErrorProps {
|
||||||
errorData?: ProblemDetailsError;
|
errorData?: ProblemDetailsError;
|
||||||
fallbackMessage?: string;
|
fallbackMessage?: string;
|
||||||
}
|
}
|
||||||
|
|
36
test/api/ShlinkApiError.test.tsx
Normal file
36
test/api/ShlinkApiError.test.tsx
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
import { shallow, ShallowWrapper } from 'enzyme';
|
||||||
|
import { Mock } from 'ts-mockery';
|
||||||
|
import { ShlinkApiError, ShlinkApiErrorProps } from '../../src/api/ShlinkApiError';
|
||||||
|
import { InvalidArgumentError, ProblemDetailsError } from '../../src/api/types';
|
||||||
|
|
||||||
|
describe('<ShlinkApiError />', () => {
|
||||||
|
let wrapper: ShallowWrapper;
|
||||||
|
const createWrapper = (props: ShlinkApiErrorProps) => {
|
||||||
|
wrapper = shallow(<ShlinkApiError {...props} />);
|
||||||
|
|
||||||
|
return wrapper;
|
||||||
|
};
|
||||||
|
|
||||||
|
afterEach(() => wrapper?.unmount());
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
[ undefined, 'the fallback', 'the fallback' ],
|
||||||
|
[ Mock.all<ProblemDetailsError>(), 'the fallback', 'the fallback' ],
|
||||||
|
[ Mock.of<ProblemDetailsError>({ detail: 'the detail' }), 'the fallback', 'the detail' ],
|
||||||
|
])('renders proper message', (errorData, fallbackMessage, expectedMessage) => {
|
||||||
|
const wrapper = createWrapper({ errorData, fallbackMessage });
|
||||||
|
|
||||||
|
expect(wrapper.text()).toContain(expectedMessage);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
[ undefined, 0 ],
|
||||||
|
[ Mock.all<ProblemDetailsError>(), 0 ],
|
||||||
|
[ Mock.of<InvalidArgumentError>({ type: 'INVALID_ARGUMENT', invalidElements: [] }), 1 ],
|
||||||
|
])('renders list of invalid elements when provided error is an InvalidError', (errorData, expectedElementsCount) => {
|
||||||
|
const wrapper = createWrapper({ errorData });
|
||||||
|
const p = wrapper.find('p');
|
||||||
|
|
||||||
|
expect(p).toHaveLength(expectedElementsCount);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue