Skip to content

Commit fb45ad6

Browse files
afc163claude
andauthored
test: improve mountTest and rtlTest coverage (ant-design#57067)
* test: improve mountTest and rtlTest coverage ## Changes ### 1. Add missing mountTest and rtlTest for components: - anchor (Anchor.test.tsx) - collapse (index.test.tsx, includes Panel) - splitter (index.test.tsx) - masonry (index.test.tsx) - affix (Affix.test.tsx, added mountTest) - alert (index.test.tsx, added mountTest) ### 2. Remove duplicate tests: - radio/Button: removed duplicate mountTest and rtlTest from radio-button.test.tsx (already covered in radio.test.tsx) ### 3. Remove misplaced mountTest and rtlTest from semantic.test.tsx: These tests should be in index.test.tsx, not semantic.test.tsx. Removed from: - auto-complete - color-picker - divider - image - pagination - popconfirm - table - tabs - tree Note: All components still have mountTest and rtlTest coverage in their respective index.test.tsx or main test files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test: remove obsolete snapshots from semantic test files Remove obsolete RTL snapshots from pagination, color-picker, and popconfirm semantic.test.tsx files after removing misplaced rtlTest. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test: update snapshot * revert test case --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7118a99 commit fb45ad6

26 files changed

Lines changed: 94 additions & 290 deletions

File tree

components/affix/__tests__/Affix.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useEffect, useRef } from 'react';
22

33
import Affix from '..';
44
import { accessibilityTest } from '../../../tests/shared/accessibilityTest';
5+
import mountTest from '../../../tests/shared/mountTest';
56
import rtlTest from '../../../tests/shared/rtlTest';
67
import { render, triggerResize, waitFakeTimer } from '../../../tests/utils';
78
import Button from '../../button';
@@ -38,6 +39,7 @@ const AffixMounter: React.FC<AffixProps> = (props) => {
3839
};
3940

