Skip to content

Commit 7add058

Browse files
committed
test: move range-align into new-range and fix tests exceed time problem
1 parent cba76c7 commit 7add058

File tree

2 files changed

+138
-144
lines changed

2 files changed

+138
-144
lines changed

tests/new-range.spec.tsx

Lines changed: 138 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { act, fireEvent, render } from '@testing-library/react';
33
import dayjs, { type Dayjs } from 'dayjs';
44
import 'dayjs/locale/ar';
5-
import { spyElementPrototype } from 'rc-util/lib/test/domHook';
5+
import { spyElementPrototype, spyElementPrototypes } from 'rc-util/lib/test/domHook';
66
import { resetWarned } from 'rc-util/lib/warning';
77
import React from 'react';
88
import type { RangePickerProps } from '../src';
@@ -43,6 +43,89 @@ describe('NewPicker.Range', () => {
4343
jest.useRealTimers();
4444
});
4545

46+
let rangeRect = { x: 0, y: 0, width: 0, height: 0 };
47+
48+
beforeEach(() => {
49+
rangeRect = {
50+
x: 0,
51+
y: 0,
52+
width: 200,
53+
height: 100,
54+
};
55+
56+
document.documentElement.scrollLeft = 0;
57+
// jest.useFakeTimers();
58+
});
59+
60+
beforeAll(() => {
61+
jest.spyOn(document.documentElement, 'scrollWidth', 'get').mockReturnValue(1000);
62+
63+
// Viewport size
64+
spyElementPrototypes(HTMLElement, {
65+
clientWidth: {
66+
get: () => 400,
67+
},
68+
clientHeight: {
69+
get: () => 400,
70+
},
71+
});
72+
73+
// Popup size
74+
spyElementPrototypes(HTMLDivElement, {
75+
getBoundingClientRect() {
76+
if (this.className.includes('rc-picker-dropdown')) {
77+
return {
78+
x: 0,
79+
y: 0,
80+
width: 300,
81+
height: 100,
82+
};
83+
}
84+
if (this.className.includes('rc-picker-range')) {
85+
return rangeRect;
86+
}
87+
if (this.className.includes('rc-picker')) {
88+
return rangeRect;
89+
}
90+
},
91+
offsetWidth: {
92+
get() {
93+
if (this.className.includes('rc-picker-range-wrapper')) {
94+
return rangeRect.width;
95+
}
96+
if (this.className.includes('rc-picker-range-arrow')) {
97+
return 10;
98+
}
99+
if (this.className.includes('rc-picker-input')) {
100+
return 100;
101+
}
102+
if (this.className.includes('rc-picker-dropdown')) {
103+
return 300;
104+
}
105+
},
106+
},
107+
offsetLeft: {
108+
get() {
109+
if (this.className.includes('rc-picker-input')) {
110+
return 0;
111+
}
112+
},
113+
},
114+
});
115+
spyElementPrototypes(HTMLElement, {
116+
offsetParent: {
117+
get: () => document.body,
118+
},
119+
offsetWidth: {
120+
get() {
121+
if (this.tagName === 'BODY') {
122+
return 200;
123+
}
124+
},
125+
},
126+
});
127+
});
128+
46129
describe('PickerValue', () => {
47130
it('defaultPickerValue should reset every time when opened', () => {
48131
const { container } = render(
@@ -1098,7 +1181,7 @@ describe('NewPicker.Range', () => {
10981181
it('pass tabIndex', () => {
10991182
const { container } = render(
11001183
<div>
1101-
<DayRangePicker tabIndex={-1}/>
1184+
<DayRangePicker tabIndex={-1} />
11021185
</div>,
11031186
);
11041187

@@ -1338,4 +1421,57 @@ describe('NewPicker.Range', () => {
13381421
}
13391422
expect(existed).toBeTruthy();
13401423
});
1424+
1425+
describe('pupop aligned position', () => {
1426+
it('the arrow should be set to `inset-inline-start` when the popup is aligned to `bottomLeft`.', async () => {
1427+
render(<DayRangePicker open />);
1428+
1429+
await act(async () => {
1430+
jest.runAllTimers();
1431+
1432+
await Promise.resolve();
1433+
});
1434+
expect(document.querySelector('.rc-picker-range-arrow')).toHaveStyle({
1435+
'inset-inline-start': '0',
1436+
});
1437+
});
1438+
1439+
it('the arrow should be set to `inset-inline-end` when the popup is aligned to `bottomRight`.', async () => {
1440+
const mock = spyElementPrototypes(HTMLDivElement, {
1441+
getBoundingClientRect() {
1442+
if (this.className.includes('rc-picker-dropdown')) {
1443+
return {
1444+
x: 0,
1445+
y: 0,
1446+
width: 300,
1447+
height: 100,
1448+
};
1449+
}
1450+
if (this.className.includes('rc-picker-range')) {
1451+
return {
1452+
...rangeRect,
1453+
x: 300,
1454+
};
1455+
}
1456+
},
1457+
});
1458+
1459+
render(<DayRangePicker open />);
1460+
1461+
await act(async () => {
1462+
jest.runAllTimers();
1463+
1464+
await Promise.resolve();
1465+
});
1466+
expect(document.querySelector('.rc-picker-range-arrow')).toHaveStyle({
1467+
'inset-inline-end': '100px',
1468+
});
1469+
1470+
expect(document.querySelector('.rc-picker-active-bar')).toHaveStyle({
1471+
'inset-inline-end': '100px',
1472+
});
1473+
1474+
mock.mockRestore();
1475+
});
1476+
});
13411477
});

tests/range-align.spec.tsx

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

0 commit comments

Comments
 (0)