@brightspace-ui/testing 1.21.1 → 1.23.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 +27 -0
- package/package.json +1 -1
- package/src/browser/commands.js +9 -0
- package/src/browser/index.js +1 -1
- package/src/server/wtr-config.js +3 -0
package/README.md
CHANGED
|
@@ -189,6 +189,33 @@ it('should click at coordinate', async() => {
|
|
|
189
189
|
});
|
|
190
190
|
```
|
|
191
191
|
|
|
192
|
+
Elements configured using the [Drag & Drop API](https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API) can be interacted with using `dragDropElems(sourceElem, destElem)`:
|
|
193
|
+
|
|
194
|
+
```javascript
|
|
195
|
+
import { dragDropElems } from '@brightspace-ui/testing';
|
|
196
|
+
|
|
197
|
+
it('should drag & drop', async() => {
|
|
198
|
+
const rootElem = await fixture(html`
|
|
199
|
+
<div>
|
|
200
|
+
<div id="source" draggable="true"></div>
|
|
201
|
+
<div id="dest"></div>
|
|
202
|
+
</div>
|
|
203
|
+
`);
|
|
204
|
+
// NOTE: destination must have "dragover" and "drop"
|
|
205
|
+
// event listeners added for the drag & drop API to function
|
|
206
|
+
await dragDropElems(
|
|
207
|
+
rootElem.querySelector('#source'),
|
|
208
|
+
rootElem.querySelector('#target')
|
|
209
|
+
);
|
|
210
|
+
// do assertions
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('should click at coordinate', async() => {
|
|
214
|
+
await clickAt(100, 200);
|
|
215
|
+
// do assertions
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
192
219
|
### Using the Keyboard
|
|
193
220
|
|
|
194
221
|
To place focus on an element using the keyboard, use `focusElem(elem)`. Doing so will trigger its `:focus-visible` CSS pseudo-class.
|
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.
|
|
5
|
+
"version": "1.23.0",
|
|
6
6
|
"repository": "https://github.com/BrightspaceUI/testing.git",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"lint": "npm run lint:eslint && npm run lint:style",
|
package/src/browser/commands.js
CHANGED
|
@@ -24,6 +24,15 @@ export async function clickElem(elem) {
|
|
|
24
24
|
return clickAt(position.x, position.y);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
export async function dragDropElems(elem, toElem) {
|
|
28
|
+
const fromPosition = getElementPosition(elem);
|
|
29
|
+
const toPosition = getElementPosition(toElem);
|
|
30
|
+
await sendMouse({ type: 'move', position: [fromPosition.x, fromPosition.y] });
|
|
31
|
+
await sendMouse({ type: 'down' });
|
|
32
|
+
await sendMouse({ type: 'move', position: [toPosition.x, toPosition.y] });
|
|
33
|
+
await sendMouse({ type: 'up' });
|
|
34
|
+
}
|
|
35
|
+
|
|
27
36
|
export async function focusElem(elem) {
|
|
28
37
|
await cmdSendKeys({ press: 'Shift' }); // Tab moves focus, Escape causes dismissible things to close
|
|
29
38
|
elem.focus({ focusVisible: true });
|
package/src/browser/index.js
CHANGED
|
@@ -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, focusElem, hoverAt, hoverElem, sendKeys, sendKeysElem, setViewport } from './commands.js';
|
|
4
|
+
export { clickAt, clickElem, dragDropElems, focusElem, hoverAt, hoverElem, sendKeys, sendKeysElem, setViewport } from './commands.js';
|
|
5
5
|
export { fixture } from './fixture.js';
|
|
6
6
|
export { runConstructor } from './constructor.js';
|
package/src/server/wtr-config.js
CHANGED
|
@@ -19,6 +19,7 @@ const ALLOWED_BROWSERS = Object.keys(BROWSER_MAP);
|
|
|
19
19
|
const DEFAULT_BROWSERS = [...new Set(Object.values(BROWSER_MAP))];
|
|
20
20
|
const TIMEZONE = '{"name":"Canada - Toronto","identifier":"America/Toronto"}';
|
|
21
21
|
const FONT_ASSETS = 'https://s.brightspace.com/lib/fonts/0.6.1/assets/';
|
|
22
|
+
const TEST_PAGE = '<script>window.isD2LTestPage = true;</script>';
|
|
22
23
|
const SUPPRESS_RESIZE_OBSERVER_ERRORS = `
|
|
23
24
|
<script>
|
|
24
25
|
window.addEventListener('error', (err) => {
|
|
@@ -53,6 +54,7 @@ export class WTRConfig {
|
|
|
53
54
|
`<!DOCTYPE html>
|
|
54
55
|
<html lang="en" data-timezone='${TIMEZONE}'>
|
|
55
56
|
<body>
|
|
57
|
+
${TEST_PAGE}
|
|
56
58
|
${SUPPRESS_RESIZE_OBSERVER_ERRORS}
|
|
57
59
|
<script type="module" src="${testFramework}"></script>
|
|
58
60
|
</body>
|
|
@@ -124,6 +126,7 @@ export class WTRConfig {
|
|
|
124
126
|
</style>
|
|
125
127
|
</head>
|
|
126
128
|
<body>
|
|
129
|
+
${TEST_PAGE}
|
|
127
130
|
${SUPPRESS_RESIZE_OBSERVER_ERRORS}
|
|
128
131
|
<script type="module" src="${testFramework}"></script>
|
|
129
132
|
</body>
|