4041
describe('Affix Render', () => {
42+
mountTest(() => <Affix>test</Affix>);
4143
rtlTest(() => <Affix>test</Affix>);
4244
accessibilityTest(() => <Affix>test</Affix>);
4345

components/alert/__tests__/index.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import userEvent from '@testing-library/user-event';
44

55
import Alert from '..';
66
import { accessibilityTest } from '../../../tests/shared/accessibilityTest';
7+
import mountTest from '../../../tests/shared/mountTest';
78
import rtlTest from '../../../tests/shared/rtlTest';
89
import { act, fireEvent, render, screen, waitFakeTimer } from '../../../tests/utils';
910
import Button from '../../button';
@@ -17,6 +18,7 @@ const { resetWarned } = warning;
1718
const { ErrorBoundary } = Alert;
1819

1920
describe('Alert', () => {
21+
mountTest(Alert);
2022
rtlTest(Alert);
2123
accessibilityTest(Alert);
2224

components/anchor/__tests__/Anchor.test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { warning } from '@rc-component/util';
33
import scrollIntoView from 'scroll-into-view-if-needed';
44

55
import Anchor from '..';
6+
import mountTest from '../../../tests/shared/mountTest';
7+
import rtlTest from '../../../tests/shared/rtlTest';
68
import { act, fireEvent, render, waitFakeTimer } from '../../../tests/utils';
79
import Button from '../../button';
810
import type { AnchorDirection } from '../Anchor';
@@ -22,6 +24,8 @@ const getHashUrl = () => `Anchor-API-${idCounter++}`;
2224

2325
jest.mock('scroll-into-view-if-needed', () => jest.fn());
2426
describe('Anchor Render', () => {
27+
mountTest(Anchor);
28+
rtlTest(Anchor);
2529
const getBoundingClientRectMock = jest.spyOn(
2630
HTMLHeadingElement.prototype,
2731
'getBoundingClientRect',

components/anchor/__tests__/__snapshots__/Anchor.test.tsx.snap

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,26 @@ exports[`Anchor Render renders items correctly#horizontal 1`] = `
167167
</div>
168168
</div>
169169
`;
170+
171+
exports[`Anchor Render rtl render component should be rendered correctly in RTL direction 1`] = `
172+
<div
173+
class=""
174+
>
175+
<div
176+
class=""
177+
>
178+
<div
179+
class="css-var-root ant-anchor-css-var ant-anchor-wrapper ant-anchor-rtl"
180+
style="max-height: 100vh;"
181+
>
182+
<div
183+
class="ant-anchor"
184+
>
185+
<span
186+
class="ant-anchor-ink"
187+
/>
188+
</div>
189+
</div>
190+
</div>
191+
</div>
192+
`;

components/auto-complete/__tests__/__snapshots__/semantic.test.tsx.snap

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

components/auto-complete/__tests__/semantic.test.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import React from 'react';
22

33
import AutoComplete from '..';
4-
import mountTest from '../../../tests/shared/mountTest';
5-
import rtlTest from '../../../tests/shared/rtlTest';
64
import { render } from '../../../tests/utils';
75

86
describe('AutoComplete.Semantic', () => {
9-
mountTest(AutoComplete);
10-
rtlTest(AutoComplete);
11-
127
it('should support classNames and styles', () => {
138
const classNames = {
149
root: 'custom-root',

components/collapse/__tests__/__snapshots__/index.test.tsx.snap

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,36 @@ exports[`Collapse could override default openMotion 1`] = `
144144
</div>
145145
`;
146146

147+
exports[`Collapse rtl render component should be rendered correctly in RTL direction 1`] = `
148+
<div
149+
class="ant-collapse ant-collapse-icon-placement-start ant-collapse-rtl css-var-root"
150+
/>
151+
`;
152+
153+
exports[`Collapse rtl render component should be rendered correctly in RTL direction 2`] = `
154+
<div
155+
class="ant-collapse-item"
156+
>
157+
<div
158+
aria-disabled="false"
159+
class="ant-collapse-header"
160+
role="button"
161+
tabindex="0"
162+
>
163+
<div
164+
class="ant-collapse-expand-icon"
165+
>
166+
<i
167+
class="arrow"
168+
/>
169+
</div>
170+
<span
171+
class="ant-collapse-title"
172+
/>
173+
</div>
174+
</div>
175+
`;
176+
147177
exports[`Collapse should render extra node of panel 1`] = `
148178
<div
149179
class="ant-collapse ant-collapse-icon-placement-start css-var-root"

components/collapse/__tests__/index.test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import React from 'react';
22

33
import { resetWarned } from '../../_util/warning';
4+
import mountTest from '../../../tests/shared/mountTest';
5+
import rtlTest from '../../../tests/shared/rtlTest';
46
import { act, fireEvent, render, waitFakeTimer } from '../../../tests/utils';
57
import ConfigProvider from '../../config-provider';
68

79
describe('Collapse', () => {
810
const Collapse = require('..').default;
11+
const Panel = Collapse.Panel;
12+
13+
mountTest(Collapse);
14+
mountTest(Panel);
15+
rtlTest(Collapse);
16+
rtlTest(Panel);
917

1018
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
1119

components/color-picker/__tests__/__snapshots__/semantic.test.tsx.snap

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

components/color-picker/__tests__/semantic.test.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@ import React from 'react';
22
import { render } from '@testing-library/react';
33

44
import { resetWarned } from '../../_util/warning';
5-
import mountTest from '../../../tests/shared/mountTest';
6-
import rtlTest from '../../../tests/shared/rtlTest';
75
import ColorPicker from '../ColorPicker';
86

97
describe('ColorPicker.Semantic', () => {
10-
mountTest(ColorPicker);
11-
rtlTest(ColorPicker);
128
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
139
beforeEach(() => {
1410
resetWarned();

0 commit comments

Comments
 (0)