/
ToastContainerSpec.tsx
41 lines (37 loc) · 1.5 KB
/
ToastContainerSpec.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { render } from '@testing-library/react';
import ToastContainer, { ToastPosition } from '../src/ToastContainer';
const expectedClasses: Record<ToastPosition, Array<string>> = {
'top-start': ['top-0', 'start-0'],
'top-center': ['top-0', 'start-50', 'translate-middle-x'],
'top-end': ['top-0', 'end-0'],
'middle-start': ['top-50', 'start-0', 'translate-middle-y'],
'middle-center': ['top-50', 'start-50', 'translate-middle'],
'middle-end': ['top-50', 'end-0', 'translate-middle-y'],
'bottom-start': ['bottom-0', 'start-0'],
'bottom-center': ['bottom-0', 'start-50', 'translate-middle-x'],
'bottom-end': ['bottom-0', 'end-0'],
};
describe('ToastContainer', () => {
it('should render a basic toast container', () => {
const { container } = render(<ToastContainer />);
container.firstElementChild!.classList.contains('toast-container').should.be
.true;
});
it('should render the containerPosition', () => {
const { container } = render(
<ToastContainer containerPosition="relative" />,
);
container.firstElementChild!.classList.contains('position-relative').should
.be.true;
});
Object.keys(expectedClasses).forEach((position: ToastPosition) => {
it(`should render position=${position}`, () => {
const { container } = render(<ToastContainer position={position} />);
expectedClasses[position].map(
(className) =>
container.firstElementChild!.classList.contains(className).should.be
.true,
);
});
});
});