Skip to content

Commit ccaede1

Browse files
authored
test: move toast tests to RTL (react-bootstrap#6172)
* test: move toast tests to RTL * cr changes
1 parent b1ec614 commit ccaede1

File tree

7 files changed

+161
-124
lines changed

7 files changed

+161
-124
lines changed

test/ToastBodySpec.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/ToastBodySpec.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from 'react';
2+
import { render } from '@testing-library/react';
3+
import Toast from '../src/Toast';
4+
5+
describe('Toast.Body', () => {
6+
it('will pass all props to the created div and renders its children', () => {
7+
const content = <strong>Content</strong>;
8+
const { container } = render(
9+
<Toast.Body className="custom-class">{content}</Toast.Body>,
10+
);
11+
container.firstElementChild!.classList.contains('custom-class').should.be
12+
.true;
13+
container.firstElementChild!.classList.contains('toast-body').should.be
14+
.true;
15+
});
16+
});

test/ToastContainerSpec.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

test/ToastContainerSpec.tsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { render } from '@testing-library/react';
2+
import ToastContainer, { ToastPosition } from '../src/ToastContainer';
3+
4+
const expectedClasses: Record<ToastPosition, Array<string>> = {
5+
'top-start': ['position-absolute', 'top-0', 'start-0'],
6+
'top-center': [
7+
'position-absolute',
8+
'top-0',
9+
'start-50',
10+
'translate-middle-x',
11+
],
12+
'top-end': ['position-absolute', 'top-0', 'end-0'],
13+
'middle-start': [
14+
'position-absolute',
15+
'top-50',
16+
'start-0',
17+
'translate-middle-y',
18+
],
19+
'middle-center': [
20+
'position-absolute',
21+
'top-50',
22+
'start-50',
23+
'translate-middle',
24+
],
25+
'middle-end': ['position-absolute', 'top-50', 'end-0', 'translate-middle-y'],
26+
'bottom-start': ['position-absolute', 'bottom-0', 'start-0'],
27+
'bottom-center': [
28+
'position-absolute',
29+
'bottom-0',
30+
'start-50',
31+
'translate-middle-x',
32+
],
33+
'bottom-end': ['position-absolute', 'bottom-0', 'end-0'],
34+
};
35+
36+
describe('ToastContainer', () => {
37+
it('should render a basic toast container', () => {
38+
const { container } = render(<ToastContainer />);
39+
container.firstElementChild!.classList.contains('toast-container').should.be
40+
.true;
41+
});
42+
43+
Object.keys(expectedClasses).forEach((position: ToastPosition) => {
44+
it(`should render position=${position}`, () => {
45+
const { container } = render(<ToastContainer position={position} />);
46+
expectedClasses[position].map(
47+
(className) =>
48+
container.firstElementChild!.classList.contains(className).should.be
49+
.true,
50+
);
51+
});
52+
});
53+
});

test/ToastHeaderSpec.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

test/ToastHeaderSpec.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { render } from '@testing-library/react';
2+
3+
import Toast from '../src/Toast';
4+
5+
describe('Toast.Header', () => {
6+
it('will pass all props to the created div and renders its children', () => {
7+
const { container } = render(
8+
<Toast.Header>
9+
<strong>content</strong>
10+
</Toast.Header>,
11+
);
12+
container.firstElementChild!.tagName === 'div';
13+
container.firstElementChild!.firstElementChild!.tagName === 'strong';
14+
container.firstElementChild!.classList.contains('toast-header').should.be
15+
.true;
16+
});
17+
18+
it('should render close button variant', () => {
19+
const { container } = render(
20+
<Toast.Header closeButton closeVariant="white">
21+
<strong>content</strong>
22+
</Toast.Header>,
23+
);
24+
container
25+
.firstElementChild!.getElementsByTagName('button')[0]
26+
.classList.contains('btn-close-white').should.be.true;
27+
});
28+
});

0 commit comments

Comments
 (0)