@brightspace-ui/testing 0.31.1 → 0.32.1

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/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": "0.31.1",
5
+ "version": "0.32.1",
6
6
  "repository": "https://github.com/BrightspaceUI/testing.git",
7
7
  "scripts": {
8
8
  "lint": "eslint . --ext .js",
@@ -19,11 +19,29 @@ mocha.setup({
19
19
  });
20
20
  /* eslint-enable */
21
21
 
22
- function findTarget(elem) {
23
- if (!elem.shadowRoot) return elem;
24
- const nestedTarget = elem.shadowRoot.querySelector('.vdiff-target');
25
- if (!nestedTarget) return elem;
26
- return findTarget(nestedTarget);
22
+ function findTargets(elem) {
23
+ if (!elem.shadowRoot) return [elem];
24
+ const nestedTargets = elem.shadowRoot.querySelectorAll('.vdiff-target');
25
+ if (nestedTargets.length === 0) return [elem];
26
+ return Array.from(nestedTargets).reduce((acc, target) => [...acc, ...findTargets(target)], [elem]);
27
+ }
28
+
29
+ function findLargestRect(elems) {
30
+ let largestRect = { left: Number.MAX_SAFE_INTEGER, top: Number.MAX_SAFE_INTEGER, right: 0, bottom: 0 };
31
+ elems.forEach(elem => {
32
+ const targets = findTargets(elem);
33
+ targets.forEach(target => {
34
+ const targetRect = target.getBoundingClientRect();
35
+ largestRect = {
36
+ left: Math.floor(Math.min(largestRect.left, targetRect.left)),
37
+ top: Math.floor(Math.min(largestRect.top, targetRect.top)),
38
+ right: Math.ceil(Math.max(largestRect.right, targetRect.right)),
39
+ bottom: Math.ceil(Math.max(largestRect.bottom, targetRect.bottom))
40
+ };
41
+ });
42
+ });
43
+
44
+ return { x: largestRect.left, y: largestRect.top, width: largestRect.right - largestRect.left, height: largestRect.bottom - largestRect.top };
27
45
  }
28
46
 
29
47
  async function ScreenshotAndCompare(opts) {
@@ -36,8 +54,8 @@ async function ScreenshotAndCompare(opts) {
36
54
  const name = this.test.fullTitle();
37
55
  let rect = null;
38
56
  if (this.elem !== document) {
39
- const target = findTarget(this.elem);
40
- rect = target.getBoundingClientRect();
57
+ const elemsToInclude = [this.elem, ...this.elem.querySelectorAll('.vdiff-include')];
58
+ rect = findLargestRect(elemsToInclude);
41
59
  }
42
60
  const slowDuration = this.test.slow();
43
61
  let result = await executeServerCommand('brightspace-visual-diff-compare', { name, rect, slowDuration, opts });