@interactors/core 0.3.0 → 1.0.0-rc1.2
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 +41 -0
- package/dist/cjs/constructor.js +28 -34
- 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/cjs/matcher.js +13 -1
- package/dist/cjs/matcher.js.map +1 -1
- package/dist/cjs/matchers/and.js +3 -0
- package/dist/cjs/matchers/and.js.map +1 -1
- package/dist/cjs/matchers/every.js +3 -0
- package/dist/cjs/matchers/every.js.map +1 -1
- package/dist/cjs/matchers/including.js +4 -0
- package/dist/cjs/matchers/including.js.map +1 -1
- package/dist/cjs/matchers/matching.js +4 -0
- package/dist/cjs/matchers/matching.js.map +1 -1
- package/dist/cjs/matchers/not.js +3 -0
- package/dist/cjs/matchers/not.js.map +1 -1
- package/dist/cjs/matchers/or.js +3 -0
- package/dist/cjs/matchers/or.js.map +1 -1
- package/dist/cjs/matchers/some.js +3 -0
- package/dist/cjs/matchers/some.js.map +1 -1
- package/dist/constructor.d.ts +3 -4
- package/dist/constructor.d.ts.map +1 -1
- package/dist/esm/constructor.js +27 -32
- 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/esm/matcher.js +11 -0
- package/dist/esm/matcher.js.map +1 -1
- package/dist/esm/matchers/and.js +4 -1
- package/dist/esm/matchers/and.js.map +1 -1
- package/dist/esm/matchers/every.js +4 -1
- package/dist/esm/matchers/every.js.map +1 -1
- package/dist/esm/matchers/including.js +4 -0
- package/dist/esm/matchers/including.js.map +1 -1
- package/dist/esm/matchers/matching.js +4 -0
- package/dist/esm/matchers/matching.js.map +1 -1
- package/dist/esm/matchers/not.js +4 -1
- package/dist/esm/matchers/not.js.map +1 -1
- package/dist/esm/matchers/or.js +4 -1
- package/dist/esm/matchers/or.js.map +1 -1
- package/dist/esm/matchers/some.js +4 -1
- package/dist/esm/matchers/some.js.map +1 -1
- package/dist/index.d.ts +3 -5
- 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/matcher.d.ts +2 -0
- package/dist/matcher.d.ts.map +1 -1
- package/dist/matchers/and.d.ts.map +1 -1
- package/dist/matchers/every.d.ts.map +1 -1
- package/dist/matchers/including.d.ts.map +1 -1
- package/dist/matchers/matching.d.ts.map +1 -1
- package/dist/matchers/not.d.ts.map +1 -1
- package/dist/matchers/or.d.ts.map +1 -1
- package/dist/matchers/some.d.ts.map +1 -1
- package/dist/specification.d.ts +40 -44
- package/dist/specification.d.ts.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -3
- package/src/constructor.ts +36 -45
- package/src/index.ts +3 -5
- package/src/inspector.ts +4 -4
- package/src/matcher.ts +11 -0
- package/src/matchers/and.ts +4 -1
- package/src/matchers/every.ts +4 -1
- package/src/matchers/including.ts +4 -1
- package/src/matchers/matching.ts +4 -1
- package/src/matchers/not.ts +4 -1
- package/src/matchers/or.ts +4 -1
- package/src/matchers/some.ts +4 -1
- package/src/specification.ts +47 -52
- 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
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
|
-
}
|