mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 01:37:24 +03:00
Migrated ShlinkLogo test to react testing library
This commit is contained in:
parent
3846ca293c
commit
43302ef5a8
1 changed files with 10 additions and 14 deletions
|
@ -1,25 +1,17 @@
|
||||||
import { shallow, ShallowWrapper } from 'enzyme';
|
import { render } from '@testing-library/react';
|
||||||
import { ShlinkLogo, ShlinkLogoProps } from '../../../src/common/img/ShlinkLogo';
|
import { ShlinkLogo, ShlinkLogoProps } from '../../../src/common/img/ShlinkLogo';
|
||||||
import { MAIN_COLOR } from '../../../src/utils/theme';
|
import { MAIN_COLOR } from '../../../src/utils/theme';
|
||||||
|
|
||||||
describe('<ShlinkLogo />', () => {
|
describe('<ShlinkLogo />', () => {
|
||||||
let wrapper: ShallowWrapper;
|
const setUp = (props: ShlinkLogoProps) => render(<ShlinkLogo {...props} />);
|
||||||
const createWrapper = (props: ShlinkLogoProps) => {
|
|
||||||
wrapper = shallow(<ShlinkLogo {...props} />);
|
|
||||||
|
|
||||||
return wrapper;
|
|
||||||
};
|
|
||||||
|
|
||||||
afterEach(() => wrapper?.unmount());
|
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
[undefined, MAIN_COLOR],
|
[undefined, MAIN_COLOR],
|
||||||
['red', 'red'],
|
['red', 'red'],
|
||||||
['white', 'white'],
|
['white', 'white'],
|
||||||
])('renders expected color', (color, expectedColor) => {
|
])('renders expected color', (color, expectedColor) => {
|
||||||
const wrapper = createWrapper({ color });
|
const { container } = setUp({ color });
|
||||||
|
expect(container.querySelector('g')).toHaveAttribute('fill', expectedColor);
|
||||||
expect(wrapper.find('g').prop('fill')).toEqual(expectedColor);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
|
@ -27,8 +19,12 @@ describe('<ShlinkLogo />', () => {
|
||||||
['foo', 'foo'],
|
['foo', 'foo'],
|
||||||
['bar', 'bar'],
|
['bar', 'bar'],
|
||||||
])('renders expected class', (className, expectedClassName) => {
|
])('renders expected class', (className, expectedClassName) => {
|
||||||
const wrapper = createWrapper({ className });
|
const { container } = setUp({ className });
|
||||||
|
|
||||||
expect(wrapper.prop('className')).toEqual(expectedClassName);
|
if (expectedClassName) {
|
||||||
|
expect(container.firstChild).toHaveAttribute('class', expectedClassName);
|
||||||
|
} else {
|
||||||
|
expect(container.firstChild).not.toHaveAttribute('class');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue