@brightspace-ui/testing 0.31.0 → 0.32.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/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.0",
5
+ "version": "0.32.0",
6
6
  "repository": "https://github.com/BrightspaceUI/testing.git",
7
7
  "scripts": {
8
8
  "lint": "eslint . --ext .js",
@@ -36,8 +36,9 @@
36
36
  "access": "public"
37
37
  },
38
38
  "dependencies": {
39
- "@rollup/plugin-node-resolve": "^15",
39
+ "@brightspace-ui/intl": "^3",
40
40
  "@open-wc/testing": "^3",
41
+ "@rollup/plugin-node-resolve": "^15",
41
42
  "@web/config-loader": "^0.2",
42
43
  "@web/dev-server": "^0.2",
43
44
  "@web/rollup-plugin-html": "^2",
@@ -1,4 +1,5 @@
1
1
  import { sendMouse, setViewport } from '@web/test-runner-commands';
2
+ import { getDocumentLocaleSettings } from '@brightspace-ui/intl/lib/common.js';
2
3
  import { nextFrame } from '@open-wc/testing';
3
4
 
4
5
  const DEFAULT_LANG = 'en',
@@ -6,7 +7,9 @@ const DEFAULT_LANG = 'en',
6
7
  DEFAULT_VIEWPORT_HEIGHT = 800,
7
8
  DEFAULT_VIEWPORT_WIDTH = 800;
8
9
 
9
- let currentLang = undefined,
10
+ const documentLocaleSettings = getDocumentLocaleSettings();
11
+
12
+ let
10
13
  currentMathjaxRenderLatex = DEFAULT_MATHJAX_RENDER_LATEX,
11
14
  currentRtl = false,
12
15
  currentViewportHeight = 0,
@@ -57,9 +60,9 @@ export async function reset(opts = {}) {
57
60
  currentRtl = opts.rtl;
58
61
  }
59
62
 
60
- if (opts.lang !== currentLang) {
61
- document.documentElement.setAttribute('lang', opts.lang);
62
- currentLang = opts.lang;
63
+ opts.lang ??= '';
64
+ if (documentLocaleSettings.lamguage !== opts.lang) {
65
+ document.documentElement.lang = opts.lang;
63
66
  awaitNextFrame = true;
64
67
  }
65
68
 
@@ -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)], []);
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 });