@interactors/core 0.3.0 → 0.4.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/CHANGELOG.md +13 -0
- package/dist/cjs/constructor.js +27 -33
- package/dist/cjs/constructor.js.map +1 -1
- package/dist/cjs/index.js +1 -20
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/inspector.js +1 -1
- package/dist/cjs/inspector.js.map +1 -1
- package/dist/constructor.d.ts +2 -3
- package/dist/constructor.d.ts.map +1 -1
- package/dist/esm/constructor.js +26 -31
- package/dist/esm/constructor.js.map +1 -1
- package/dist/esm/index.js +0 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/inspector.js +2 -2
- package/dist/esm/inspector.js.map +1 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/inspector.d.ts +2 -2
- package/dist/inspector.d.ts.map +1 -1
- package/dist/specification.d.ts +32 -36
- package/dist/specification.d.ts.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -3
- package/src/constructor.ts +32 -41
- package/src/index.ts +0 -4
- package/src/inspector.ts +4 -4
- package/src/specification.ts +39 -44
- package/dist/cjs/dispatch.js +0 -34
- package/dist/cjs/dispatch.js.map +0 -1
- package/dist/cjs/element/fill-in.js +0 -71
- package/dist/cjs/element/fill-in.js.map +0 -1
- package/dist/cjs/focused.js +0 -47
- package/dist/cjs/focused.js.map +0 -1
- package/dist/cjs/perform.js +0 -13
- package/dist/cjs/perform.js.map +0 -1
- package/dist/dispatch.d.ts +0 -6
- package/dist/dispatch.d.ts.map +0 -1
- package/dist/element/fill-in.d.ts +0 -12
- package/dist/element/fill-in.d.ts.map +0 -1
- package/dist/esm/dispatch.js +0 -26
- package/dist/esm/dispatch.js.map +0 -1
- package/dist/esm/element/fill-in.js +0 -67
- package/dist/esm/element/fill-in.js.map +0 -1
- package/dist/esm/focused.js +0 -41
- package/dist/esm/focused.js.map +0 -1
- package/dist/esm/perform.js +0 -9
- package/dist/esm/perform.js.map +0 -1
- package/dist/focused.d.ts +0 -30
- package/dist/focused.d.ts.map +0 -1
- package/dist/perform.d.ts +0 -3
- package/dist/perform.d.ts.map +0 -1
- package/src/dispatch.ts +0 -24
- package/src/element/fill-in.ts +0 -76
- package/src/focused.ts +0 -43
- package/src/perform.ts +0 -11
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fillIn = void 0;
|
|
4
|
-
const dispatch_1 = require("../dispatch");
|
|
5
|
-
// do a best effort at determining the key code
|
|
6
|
-
function guessCode(letter) {
|
|
7
|
-
if (letter.match(/^[a-zA-Z]$/)) {
|
|
8
|
-
return `Key${letter.toUpperCase()}`;
|
|
9
|
-
}
|
|
10
|
-
else if (letter.match(/^[0-9]$/)) {
|
|
11
|
-
return `Digit${letter}`;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
function clearText(element) {
|
|
15
|
-
if (element.value.length) {
|
|
16
|
-
setValue(element, "");
|
|
17
|
-
dispatch_1.dispatchInput(element, { inputType: 'deleteContentBackward', data: null });
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function enterText(element, value) {
|
|
21
|
-
for (let letter of value) {
|
|
22
|
-
if (dispatch_1.dispatchKeyDown(element, { key: letter, code: guessCode(letter) })) {
|
|
23
|
-
// don't change the value if the keydown event was stopped
|
|
24
|
-
setValue(element, element.value + letter);
|
|
25
|
-
// input is not dispatched if the keydown event was stopped
|
|
26
|
-
dispatch_1.dispatchInput(element, { inputType: 'insertText', data: letter });
|
|
27
|
-
}
|
|
28
|
-
// keyup is always dispatched
|
|
29
|
-
dispatch_1.dispatchKeyUp(element, { key: letter, code: guessCode(letter) });
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Use the prototype setter of the element in order to set the value, that way any behavior that monkey patches
|
|
34
|
-
* the element itself is circumvented. This has the effect of the value just "magically" appearing on the input
|
|
35
|
-
* element just like it does when the browser sets the value because of the default action of an event.
|
|
36
|
-
* We have to do this because React actually does do this monkey-patching as an optimization. Basically, they
|
|
37
|
-
* short-circuit syncing the react state whenever someone sets input.value and then ignore the next `change` event.
|
|
38
|
-
*
|
|
39
|
-
* See https://github.com/cypress-io/cypress/issues/536
|
|
40
|
-
*/
|
|
41
|
-
function setValue(element, value) {
|
|
42
|
-
let property = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(element), 'value');
|
|
43
|
-
if (property && property.set) {
|
|
44
|
-
property.set.call(element, value);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
// if the value property on the element protoype is not present
|
|
48
|
-
// then there are worse problems. But this is very typesafe!
|
|
49
|
-
element.value = value;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Fill in text into an element by emulating how a user would do it, first
|
|
54
|
-
* focusing the element, then filling in the text letter by letter, generating
|
|
55
|
-
* the appropriate keyboard events.
|
|
56
|
-
*
|
|
57
|
-
* @param element The element to fill in text in
|
|
58
|
-
* @param value The text value to fill in
|
|
59
|
-
*/
|
|
60
|
-
function fillIn(element, value) {
|
|
61
|
-
let originalValue = element.value;
|
|
62
|
-
element.focus();
|
|
63
|
-
clearText(element);
|
|
64
|
-
enterText(element, value);
|
|
65
|
-
if (originalValue !== value) {
|
|
66
|
-
dispatch_1.dispatchChange(element);
|
|
67
|
-
}
|
|
68
|
-
element.blur();
|
|
69
|
-
}
|
|
70
|
-
exports.fillIn = fillIn;
|
|
71
|
-
//# sourceMappingURL=fill-in.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fill-in.js","sourceRoot":"","sources":["../../../src/element/fill-in.ts"],"names":[],"mappings":";;;AAAA,0CAA4F;AAI5F,+CAA+C;AAC/C,SAAS,SAAS,CAAC,MAAc;IAC/B,IAAG,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;QAC7B,OAAO,MAAM,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC;KACrC;SAAM,IAAG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE;QACjC,OAAO,QAAQ,MAAM,EAAE,CAAC;KACzB;AACH,CAAC;AAED,SAAS,SAAS,CAAC,OAAyB;IAC1C,IAAG,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE;QACvB,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACtB,wBAAa,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,uBAAuB,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;KAC5E;AACH,CAAC;AAED,SAAS,SAAS,CAAC,OAAyB,EAAE,KAAa;IACzD,KAAI,IAAI,MAAM,IAAI,KAAK,EAAE;QACvB,IAAG,0BAAe,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;YACrE,0DAA0D;YAC1D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC;YAC1C,2DAA2D;YAC3D,wBAAa,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;SACnE;QACD,6BAA6B;QAC7B,wBAAa,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;KAClE;AACH,CAAC;AAGD;;;;;;;;GAQG;AACH,SAAS,QAAQ,CAAC,OAAyB,EAAE,KAAa;IACxD,IAAI,QAAQ,GAAG,MAAM,CAAC,wBAAwB,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;IACxF,IAAI,QAAQ,IAAI,QAAQ,CAAC,GAAG,EAAE;QAC5B,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;KACnC;SAAM;QACL,+DAA+D;QAC/D,4DAA4D;QAC5D,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;KACvB;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,MAAM,CAAC,OAAyB,EAAE,KAAa;IAC7D,IAAI,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC;IAElC,OAAO,CAAC,KAAK,EAAE,CAAC;IAEhB,SAAS,CAAC,OAAO,CAAC,CAAC;IACnB,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAE1B,IAAG,aAAa,KAAK,KAAK,EAAE;QAC1B,yBAAc,CAAC,OAAO,CAAC,CAAC;KACzB;IAED,OAAO,CAAC,IAAI,EAAE,CAAC;AACjB,CAAC;AAbD,wBAaC"}
|
package/dist/cjs/focused.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.blur = exports.focus = exports.focused = void 0;
|
|
5
|
-
/**
|
|
6
|
-
* Helper function for focused filters, returns whether the given element is focused.
|
|
7
|
-
*/
|
|
8
|
-
function focused(element) {
|
|
9
|
-
console.warn("usage of the focused() helper is deprecated, and will be removed from the public API. Instead, switch your interactor to extend the `HTML` interactor to inherit the `focused` filter");
|
|
10
|
-
return element.ownerDocument.activeElement === element;
|
|
11
|
-
}
|
|
12
|
-
exports.focused = focused;
|
|
13
|
-
/**
|
|
14
|
-
* Helper function for focus action, performs `element.focus()` on the selected element.
|
|
15
|
-
*
|
|
16
|
-
* Can be used with object property value shorthand in your interactor actions.
|
|
17
|
-
*
|
|
18
|
-
* ```js
|
|
19
|
-
* actions: {
|
|
20
|
-
* focus,
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
async function focus(interactor) {
|
|
25
|
-
console.warn("usage of the focus() helper is deprecated, and will be removed from the public API. Instead, switch your interactor to extend the `HTML` interactor to inherit the `focus()` action");
|
|
26
|
-
await interactor.perform((element) => element.focus());
|
|
27
|
-
}
|
|
28
|
-
exports.focus = focus;
|
|
29
|
-
;
|
|
30
|
-
/**
|
|
31
|
-
* Helper function for blur action, performs `element.blur()` on the selected element.
|
|
32
|
-
*
|
|
33
|
-
* Can be used with object property value shorthand in your interactor actions.
|
|
34
|
-
*
|
|
35
|
-
* ```js
|
|
36
|
-
* actions: {
|
|
37
|
-
* focus,
|
|
38
|
-
* }
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
async function blur(interactor) {
|
|
42
|
-
console.warn("usage of the blur() helper is deprecated, and will be removed from the public API. Instead, switch your interactor to extend the `HTML` interactor to inherit the `blur()` action");
|
|
43
|
-
await interactor.perform((element) => element.blur());
|
|
44
|
-
}
|
|
45
|
-
exports.blur = blur;
|
|
46
|
-
;
|
|
47
|
-
//# sourceMappingURL=focused.js.map
|
package/dist/cjs/focused.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"focused.js","sourceRoot":"","sources":["../../src/focused.ts"],"names":[],"mappings":";AAAA,uDAAuD;;;AAIvD;;GAEG;AACH,SAAgB,OAAO,CAAC,OAAgB;IACtC,OAAO,CAAC,IAAI,CAAC,uLAAuL,CAAC,CAAC;IACtM,OAAO,OAAO,CAAC,aAAa,CAAC,aAAa,KAAK,OAAO,CAAC;AACzD,CAAC;AAHD,0BAGC;AAED;;;;;;;;;;GAUG;AACI,KAAK,UAAU,KAAK,CAAwB,UAA8B;IAC/E,OAAO,CAAC,IAAI,CAAC,qLAAqL,CAAC,CAAC;IACpM,MAAM,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;AACxD,CAAC;AAHD,sBAGC;AAAA,CAAC;AAEF;;;;;;;;;;GAUG;AACI,KAAK,UAAU,IAAI,CAAwB,UAA8B;IAC9E,OAAO,CAAC,IAAI,CAAC,mLAAmL,CAAC,CAAC;IAClM,MAAM,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;AACvD,CAAC;AAHD,oBAGC;AAAA,CAAC"}
|
package/dist/cjs/perform.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.perform = void 0;
|
|
4
|
-
function perform(fn) {
|
|
5
|
-
console.warn('`perform` is deprecated, please use `({ perform }) => perform(...)` instead!');
|
|
6
|
-
return async (interactor, ...args) => {
|
|
7
|
-
return await interactor.perform(element => {
|
|
8
|
-
fn(element, ...args);
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
exports.perform = perform;
|
|
13
|
-
//# sourceMappingURL=perform.js.map
|
package/dist/cjs/perform.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"perform.js","sourceRoot":"","sources":["../../src/perform.ts"],"names":[],"mappings":";;;AAGA,SAAgB,OAAO,CAA2E,EAAoC;IACpI,OAAO,CAAC,IAAI,CAAC,8EAA8E,CAAC,CAAC;IAC7F,OAAO,KAAK,EAAE,UAA4B,EAAE,GAAG,IAAO,EAAE,EAAE;QACxD,OAAO,MAAM,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YACxC,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAPD,0BAOC"}
|
package/dist/dispatch.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare function dispatchChange(element: HTMLElement): boolean;
|
|
2
|
-
export declare function dispatchInput(element: HTMLElement, options?: InputEventInit): boolean;
|
|
3
|
-
export declare function dispatchKeyDown(element: HTMLElement, options?: KeyboardEventInit): boolean;
|
|
4
|
-
export declare function dispatchKeyUp(element: HTMLElement, options?: KeyboardEventInit): boolean;
|
|
5
|
-
export declare function dispatchClick(element: HTMLElement, options?: MouseEventInit): boolean;
|
|
6
|
-
//# sourceMappingURL=dispatch.d.ts.map
|
package/dist/dispatch.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../src/dispatch.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAG5D;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAGzF;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAG9F;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAG5F;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAGzF"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
declare type TextFieldElement = HTMLInputElement | HTMLTextAreaElement;
|
|
2
|
-
/**
|
|
3
|
-
* Fill in text into an element by emulating how a user would do it, first
|
|
4
|
-
* focusing the element, then filling in the text letter by letter, generating
|
|
5
|
-
* the appropriate keyboard events.
|
|
6
|
-
*
|
|
7
|
-
* @param element The element to fill in text in
|
|
8
|
-
* @param value The text value to fill in
|
|
9
|
-
*/
|
|
10
|
-
export declare function fillIn(element: TextFieldElement, value: string): void;
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=fill-in.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fill-in.d.ts","sourceRoot":"","sources":["../../src/element/fill-in.ts"],"names":[],"mappings":"AAEA,aAAK,gBAAgB,GAAG,gBAAgB,GAAG,mBAAmB,CAAC;AAoD/D;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAarE"}
|
package/dist/esm/dispatch.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export function dispatchChange(element) {
|
|
2
|
-
var _a;
|
|
3
|
-
let Event = ((_a = element.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.Event) || window.Event;
|
|
4
|
-
return element.dispatchEvent(new Event('change', { bubbles: true, cancelable: false }));
|
|
5
|
-
}
|
|
6
|
-
export function dispatchInput(element, options = {}) {
|
|
7
|
-
var _a;
|
|
8
|
-
let InputEvent = ((_a = element.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.InputEvent) || window.InputEvent;
|
|
9
|
-
return element.dispatchEvent(new InputEvent('input', Object.assign({ bubbles: true, cancelable: false }, options)));
|
|
10
|
-
}
|
|
11
|
-
export function dispatchKeyDown(element, options = {}) {
|
|
12
|
-
var _a;
|
|
13
|
-
let KeyboardEvent = ((_a = element.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.KeyboardEvent) || window.KeyboardEvent;
|
|
14
|
-
return element.dispatchEvent(new KeyboardEvent('keydown', Object.assign({ bubbles: true, cancelable: true }, options)));
|
|
15
|
-
}
|
|
16
|
-
export function dispatchKeyUp(element, options = {}) {
|
|
17
|
-
var _a;
|
|
18
|
-
let KeyboardEvent = ((_a = element.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.KeyboardEvent) || window.KeyboardEvent;
|
|
19
|
-
return element.dispatchEvent(new KeyboardEvent('keyup', Object.assign({ bubbles: true, cancelable: true }, options)));
|
|
20
|
-
}
|
|
21
|
-
export function dispatchClick(element, options = {}) {
|
|
22
|
-
var _a;
|
|
23
|
-
let MouseEvent = ((_a = element.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.MouseEvent) || window.MouseEvent;
|
|
24
|
-
return element.dispatchEvent(new MouseEvent('click', Object.assign({ bubbles: true, cancelable: true }, options)));
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=dispatch.js.map
|
package/dist/esm/dispatch.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../src/dispatch.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,cAAc,CAAC,OAAoB;;IACjD,IAAI,KAAK,GAAG,CAAA,MAAA,OAAO,CAAC,aAAa,CAAC,WAAW,0CAAE,KAAK,KAAI,MAAM,CAAC,KAAK,CAAC;IACrE,OAAO,OAAO,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;AAC1F,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAoB,EAAE,UAA0B,EAAE;;IAC9E,IAAI,UAAU,GAAG,CAAA,MAAA,OAAO,CAAC,aAAa,CAAC,WAAW,0CAAE,UAAU,KAAI,MAAM,CAAC,UAAU,CAAC;IACpF,OAAO,OAAO,CAAC,aAAa,CAAC,IAAI,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;AACtH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,OAAoB,EAAE,UAA6B,EAAE;;IACnF,IAAI,aAAa,GAAG,CAAA,MAAA,OAAO,CAAC,aAAa,CAAC,WAAW,0CAAE,aAAa,KAAI,MAAM,CAAC,aAAa,CAAC;IAC7F,OAAO,OAAO,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;AAC1H,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAoB,EAAE,UAA6B,EAAE;;IACjF,IAAI,aAAa,GAAG,CAAA,MAAA,OAAO,CAAC,aAAa,CAAC,WAAW,0CAAE,aAAa,KAAI,MAAM,CAAC,aAAa,CAAC;IAC7F,OAAO,OAAO,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;AACxH,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAoB,EAAE,UAA0B,EAAE;;IAC9E,IAAI,UAAU,GAAG,CAAA,MAAA,OAAO,CAAC,aAAa,CAAC,WAAW,0CAAE,UAAU,KAAI,MAAM,CAAC,UAAU,CAAC;IACpF,OAAO,OAAO,CAAC,aAAa,CAAC,IAAI,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;AACrH,CAAC"}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { dispatchChange, dispatchInput, dispatchKeyDown, dispatchKeyUp } from '../dispatch';
|
|
2
|
-
// do a best effort at determining the key code
|
|
3
|
-
function guessCode(letter) {
|
|
4
|
-
if (letter.match(/^[a-zA-Z]$/)) {
|
|
5
|
-
return `Key${letter.toUpperCase()}`;
|
|
6
|
-
}
|
|
7
|
-
else if (letter.match(/^[0-9]$/)) {
|
|
8
|
-
return `Digit${letter}`;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
function clearText(element) {
|
|
12
|
-
if (element.value.length) {
|
|
13
|
-
setValue(element, "");
|
|
14
|
-
dispatchInput(element, { inputType: 'deleteContentBackward', data: null });
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function enterText(element, value) {
|
|
18
|
-
for (let letter of value) {
|
|
19
|
-
if (dispatchKeyDown(element, { key: letter, code: guessCode(letter) })) {
|
|
20
|
-
// don't change the value if the keydown event was stopped
|
|
21
|
-
setValue(element, element.value + letter);
|
|
22
|
-
// input is not dispatched if the keydown event was stopped
|
|
23
|
-
dispatchInput(element, { inputType: 'insertText', data: letter });
|
|
24
|
-
}
|
|
25
|
-
// keyup is always dispatched
|
|
26
|
-
dispatchKeyUp(element, { key: letter, code: guessCode(letter) });
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Use the prototype setter of the element in order to set the value, that way any behavior that monkey patches
|
|
31
|
-
* the element itself is circumvented. This has the effect of the value just "magically" appearing on the input
|
|
32
|
-
* element just like it does when the browser sets the value because of the default action of an event.
|
|
33
|
-
* We have to do this because React actually does do this monkey-patching as an optimization. Basically, they
|
|
34
|
-
* short-circuit syncing the react state whenever someone sets input.value and then ignore the next `change` event.
|
|
35
|
-
*
|
|
36
|
-
* See https://github.com/cypress-io/cypress/issues/536
|
|
37
|
-
*/
|
|
38
|
-
function setValue(element, value) {
|
|
39
|
-
let property = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(element), 'value');
|
|
40
|
-
if (property && property.set) {
|
|
41
|
-
property.set.call(element, value);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
// if the value property on the element protoype is not present
|
|
45
|
-
// then there are worse problems. But this is very typesafe!
|
|
46
|
-
element.value = value;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Fill in text into an element by emulating how a user would do it, first
|
|
51
|
-
* focusing the element, then filling in the text letter by letter, generating
|
|
52
|
-
* the appropriate keyboard events.
|
|
53
|
-
*
|
|
54
|
-
* @param element The element to fill in text in
|
|
55
|
-
* @param value The text value to fill in
|
|
56
|
-
*/
|
|
57
|
-
export function fillIn(element, value) {
|
|
58
|
-
let originalValue = element.value;
|
|
59
|
-
element.focus();
|
|
60
|
-
clearText(element);
|
|
61
|
-
enterText(element, value);
|
|
62
|
-
if (originalValue !== value) {
|
|
63
|
-
dispatchChange(element);
|
|
64
|
-
}
|
|
65
|
-
element.blur();
|
|
66
|
-
}
|
|
67
|
-
//# sourceMappingURL=fill-in.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fill-in.js","sourceRoot":"","sources":["../../../src/element/fill-in.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAI5F,+CAA+C;AAC/C,SAAS,SAAS,CAAC,MAAc;IAC/B,IAAG,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;QAC7B,OAAO,MAAM,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC;KACrC;SAAM,IAAG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE;QACjC,OAAO,QAAQ,MAAM,EAAE,CAAC;KACzB;AACH,CAAC;AAED,SAAS,SAAS,CAAC,OAAyB;IAC1C,IAAG,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE;QACvB,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACtB,aAAa,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,uBAAuB,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;KAC5E;AACH,CAAC;AAED,SAAS,SAAS,CAAC,OAAyB,EAAE,KAAa;IACzD,KAAI,IAAI,MAAM,IAAI,KAAK,EAAE;QACvB,IAAG,eAAe,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;YACrE,0DAA0D;YAC1D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC;YAC1C,2DAA2D;YAC3D,aAAa,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;SACnE;QACD,6BAA6B;QAC7B,aAAa,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;KAClE;AACH,CAAC;AAGD;;;;;;;;GAQG;AACH,SAAS,QAAQ,CAAC,OAAyB,EAAE,KAAa;IACxD,IAAI,QAAQ,GAAG,MAAM,CAAC,wBAAwB,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;IACxF,IAAI,QAAQ,IAAI,QAAQ,CAAC,GAAG,EAAE;QAC5B,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;KACnC;SAAM;QACL,+DAA+D;QAC/D,4DAA4D;QAC5D,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;KACvB;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,MAAM,CAAC,OAAyB,EAAE,KAAa;IAC7D,IAAI,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC;IAElC,OAAO,CAAC,KAAK,EAAE,CAAC;IAEhB,SAAS,CAAC,OAAO,CAAC,CAAC;IACnB,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAE1B,IAAG,aAAa,KAAK,KAAK,EAAE;QAC1B,cAAc,CAAC,OAAO,CAAC,CAAC;KACzB;IAED,OAAO,CAAC,IAAI,EAAE,CAAC;AACjB,CAAC"}
|
package/dist/esm/focused.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
/**
|
|
3
|
-
* Helper function for focused filters, returns whether the given element is focused.
|
|
4
|
-
*/
|
|
5
|
-
export function focused(element) {
|
|
6
|
-
console.warn("usage of the focused() helper is deprecated, and will be removed from the public API. Instead, switch your interactor to extend the `HTML` interactor to inherit the `focused` filter");
|
|
7
|
-
return element.ownerDocument.activeElement === element;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Helper function for focus action, performs `element.focus()` on the selected element.
|
|
11
|
-
*
|
|
12
|
-
* Can be used with object property value shorthand in your interactor actions.
|
|
13
|
-
*
|
|
14
|
-
* ```js
|
|
15
|
-
* actions: {
|
|
16
|
-
* focus,
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export async function focus(interactor) {
|
|
21
|
-
console.warn("usage of the focus() helper is deprecated, and will be removed from the public API. Instead, switch your interactor to extend the `HTML` interactor to inherit the `focus()` action");
|
|
22
|
-
await interactor.perform((element) => element.focus());
|
|
23
|
-
}
|
|
24
|
-
;
|
|
25
|
-
/**
|
|
26
|
-
* Helper function for blur action, performs `element.blur()` on the selected element.
|
|
27
|
-
*
|
|
28
|
-
* Can be used with object property value shorthand in your interactor actions.
|
|
29
|
-
*
|
|
30
|
-
* ```js
|
|
31
|
-
* actions: {
|
|
32
|
-
* focus,
|
|
33
|
-
* }
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export async function blur(interactor) {
|
|
37
|
-
console.warn("usage of the blur() helper is deprecated, and will be removed from the public API. Instead, switch your interactor to extend the `HTML` interactor to inherit the `blur()` action");
|
|
38
|
-
await interactor.perform((element) => element.blur());
|
|
39
|
-
}
|
|
40
|
-
;
|
|
41
|
-
//# sourceMappingURL=focused.js.map
|
package/dist/esm/focused.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"focused.js","sourceRoot":"","sources":["../../src/focused.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAIvD;;GAEG;AACH,MAAM,UAAU,OAAO,CAAC,OAAgB;IACtC,OAAO,CAAC,IAAI,CAAC,uLAAuL,CAAC,CAAC;IACtM,OAAO,OAAO,CAAC,aAAa,CAAC,aAAa,KAAK,OAAO,CAAC;AACzD,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAwB,UAA8B;IAC/E,OAAO,CAAC,IAAI,CAAC,qLAAqL,CAAC,CAAC;IACpM,MAAM,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;AACxD,CAAC;AAAA,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAwB,UAA8B;IAC9E,OAAO,CAAC,IAAI,CAAC,mLAAmL,CAAC,CAAC;IAClM,MAAM,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;AACvD,CAAC;AAAA,CAAC"}
|
package/dist/esm/perform.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export function perform(fn) {
|
|
2
|
-
console.warn('`perform` is deprecated, please use `({ perform }) => perform(...)` instead!');
|
|
3
|
-
return async (interactor, ...args) => {
|
|
4
|
-
return await interactor.perform(element => {
|
|
5
|
-
fn(element, ...args);
|
|
6
|
-
});
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=perform.js.map
|
package/dist/esm/perform.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"perform.js","sourceRoot":"","sources":["../../src/perform.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,OAAO,CAA2E,EAAoC;IACpI,OAAO,CAAC,IAAI,CAAC,8EAA8E,CAAC,CAAC;IAC7F,OAAO,KAAK,EAAE,UAA4B,EAAE,GAAG,IAAO,EAAE,EAAE;QACxD,OAAO,MAAM,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YACxC,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/focused.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Interactor } from './specification';
|
|
2
|
-
/**
|
|
3
|
-
* Helper function for focused filters, returns whether the given element is focused.
|
|
4
|
-
*/
|
|
5
|
-
export declare function focused(element: Element): boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Helper function for focus action, performs `element.focus()` on the selected element.
|
|
8
|
-
*
|
|
9
|
-
* Can be used with object property value shorthand in your interactor actions.
|
|
10
|
-
*
|
|
11
|
-
* ```js
|
|
12
|
-
* actions: {
|
|
13
|
-
* focus,
|
|
14
|
-
* }
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export declare function focus<E extends HTMLElement>(interactor: Interactor<E, any>): Promise<void>;
|
|
18
|
-
/**
|
|
19
|
-
* Helper function for blur action, performs `element.blur()` on the selected element.
|
|
20
|
-
*
|
|
21
|
-
* Can be used with object property value shorthand in your interactor actions.
|
|
22
|
-
*
|
|
23
|
-
* ```js
|
|
24
|
-
* actions: {
|
|
25
|
-
* focus,
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export declare function blur<E extends HTMLElement>(interactor: Interactor<E, any>): Promise<void>;
|
|
30
|
-
//# sourceMappingURL=focused.d.ts.map
|
package/dist/focused.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"focused.d.ts","sourceRoot":"","sources":["../src/focused.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;GAEG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAGjD;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,KAAK,CAAC,CAAC,SAAS,WAAW,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAGhG;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,IAAI,CAAC,CAAC,SAAS,WAAW,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAG/F"}
|
package/dist/perform.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { Interactor, FilterParams } from './specification';
|
|
2
|
-
export declare function perform<E extends Element, F extends FilterParams<any, any>, T extends unknown[]>(fn: (element: E, ...args: T) => void): (interactor: Interactor<E, F>, ...args: T) => Promise<void>;
|
|
3
|
-
//# sourceMappingURL=perform.d.ts.map
|
package/dist/perform.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"perform.d.ts","sourceRoot":"","sources":["../src/perform.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE3D,wBAAgB,OAAO,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAOnM"}
|
package/src/dispatch.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export function dispatchChange(element: HTMLElement): boolean {
|
|
2
|
-
let Event = element.ownerDocument.defaultView?.Event || window.Event;
|
|
3
|
-
return element.dispatchEvent(new Event('change', { bubbles: true, cancelable: false }));
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export function dispatchInput(element: HTMLElement, options: InputEventInit = {}): boolean {
|
|
7
|
-
let InputEvent = element.ownerDocument.defaultView?.InputEvent || window.InputEvent;
|
|
8
|
-
return element.dispatchEvent(new InputEvent('input', Object.assign({ bubbles: true, cancelable: false }, options)));
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function dispatchKeyDown(element: HTMLElement, options: KeyboardEventInit = {}): boolean {
|
|
12
|
-
let KeyboardEvent = element.ownerDocument.defaultView?.KeyboardEvent || window.KeyboardEvent;
|
|
13
|
-
return element.dispatchEvent(new KeyboardEvent('keydown', Object.assign({ bubbles: true, cancelable: true }, options)));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function dispatchKeyUp(element: HTMLElement, options: KeyboardEventInit = {}): boolean {
|
|
17
|
-
let KeyboardEvent = element.ownerDocument.defaultView?.KeyboardEvent || window.KeyboardEvent;
|
|
18
|
-
return element.dispatchEvent(new KeyboardEvent('keyup', Object.assign({ bubbles: true, cancelable: true }, options)));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function dispatchClick(element: HTMLElement, options: MouseEventInit = {}): boolean {
|
|
22
|
-
let MouseEvent = element.ownerDocument.defaultView?.MouseEvent || window.MouseEvent;
|
|
23
|
-
return element.dispatchEvent(new MouseEvent('click', Object.assign({ bubbles: true, cancelable: true }, options)));
|
|
24
|
-
}
|
package/src/element/fill-in.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { dispatchChange, dispatchInput, dispatchKeyDown, dispatchKeyUp } from '../dispatch';
|
|
2
|
-
|
|
3
|
-
type TextFieldElement = HTMLInputElement | HTMLTextAreaElement;
|
|
4
|
-
|
|
5
|
-
// do a best effort at determining the key code
|
|
6
|
-
function guessCode(letter: string): string | undefined {
|
|
7
|
-
if(letter.match(/^[a-zA-Z]$/)) {
|
|
8
|
-
return `Key${letter.toUpperCase()}`;
|
|
9
|
-
} else if(letter.match(/^[0-9]$/)) {
|
|
10
|
-
return `Digit${letter}`;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function clearText(element: TextFieldElement) {
|
|
15
|
-
if(element.value.length) {
|
|
16
|
-
setValue(element, "");
|
|
17
|
-
dispatchInput(element, { inputType: 'deleteContentBackward', data: null });
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function enterText(element: TextFieldElement, value: string) {
|
|
22
|
-
for(let letter of value) {
|
|
23
|
-
if(dispatchKeyDown(element, { key: letter, code: guessCode(letter) })) {
|
|
24
|
-
// don't change the value if the keydown event was stopped
|
|
25
|
-
setValue(element, element.value + letter);
|
|
26
|
-
// input is not dispatched if the keydown event was stopped
|
|
27
|
-
dispatchInput(element, { inputType: 'insertText', data: letter });
|
|
28
|
-
}
|
|
29
|
-
// keyup is always dispatched
|
|
30
|
-
dispatchKeyUp(element, { key: letter, code: guessCode(letter) });
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Use the prototype setter of the element in order to set the value, that way any behavior that monkey patches
|
|
37
|
-
* the element itself is circumvented. This has the effect of the value just "magically" appearing on the input
|
|
38
|
-
* element just like it does when the browser sets the value because of the default action of an event.
|
|
39
|
-
* We have to do this because React actually does do this monkey-patching as an optimization. Basically, they
|
|
40
|
-
* short-circuit syncing the react state whenever someone sets input.value and then ignore the next `change` event.
|
|
41
|
-
*
|
|
42
|
-
* See https://github.com/cypress-io/cypress/issues/536
|
|
43
|
-
*/
|
|
44
|
-
function setValue(element: TextFieldElement, value: string): void {
|
|
45
|
-
let property = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(element), 'value');
|
|
46
|
-
if (property && property.set) {
|
|
47
|
-
property.set.call(element, value);
|
|
48
|
-
} else {
|
|
49
|
-
// if the value property on the element protoype is not present
|
|
50
|
-
// then there are worse problems. But this is very typesafe!
|
|
51
|
-
element.value = value;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Fill in text into an element by emulating how a user would do it, first
|
|
57
|
-
* focusing the element, then filling in the text letter by letter, generating
|
|
58
|
-
* the appropriate keyboard events.
|
|
59
|
-
*
|
|
60
|
-
* @param element The element to fill in text in
|
|
61
|
-
* @param value The text value to fill in
|
|
62
|
-
*/
|
|
63
|
-
export function fillIn(element: TextFieldElement, value: string): void {
|
|
64
|
-
let originalValue = element.value;
|
|
65
|
-
|
|
66
|
-
element.focus();
|
|
67
|
-
|
|
68
|
-
clearText(element);
|
|
69
|
-
enterText(element, value);
|
|
70
|
-
|
|
71
|
-
if(originalValue !== value) {
|
|
72
|
-
dispatchChange(element);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
element.blur();
|
|
76
|
-
}
|
package/src/focused.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
|
|
3
|
-
import { Interactor } from './specification';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Helper function for focused filters, returns whether the given element is focused.
|
|
7
|
-
*/
|
|
8
|
-
export function focused(element: Element): boolean {
|
|
9
|
-
console.warn("usage of the focused() helper is deprecated, and will be removed from the public API. Instead, switch your interactor to extend the `HTML` interactor to inherit the `focused` filter");
|
|
10
|
-
return element.ownerDocument.activeElement === element;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Helper function for focus action, performs `element.focus()` on the selected element.
|
|
15
|
-
*
|
|
16
|
-
* Can be used with object property value shorthand in your interactor actions.
|
|
17
|
-
*
|
|
18
|
-
* ```js
|
|
19
|
-
* actions: {
|
|
20
|
-
* focus,
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export async function focus<E extends HTMLElement>(interactor: Interactor<E, any>): Promise<void> {
|
|
25
|
-
console.warn("usage of the focus() helper is deprecated, and will be removed from the public API. Instead, switch your interactor to extend the `HTML` interactor to inherit the `focus()` action");
|
|
26
|
-
await interactor.perform((element) => element.focus())
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Helper function for blur action, performs `element.blur()` on the selected element.
|
|
31
|
-
*
|
|
32
|
-
* Can be used with object property value shorthand in your interactor actions.
|
|
33
|
-
*
|
|
34
|
-
* ```js
|
|
35
|
-
* actions: {
|
|
36
|
-
* focus,
|
|
37
|
-
* }
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export async function blur<E extends HTMLElement>(interactor: Interactor<E, any>): Promise<void> {
|
|
41
|
-
console.warn("usage of the blur() helper is deprecated, and will be removed from the public API. Instead, switch your interactor to extend the `HTML` interactor to inherit the `blur()` action");
|
|
42
|
-
await interactor.perform((element) => element.blur())
|
|
43
|
-
};
|
package/src/perform.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { Interactor, FilterParams } from './specification';
|
|
3
|
-
|
|
4
|
-
export function perform<E extends Element, F extends FilterParams<any, any>, T extends unknown[]>(fn: (element: E, ...args: T) => void): (interactor: Interactor<E, F>, ...args: T) => Promise<void> {
|
|
5
|
-
console.warn('`perform` is deprecated, please use `({ perform }) => perform(...)` instead!');
|
|
6
|
-
return async (interactor: Interactor<E, F>, ...args: T) => {
|
|
7
|
-
return await interactor.perform(element => {
|
|
8
|
-
fn(element, ...args);
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
}
|