1 | import { assert } from '@ember/debug';
|
2 | import { getPositionDifferences } from 'ember-tooltips/test-support/dom';
|
3 | import { validateSide } from 'ember-tooltips/test-support/utils';
|
4 |
|
5 | export default function assertTooltipSpacing(qunitAssert, options) {
|
6 | const { side, spacing } = options;
|
7 |
|
8 | validateSide(side, 'assertTooltipSpacing');
|
9 |
|
10 | if (typeof spacing !== 'number') {
|
11 | assert(`You must pass spacing as a number like assertTooltipSpacing(assert, { side: 'top', spacing: 10 });`);
|
12 | }
|
13 |
|
14 | const { expectedGreaterDistance, expectedLesserDistance } = getPositionDifferences(options);
|
15 | const actualSpacing = Math.round(expectedGreaterDistance - expectedLesserDistance);
|
16 |
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 | const isSideCorrect = expectedGreaterDistance > expectedLesserDistance;
|
23 | const isSpacingCorrect = actualSpacing === spacing;
|
24 |
|
25 | qunitAssert.ok(isSideCorrect && isSpacingCorrect,
|
26 | `assertTooltipSpacing(): the tooltip should be in the correct position:
|
27 | - Tooltip should be on the ${side} side of the target: ${isSideCorrect}.
|
28 | - On the ${side} side of the target, the tooltip should be ${spacing}px from the target but it was ${actualSpacing}px`);
|
29 | }
|