Skip to content

Commit e7e0dcd

Browse files
committed
test: of it
1 parent 913e9dd commit e7e0dcd

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

examples/basic.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function renderRest(items: ItemType[]) {
4747

4848
const Demo = () => {
4949
const [responsive, setResponsive] = React.useState(true);
50-
const [data, setData] = React.useState(createData(2));
50+
const [data, setData] = React.useState(createData(1));
5151

5252
return (
5353
<div style={{ padding: 32 }}>
@@ -80,7 +80,7 @@ const Demo = () => {
8080
style={{
8181
border: '5px solid green',
8282
padding: 8,
83-
width: 100,
83+
maxWidth: 300,
8484
marginTop: 32,
8585
}}
8686
>

src/Overflow.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,9 @@ function Overflow<ItemType = any>(
185185
// We take `mergedData` as deps which may cause dead loop if it's dynamic generate.
186186
// ref: https://github.com/ant-design/ant-design/issues/36559
187187
if (
188-
displayCount === count
189-
// displayCount === count &&
190-
// (suffixFixedStartVal === undefined ||
191-
// suffixFixedStartVal === suffixFixedStart)
188+
displayCount === count &&
189+
(suffixFixedStartVal === undefined ||
190+
suffixFixedStartVal === suffixFixedStart)
192191
) {
193192
return;
194193
}
@@ -207,7 +206,6 @@ function Overflow<ItemType = any>(
207206

208207
// ================================= Size =================================
209208
function onOverflowResize(_: object, element: HTMLElement) {
210-
console.log('resize overflow');
211209
setContainerWidth(element.clientWidth);
212210
}
213211

@@ -239,7 +237,6 @@ function Overflow<ItemType = any>(
239237
}
240238

241239
useLayoutEffect(() => {
242-
console.log('Effect:', mergedContainerWidth, mergedRestWidth, mergedData);
243240
if (mergedContainerWidth && mergedRestWidth && mergedData) {
244241
let totalWidth = suffixWidth;
245242

tests/github.spec.tsx

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,28 @@ describe('Overflow.github', () => {
3434
jest.useRealTimers();
3535
});
3636

37-
const clientWidths = {
37+
const widths = {
3838
'rc-overflow': 100,
39+
'rc-overflow-item': 90,
40+
};
41+
42+
const propDef = {
43+
get() {
44+
let targetWidth = 0;
45+
Object.keys(widths).forEach(key => {
46+
if (this.className.includes(key)) {
47+
targetWidth = widths[key];
48+
}
49+
});
50+
51+
return targetWidth;
52+
},
3953
};
4054

4155
beforeAll(() => {
4256
spyElementPrototypes(HTMLDivElement, {
43-
clientWidth: {
44-
get() {
45-
let targetWidth = 0;
46-
Object.keys(clientWidths).forEach(key => {
47-
if (this.className.includes(key)) {
48-
targetWidth = clientWidths[key];
49-
}
50-
});
51-
52-
return targetWidth;
53-
},
54-
},
57+
clientWidth: propDef,
58+
offsetWidth: propDef,
5559
});
5660
});
5761

@@ -75,19 +79,29 @@ describe('Overflow.github', () => {
7579
/>,
7680
);
7781

78-
// width resize
82+
// width & rest resize
7983
await triggerResize(container.querySelector('.rc-overflow'));
80-
81-
setTimeout(() => {
82-
console.log(2333);
83-
}, 1000);
84+
await triggerResize(container.querySelector('.rc-overflow-item-rest'));
8485

8586
act(() => {
8687
jest.runAllTimers();
8788
});
89+
90+
const items = Array.from(
91+
container.querySelectorAll<HTMLDivElement>(
92+
'.rc-overflow-item:not(.rc-overflow-item-rest)',
93+
),
94+
);
95+
96+
for (let i = 0; i < items.length; i += 1) {
97+
await triggerResize(items[i]);
98+
}
8899
act(() => {
89100
jest.runAllTimers();
90101
});
91-
console.log(jest.getTimerCount());
102+
103+
expect(container.querySelector('.rc-overflow-item-rest')).toHaveStyle({
104+
opacity: 1,
105+
});
92106
});
93107
});

0 commit comments

Comments
 (0)