Skip to content

Commit 3e2f87b

Browse files
test(js): update panel position tests
1 parent 54b8479 commit 3e2f87b

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

packages/autocomplete-js/src/__tests__/positioning.test.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,23 @@ const querySuggestionsFixturePlugin: AutocompletePlugin<
5151
describe('Panel positioning', () => {
5252
const rootPosition = {
5353
bottom: 0,
54-
height: 40,
54+
height: 20,
5555
left: 300,
5656
right: 990,
5757
top: 20,
5858
width: 600,
5959
x: 300,
60-
y: 40,
60+
y: 20,
6161
};
6262
const formPosition = {
6363
bottom: 0,
64-
height: 40,
64+
height: 20,
6565
left: 300,
6666
right: 990,
6767
top: 20,
6868
width: 600,
6969
x: 300,
70-
y: 40,
70+
y: 20,
7171
};
7272

7373
beforeAll(() => {
@@ -100,6 +100,11 @@ describe('Panel positioning', () => {
100100
});
101101

102102
const root = document.querySelector<HTMLDivElement>('.aa-Autocomplete');
103+
Object.defineProperty(root, 'offsetTop', {
104+
writable: true,
105+
configurable: true,
106+
value: 40,
107+
});
103108
root.getBoundingClientRect = jest.fn().mockReturnValue(rootPosition);
104109
const form = document.querySelector<HTMLFormElement>('.aa-Form');
105110
form.getBoundingClientRect = jest.fn().mockReturnValue(formPosition);
@@ -130,6 +135,11 @@ describe('Panel positioning', () => {
130135

131136
const root = document.querySelector<HTMLDivElement>('.aa-Autocomplete');
132137
root.getBoundingClientRect = jest.fn().mockReturnValue(rootPosition);
138+
Object.defineProperty(root, 'offsetTop', {
139+
writable: true,
140+
configurable: true,
141+
value: 40,
142+
});
133143
const form = document.querySelector<HTMLFormElement>('.aa-Form');
134144
form.getBoundingClientRect = jest.fn().mockReturnValue(formPosition);
135145

@@ -147,15 +157,16 @@ describe('Panel positioning', () => {
147157
input.blur();
148158

149159
// Move the root vertically
150-
root.getBoundingClientRect = jest.fn().mockReturnValue({
151-
...rootPosition,
152-
top: 40,
160+
Object.defineProperty(root, 'offsetTop', {
161+
writable: true,
162+
configurable: true,
163+
value: 90,
153164
});
154165

155166
input.focus();
156167

157168
expect(getByTestId(panelContainer, 'panel')).toHaveStyle({
158-
top: '80px',
169+
top: '110px',
159170
left: '300px',
160171
right: '1020px',
161172
});

0 commit comments

Comments
 (0)