UNPKG

1.31 kBJavaScriptView Raw
1import { assert } from '@ember/debug';
2import { getPositionDifferences } from 'ember-tooltips/test-support/dom';
3import { validateSide } from 'ember-tooltips/test-support/utils';
4
5export 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 /* When the side is top or left, the greater number
18 is the target's position. Thus, we check that the
19 target's position is greater than the tooltip's
20 position. */
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}