@brightspace-ui/testing 1.25.1 → 1.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -173,6 +173,24 @@ it('should click on element', async() => {
173
173
  });
174
174
  ```
175
175
 
176
+ To hover or click on a specific element with offset relative its origin (top-left corner), use `hoverElemAt(elem, x, y)` and `clickElemAt(elem, x, y)`. Useful for reducing shadowRoot snooping and element offset calculations.
177
+
178
+ ```javascript
179
+ import { clickElemAt, hoverElemAt } from '@brightspace-ui/testing';
180
+
181
+ it('should click element with offset from element origin', async() => {
182
+ const elem = await fixture(...);
183
+ await clickElemAt(elem, 25, 50);
184
+ // do assertions
185
+ });
186
+
187
+ it('should hover element with offset from element origin', async() => {
188
+ const elem = await fixture(...);
189
+ await hoverElemAt(elem, 25, 50);
190
+ // do assertions
191
+ });
192
+ ```
193
+
176
194
  Alternatively, to hover over or click at viewport coordinates with the mouse, use `hoverAt(x, y)` or `clickAt(x, y)`:
177
195
 
178
196
  ```javascript
@@ -593,7 +611,7 @@ my-elem {
593
611
  my-elem.faded-out {
594
612
  opacity: 0;
595
613
  }
596
- @media (prefers-reduced-motion: no-preference) {
614
+ @media (prefers-reduced-motion: no-preference) {
597
615
  my-elem {
598
616
  transition: opacity 0.2s ease-in-out;
599
617
  }
@@ -628,7 +646,7 @@ Refer to the [vdiff GitHub Action](https://github.com/BrightspaceUI/actions/tree
628
646
 
629
647
  ### Generating the Goldens
630
648
 
631
- To ensure a consistent environment, goldens checked into source control should be generated by [continuous integration](#continuous-integration).
649
+ To ensure a consistent environment, goldens checked into source control should be generated by [continuous integration](#continuous-integration).
632
650
 
633
651
  However, it can be helpful during development to generate a local version of the goldens to test and preview changes. This can be done by passing the `golden` sub-command:
634
652
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@brightspace-ui/testing",
3
3
  "description": "Utilities for testing front-end components and applications",
4
4
  "type": "module",
5
- "version": "1.25.1",
5
+ "version": "1.26.0",
6
6
  "repository": "https://github.com/BrightspaceUI/testing.git",
7
7
  "scripts": {
8
8
  "lint": "npm run lint:eslint && npm run lint:style",
@@ -33,7 +33,7 @@
33
33
  "@eslint/compat": "^1",
34
34
  "@eslint/eslintrc": "^3",
35
35
  "@eslint/js": "^9",
36
- "globals": "^1"
36
+ "globals": "^15"
37
37
  },
38
38
  "exports": {
39
39
  ".": "./src/browser/index.js"
@@ -5,6 +5,8 @@ export { setViewport } from './reset.js';
5
5
  function getElementPosition(elem) {
6
6
  const { x, y, width, height } = elem.getBoundingClientRect();
7
7
  return {
8
+ left: Math.floor(x + window.scrollX),
9
+ top: Math.floor(y + window.scrollY),
8
10
  x: Math.floor(x + window.scrollX + width / 2),
9
11
  y: Math.floor(y + window.scrollY + height / 2),
10
12
  };
@@ -24,6 +26,11 @@ export async function clickElem(elem) {
24
26
  return clickAt(position.x, position.y);
25
27
  }
26
28
 
29
+ export async function clickElemAt(elem, offsetX = 0, offsetY = 0) {
30
+ const position = getElementPosition(elem);
31
+ return clickAt(Math.floor(position.left + offsetX), Math.floor(position.top + offsetY));
32
+ }
33
+
27
34
  export async function dragDropElems(elem, toElem) {
28
35
  const fromPosition = getElementPosition(elem);
29
36
  const toPosition = getElementPosition(toElem);
@@ -48,6 +55,11 @@ export async function hoverElem(elem) {
48
55
  return hoverAt(position.x, position.y);
49
56
  }
50
57
 
58
+ export async function hoverElemAt(elem, offsetX = 0, offsetY = 0) {
59
+ const position = getElementPosition(elem);
60
+ return hoverAt(Math.floor(position.left + offsetX), Math.floor(position.top + offsetY));
61
+ }
62
+
51
63
  export async function sendKeys(action, keys) {
52
64
  const val = {};
53
65
  val[action] = keys;
@@ -1,6 +1,6 @@
1
1
  import './vdiff.js';
2
2
 
3
3
  export { assert, aTimeout, defineCE, expect, html, nextFrame, oneDefaultPreventedEvent, oneEvent, waitUntil } from '@open-wc/testing';
4
- export { clickAt, clickElem, dragDropElems, focusElem, hoverAt, hoverElem, sendKeys, sendKeysElem, setViewport } from './commands.js';
4
+ export { clickAt, clickElem, clickElemAt, dragDropElems, focusElem, hoverAt, hoverElem, hoverElemAt, sendKeys, sendKeysElem, setViewport } from './commands.js';
5
5
  export { fixture } from './fixture.js';
6
6
  export { runConstructor } from './constructor.js';