@oracle/oraclejet-dom-driver 18.0.10
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.
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type TestDriver } from '@oracle/oraclejet-testing/UNSAFE_driver';
|
|
2
|
+
export declare const keyMap: {
|
|
3
|
+
[key: string]: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* A DOM-based TestDriver. This works in environments where the DOM is directly
|
|
7
|
+
* available, such as Jest or Karma.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DomDriver: TestDriver;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DomDriver = exports.keyMap = void 0;
|
|
7
|
+
const UNSAFE_driver_1 = require("@oracle/oraclejet-testing/UNSAFE_driver");
|
|
8
|
+
const user_event_1 = __importDefault(require("@testing-library/user-event"));
|
|
9
|
+
const userEvent = user_event_1.default.setup();
|
|
10
|
+
exports.keyMap = {
|
|
11
|
+
SHIFT: '[Shift]',
|
|
12
|
+
CONTROL: '[Control]',
|
|
13
|
+
// jest always runs in linux-like environment, so CONTROL_COMMAND is always 'Control'
|
|
14
|
+
CONTROL_COMMAND: '[Control]',
|
|
15
|
+
ALT: '[Alt]',
|
|
16
|
+
BACKSPACE: '[Backspace]',
|
|
17
|
+
TAB: '[Tab]',
|
|
18
|
+
ENTER: '[Enter]',
|
|
19
|
+
ESCAPE: '[Escape]',
|
|
20
|
+
PAGE_UP: '[PageUp]',
|
|
21
|
+
PAGE_DOWN: '[PageDown]',
|
|
22
|
+
END: '[End]',
|
|
23
|
+
HOME: '[Home]',
|
|
24
|
+
ARROW_LEFT: '[ArrowLeft]',
|
|
25
|
+
ARROW_UP: '[ArrowUp]',
|
|
26
|
+
ARROW_RIGHT: '[ArrowRight]',
|
|
27
|
+
ARROW_DOWN: '[ArrowDown]',
|
|
28
|
+
DELETE: '[Delete]',
|
|
29
|
+
F1: '[F1]',
|
|
30
|
+
F2: '[F2]',
|
|
31
|
+
F3: '[F3]',
|
|
32
|
+
F4: '[F4]',
|
|
33
|
+
F5: '[F5]',
|
|
34
|
+
F6: '[F6]',
|
|
35
|
+
F7: '[F7]',
|
|
36
|
+
F8: '[F8]',
|
|
37
|
+
F9: '[F9]',
|
|
38
|
+
F10: '[F10]',
|
|
39
|
+
F11: '[F11]',
|
|
40
|
+
F12: '[F12]'
|
|
41
|
+
};
|
|
42
|
+
function getMappedKey(key) {
|
|
43
|
+
if (typeof key === 'object') {
|
|
44
|
+
return exports.keyMap[key.key];
|
|
45
|
+
}
|
|
46
|
+
return key;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get an array of keys (chord) representing the given parameters, substituting modifier keys
|
|
50
|
+
* with their equivalent user-event values.
|
|
51
|
+
* Ex. "[CONTROL],a" -> "{CONTROL>}a{/CONTROL}"
|
|
52
|
+
* @param values The values from which to create a chord
|
|
53
|
+
* @returns The array of keys
|
|
54
|
+
*/
|
|
55
|
+
function getChord(values) {
|
|
56
|
+
const text = values.map(getMappedKey);
|
|
57
|
+
const modifierValues = Object.keys(UNSAFE_driver_1.ModifierKeys).map((m) => exports.keyMap[m]);
|
|
58
|
+
const modifierValueRegEx = new RegExp(`\\{(${modifierValues.map((m) => m.replace(/[\[\]]/g, '')).join('|')})>\\}`);
|
|
59
|
+
const chord = text.map((v) =>
|
|
60
|
+
// [ALT] => {ALT>}
|
|
61
|
+
modifierValues.includes(v) ? `${v.replace(/^\[/, '{').replace(/\]$/, '>}')}` : v);
|
|
62
|
+
// add modifier release values
|
|
63
|
+
return chord.reduceRight((accum, v) => {
|
|
64
|
+
const match = v.match(modifierValueRegEx);
|
|
65
|
+
if (match) {
|
|
66
|
+
accum.push(`{/${match[1]}}`);
|
|
67
|
+
}
|
|
68
|
+
return accum;
|
|
69
|
+
}, chord);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A DOM-based TestDriver. This works in environments where the DOM is directly
|
|
73
|
+
* available, such as Jest or Karma.
|
|
74
|
+
*/
|
|
75
|
+
exports.DomDriver = {
|
|
76
|
+
executeScript(script, ...args) {
|
|
77
|
+
if (typeof script === 'string') {
|
|
78
|
+
const remoteFunction = new Function(`
|
|
79
|
+
function execute() {
|
|
80
|
+
${script}
|
|
81
|
+
}
|
|
82
|
+
return execute.call(undefined, ${args.map(JSON.stringify).join(', ')});
|
|
83
|
+
`)();
|
|
84
|
+
return Promise.resolve(remoteFunction);
|
|
85
|
+
}
|
|
86
|
+
return Promise.resolve(script.apply(null, args));
|
|
87
|
+
},
|
|
88
|
+
findElement(query) {
|
|
89
|
+
const el = document.querySelector(query);
|
|
90
|
+
if (el) {
|
|
91
|
+
return Promise.resolve(wrapElement(el));
|
|
92
|
+
}
|
|
93
|
+
throw Error(`No element matching query "${query}"`);
|
|
94
|
+
},
|
|
95
|
+
findElements(query) {
|
|
96
|
+
return Promise.resolve(Array.from(document.querySelectorAll(query)).map(wrapElement));
|
|
97
|
+
},
|
|
98
|
+
async click(element, options = {}) {
|
|
99
|
+
const chord = getChord(options.modifiers || []);
|
|
100
|
+
// send the first half of the chord (key-down values), then click()
|
|
101
|
+
chord.length && (await userEvent.keyboard(chord.slice(0, chord.length / 2).join('')));
|
|
102
|
+
await userEvent.click(element.el);
|
|
103
|
+
// send the second half of the chord (key-up values)
|
|
104
|
+
chord.length && (await userEvent.keyboard(chord.slice(chord.length / 2).join('')));
|
|
105
|
+
},
|
|
106
|
+
async sendKeys(element, ...text) {
|
|
107
|
+
// ensure focus if blurred (re-focusing will clear out selection)
|
|
108
|
+
if (document.activeElement !== element.el) {
|
|
109
|
+
element.el.focus();
|
|
110
|
+
}
|
|
111
|
+
await userEvent.keyboard(getChord(text).join(''));
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
function wrapElement(element) {
|
|
115
|
+
return new ElementWrapper(element);
|
|
116
|
+
}
|
|
117
|
+
class ElementWrapper {
|
|
118
|
+
constructor(element) {
|
|
119
|
+
this.el = element;
|
|
120
|
+
}
|
|
121
|
+
findElement(query) {
|
|
122
|
+
const el = this.el.querySelector(query);
|
|
123
|
+
if (el) {
|
|
124
|
+
return Promise.resolve(wrapElement(el));
|
|
125
|
+
}
|
|
126
|
+
throw Error(`No element matching query "${query}"`);
|
|
127
|
+
}
|
|
128
|
+
findElements(query) {
|
|
129
|
+
return Promise.resolve(Array.from(this.el.querySelectorAll(query)).map(wrapElement));
|
|
130
|
+
}
|
|
131
|
+
getAttribute(attrName) {
|
|
132
|
+
return Promise.resolve(this.el.getAttribute(attrName));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DomDriver } from './DomDriver';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DomDriver = void 0;
|
|
4
|
+
var DomDriver_1 = require("./DomDriver");
|
|
5
|
+
Object.defineProperty(exports, "DomDriver", { enumerable: true, get: function () { return DomDriver_1.DomDriver; } });
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oracle/oraclejet-dom-driver",
|
|
3
|
+
"packageManager": "yarn@3.5.0",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"@oracle/oraclejet-testing": "18.0.10",
|
|
6
|
+
"@testing-library/user-event": "14.4.3"
|
|
7
|
+
},
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"@jest/globals": "29.6.2",
|
|
10
|
+
"@oracle/oraclejet-internal-test-utils": "workspace:*",
|
|
11
|
+
"@oracle/oraclejet-internal-ws-build": "workspace:^",
|
|
12
|
+
"@testing-library/preact": "3.2.3",
|
|
13
|
+
"copyfiles": "2.4.1",
|
|
14
|
+
"jest": "29.6.2",
|
|
15
|
+
"jest-environment-jsdom": "29.6.2",
|
|
16
|
+
"jsdom-global": "3.0.2",
|
|
17
|
+
"preact": "10.24.3",
|
|
18
|
+
"rimraf": "3.0.2",
|
|
19
|
+
"ts-jest": "29.1.0",
|
|
20
|
+
"typescript": "5.7.2"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "yarn clean; tsc --outDir dist/UNSAFE_DomDriver && yarn copy-files",
|
|
24
|
+
"clean": "rimraf dist",
|
|
25
|
+
"copy-files": "mergeJson package.json src/package-overrides.json dist/package.json",
|
|
26
|
+
"test": "jest -c test/jest.config.js",
|
|
27
|
+
"test-ci-headless": "yarn test"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
"./*": "./*/index.js"
|
|
31
|
+
},
|
|
32
|
+
"typesVersions": {
|
|
33
|
+
"*": {
|
|
34
|
+
"*": [
|
|
35
|
+
"./*/index.d.ts"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"version": "18.0.10"
|
|
40
|
+
}
|