mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-08 17:27:32 +03:00
Created Result test
This commit is contained in:
parent
344f5e9b0d
commit
94d2f3167b
2 changed files with 50 additions and 2 deletions
|
@ -3,8 +3,10 @@ import { Row } from 'reactstrap';
|
|||
import classNames from 'classnames';
|
||||
import { SimpleCard } from './SimpleCard';
|
||||
|
||||
interface ResultProps {
|
||||
type: 'success' | 'error' | 'warning';
|
||||
export type ResultType = 'success' | 'error' | 'warning';
|
||||
|
||||
export interface ResultProps {
|
||||
type: ResultType;
|
||||
className?: string;
|
||||
small?: boolean;
|
||||
}
|
||||
|
|
46
test/utils/Result.test.tsx
Normal file
46
test/utils/Result.test.tsx
Normal file
|
@ -0,0 +1,46 @@
|
|||
import { shallow, ShallowWrapper } from 'enzyme';
|
||||
import { Result, ResultProps, ResultType } from '../../src/utils/Result';
|
||||
import { SimpleCard } from '../../src/utils/SimpleCard';
|
||||
|
||||
describe('<Result />', () => {
|
||||
let wrapper: ShallowWrapper;
|
||||
const createWrapper = (props: ResultProps) => {
|
||||
wrapper = shallow(<Result {...props} />);
|
||||
|
||||
return wrapper;
|
||||
};
|
||||
|
||||
afterEach(() => wrapper?.unmount());
|
||||
|
||||
it.each([
|
||||
[ 'success' as ResultType, 'bg-main text-white' ],
|
||||
[ 'error' as ResultType, 'bg-danger text-white' ],
|
||||
[ 'warning' as ResultType, 'bg-warning' ],
|
||||
])('renders expected classes based on type', (type, expectedClasses) => {
|
||||
const wrapper = createWrapper({ type });
|
||||
const innerCard = wrapper.find(SimpleCard);
|
||||
|
||||
expect(innerCard.prop('className')).toEqual(`text-center ${expectedClasses}`);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[ undefined ],
|
||||
[ 'foo' ],
|
||||
[ 'bar' ],
|
||||
])('renders provided classes in root element', (className) => {
|
||||
const wrapper = createWrapper({ type: 'success', className });
|
||||
|
||||
expect(wrapper.prop('className')).toEqual(className);
|
||||
});
|
||||
|
||||
it.each([{ small: true }, { small: false }])('renders small results properly', ({ small }) => {
|
||||
const wrapper = createWrapper({ type: 'success', small });
|
||||
const bigElement = wrapper.find('.col-md-10');
|
||||
const smallElement = wrapper.find('.col-12');
|
||||
const innerCard = wrapper.find(SimpleCard);
|
||||
|
||||
expect(bigElement).toHaveLength(small ? 0 : 1);
|
||||
expect(smallElement).toHaveLength(small ? 1 : 0);
|
||||
expect(innerCard.prop('bodyClassName')).toEqual(small ? 'p-2' : '');
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue