Skip to content

Commit c061a4e

Browse files
committed
test: add test case
1 parent 43b1b6a commit c061a4e

File tree

1 file changed

+50
-6
lines changed

1 file changed

+50
-6
lines changed

tests/flipShift.test.tsx

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ const builtinPlacements = {
4848
shiftY: true,
4949
},
5050
},
51+
topShift: {
52+
points: ['bc', 'tc'],
53+
overflow: {
54+
shiftX: true,
55+
},
56+
htmlRegion: 'visibleFirst' as const,
57+
},
5158
bottom: {
5259
points: ['tc', 'bc'],
5360
overflow: {
@@ -72,7 +79,24 @@ const builtinPlacements = {
7279
};
7380

7481
describe('Trigger.Flip+Shift', () => {
82+
let spanRect = { x: 0, y: 0, width: 0, height: 0 };
83+
84+
beforeEach(() => {
85+
spanRect = {
86+
x: 0,
87+
y: 100,
88+
width: 100,
89+
height: 100,
90+
};
91+
92+
document.documentElement.scrollLeft = 0;
93+
});
94+
7595
beforeAll(() => {
96+
jest
97+
.spyOn(document.documentElement, 'scrollWidth', 'get')
98+
.mockReturnValue(1000);
99+
76100
// Viewport size
77101
spyElementPrototypes(HTMLElement, {
78102
clientWidth: {
@@ -96,12 +120,7 @@ describe('Trigger.Flip+Shift', () => {
96120
});
97121
spyElementPrototypes(HTMLSpanElement, {
98122
getBoundingClientRect() {
99-
return {
100-
x: 0,
101-
y: 100,
102-
width: 100,
103-
height: 100,
104-
};
123+
return spanRect;
105124
},
106125
});
107126
spyElementPrototypes(HTMLElement, {
@@ -146,4 +165,29 @@ describe('Trigger.Flip+Shift', () => {
146165
top: '100px',
147166
});
148167
});
168+
169+
it('top with visibleFirst region', async () => {
170+
spanRect.x = -1000;
171+
document.documentElement.scrollLeft = 500;
172+
173+
render(
174+
<Trigger
175+
popupVisible
176+
popupPlacement="topShift"
177+
builtinPlacements={builtinPlacements}
178+
popup={<strong>trigger</strong>}
179+
>
180+
<span className="target" />
181+
</Trigger>,
182+
);
183+
184+
await act(async () => {
185+
await Promise.resolve();
186+
});
187+
188+
// Just need check left < 0
189+
expect(document.querySelector('.rc-trigger-popup')).toHaveStyle({
190+
left: '-900px',
191+
});
192+
});
149193
});

0 commit comments

Comments
 (0)