Skip to content

Commit 36d92ce

Browse files
committed
test: Add test case
1 parent b52287d commit 36d92ce

File tree

4 files changed

+48
-13
lines changed

4 files changed

+48
-13
lines changed

src/Overflow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function Overflow<ItemType = any>(
254254
{suffix && (
255255
<Item
256256
order={displayCount}
257-
prefixCls={prefixCls}
257+
prefixCls={itemPrefixCls}
258258
className={`${itemPrefixCls}-suffix`}
259259
responsive={isResponsive}
260260
registerSize={registerSuffixSize}

tests/responsive.spec.tsx

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ describe('Overflow.Responsive', () => {
4040
wrapper.initSize(100, 20); // [0][1][2][3][4][+2](5)(6)
4141
expect(wrapper.findItems()).toHaveLength(6);
4242
[true, true, true, true, false, false].forEach((display, i) => {
43-
expect(
44-
wrapper
45-
.findItems()
46-
.at(i)
47-
.props().display,
48-
).toBe(display);
43+
expect(wrapper.findItems().at(i).props().display).toBe(display);
4944
});
5045
expect(wrapper.findRest()).toHaveLength(1);
5146
expect(wrapper.findRest().text()).toEqual('+ 2 ...');
@@ -157,4 +152,41 @@ describe('Overflow.Responsive', () => {
157152
jest.runAllTimers();
158153
});
159154
});
155+
156+
describe('suffix', () => {
157+
it('ping the position', () => {
158+
const wrapper = mount(
159+
<Overflow<ItemType>
160+
data={getData(10)}
161+
itemKey="key"
162+
renderItem={renderItem}
163+
maxCount="responsive"
164+
suffix="Bamboo"
165+
/>,
166+
);
167+
168+
wrapper.initSize(100, 20);
169+
170+
expect(wrapper.findSuffix().props().style).toEqual(
171+
expect.objectContaining({ position: 'absolute', top: 0, left: 80 }),
172+
);
173+
});
174+
175+
it('too long to pin', () => {
176+
const wrapper = mount(
177+
<Overflow<ItemType>
178+
data={getData(1)}
179+
itemKey="key"
180+
renderItem={renderItem}
181+
maxCount="responsive"
182+
suffix="Bamboo"
183+
/>,
184+
);
185+
186+
wrapper.initSize(100, 20);
187+
wrapper.triggerItemResize(0, 90);
188+
189+
expect(wrapper.findSuffix().props().style.position).toBeFalsy();
190+
});
191+
});
160192
});

tests/setup.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const Adapter = require('enzyme-adapter-react-16');
33
const { act } = require('react-dom/test-utils');
44
require('regenerator-runtime/runtime');
55

6-
window.requestAnimationFrame = func => {
6+
window.requestAnimationFrame = (func) => {
77
window.setTimeout(func, 16);
88
};
99

@@ -12,10 +12,7 @@ Enzyme.configure({ adapter: new Adapter() });
1212
Object.assign(Enzyme.ReactWrapper.prototype, {
1313
triggerResize(clientWidth) {
1414
act(() => {
15-
this.find('ResizeObserver')
16-
.first()
17-
.props()
18-
.onResize({}, { clientWidth });
15+
this.find('ResizeObserver').first().props().onResize({}, { clientWidth });
1916
jest.runAllTimers();
2017
this.update();
2118
});
@@ -39,10 +36,15 @@ Object.assign(Enzyme.ReactWrapper.prototype, {
3936
},
4037
findItems() {
4138
return this.find('Item').filterWhere(
42-
item => item.props().className !== 'rc-overflow-item-rest',
39+
(item) =>
40+
item.props().className !== 'rc-overflow-item-rest' &&
41+
item.props().className !== 'rc-overflow-item-suffix',
4342
);
4443
},
4544
findRest() {
4645
return this.find('Item.rc-overflow-item-rest');
4746
},
47+
findSuffix() {
48+
return this.find('Item.rc-overflow-item-suffix');
49+
},
4850
});

tests/wrapper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface WrapperType extends ReactWrapper<any, any> {
88
initSize: (width: number, itemWidth: number) => WrapperType;
99
findItems: () => WrapperType;
1010
findRest: () => WrapperType;
11+
findSuffix: () => WrapperType;
1112
}
1213

1314
export function mount(...args: MountParam) {

0 commit comments

Comments
 (0)