Skip to content

Commit 5f73f86

Browse files
authored
test: update popover position unit tests to pass with base styles (#9835)
1 parent 1031a9d commit 5f73f86

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

packages/popover/test/position.test.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import './not-animated-styles.js';
44
import '../src/vaadin-popover.js';
55

66
describe('position', () => {
7-
let popover, target, overlay;
7+
let popover, target, overlay, defaultOffset;
88

99
beforeEach(async () => {
1010
popover = fixtureSync('<vaadin-popover></vaadin-popover>');
@@ -15,59 +15,61 @@ describe('position', () => {
1515
popover.target = target;
1616
await nextRender();
1717
overlay = popover.shadowRoot.querySelector('vaadin-popover-overlay');
18+
// The default offset is 0px in core styles and 4px in base styles + 0.1px for rounding
19+
defaultOffset = 0.1 + parseInt(getComputedStyle(overlay).getPropertyValue('--_default-offset'));
1820
});
1921

2022
// Overlay above the target (position="top-*")
2123
function assertPlacedAbove(overlayRect, targetRect) {
22-
expect(overlayRect.bottom).to.be.closeTo(targetRect.top, 1);
24+
expect(overlayRect.bottom).to.be.closeTo(targetRect.top, defaultOffset);
2325
}
2426

2527
// Overlay below the target (position="bottom-*")
2628
function assertPlacedBelow(overlayRect, targetRect) {
27-
expect(overlayRect.top).to.be.closeTo(targetRect.bottom, 1);
29+
expect(overlayRect.top).to.be.closeTo(targetRect.bottom, defaultOffset);
2830
}
2931

3032
// Overlay before the target (position="start-*")
3133
function assertPlacedBefore(overlayRect, targetRect, dir) {
3234
const x1 = dir === 'rtl' ? 'left' : 'right';
3335
const x2 = dir === 'rtl' ? 'right' : 'left';
34-
expect(overlayRect[x1]).to.be.closeTo(targetRect[x2], 1);
36+
expect(overlayRect[x1]).to.be.closeTo(targetRect[x2], defaultOffset);
3537
}
3638

3739
// Overlay after the target (position="end-*")
3840
function assertPlacedAfter(overlayRect, targetRect, dir) {
3941
const x1 = dir === 'rtl' ? 'right' : 'left';
4042
const x2 = dir === 'rtl' ? 'left' : 'right';
41-
expect(overlayRect[x1]).to.be.closeTo(targetRect[x2], 1);
43+
expect(overlayRect[x1]).to.be.closeTo(targetRect[x2], defaultOffset);
4244
}
4345

4446
function assertStartAligned(overlayRect, targetRect, dir) {
4547
const x = dir === 'rtl' ? 'right' : 'left';
46-
expect(overlayRect[x]).to.be.closeTo(targetRect[x], 1);
48+
expect(overlayRect[x]).to.be.closeTo(targetRect[x], defaultOffset);
4749
}
4850

4951
function assertEndAligned(overlayRect, targetRect, dir) {
5052
const x = dir === 'rtl' ? 'left' : 'right';
51-
expect(overlayRect[x]).to.be.closeTo(targetRect[x], 1);
53+
expect(overlayRect[x]).to.be.closeTo(targetRect[x], defaultOffset);
5254
}
5355

5456
function assertTopAligned(overlayRect, targetRect) {
55-
expect(overlayRect.top).to.be.closeTo(targetRect.top, 1);
57+
expect(overlayRect.top).to.be.closeTo(targetRect.top, defaultOffset);
5658
}
5759

5860
function assertBottomAligned(overlayRect, targetRect) {
59-
expect(overlayRect.bottom).to.be.closeTo(targetRect.bottom, 1);
61+
expect(overlayRect.bottom).to.be.closeTo(targetRect.bottom, defaultOffset);
6062
}
6163

6264
function assertCenteredHorizontally(overlayRect, targetRect, dir) {
6365
const coord = dir === 'rtl' ? 'right' : 'left';
6466
const offset = targetRect.width / 2 - overlayRect.width / 2;
65-
expect(overlayRect[coord]).to.be.closeTo(targetRect[coord] + (dir === 'rtl' ? offset * -1 : offset), 1);
67+
expect(overlayRect[coord]).to.be.closeTo(targetRect[coord] + (dir === 'rtl' ? offset * -1 : offset), defaultOffset);
6668
}
6769

6870
function assertCenteredVertically(overlayRect, targetRect) {
6971
const offset = targetRect.height / 2 - overlayRect.height / 2;
70-
expect(overlayRect.top).to.be.closeTo(targetRect.top + offset, 1);
72+
expect(overlayRect.top).to.be.closeTo(targetRect.top + offset, defaultOffset);
7173
}
7274

7375
describe('default', () => {

0 commit comments

Comments
 (0)