@vonage/vivid-test-utils 5.2.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 +102 -0
- package/dist/actions.d.ts +31 -0
- package/dist/base.d.ts +38 -0
- package/dist/components.generated-DY7hz_DE.js +3311 -0
- package/dist/components.generated-DiskE4p5.cjs +1 -0
- package/dist/components.generated.d.ts +2581 -0
- package/dist/cypress.cjs +3 -0
- package/dist/cypress.d.ts +7 -0
- package/dist/cypress.js +133 -0
- package/dist/dom.cjs +3 -0
- package/dist/dom.d.ts +4 -0
- package/dist/dom.js +120 -0
- package/dist/drivers/cypress.d.ts +7 -0
- package/dist/drivers/dom.d.ts +5 -0
- package/dist/drivers/driver.d.ts +54 -0
- package/dist/drivers/playwright.d.ts +3 -0
- package/dist/jsdom-polyfill.cjs +1 -0
- package/dist/jsdom-polyfill.d.ts +1 -0
- package/dist/jsdom-polyfill.js +37 -0
- package/dist/playwright.cjs +3 -0
- package/dist/playwright.d.ts +4 -0
- package/dist/playwright.js +87 -0
- package/dist/queries.d.ts +20 -0
- package/dist/refs.d.ts +8 -0
- package/dist/selectors.d.ts +7 -0
- package/dist/utils/cssSelectors.d.ts +2 -0
- package/dist/utils/runSequence.d.ts +1 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Vivid Test Utils
|
|
2
|
+
|
|
3
|
+
A library to make it easier to interact with Vivid components in tests, that works with any frontend library and common testing frameworks.
|
|
4
|
+
|
|
5
|
+
## Motivation
|
|
6
|
+
|
|
7
|
+
Since Vivid is a Web Components library, writing tests can be more challenging. Depending on the testing framework used and how tests are set up, there can be various pitfalls and issues that slow down test development.
|
|
8
|
+
|
|
9
|
+
The library provides a unified way to select components, perform actions on them, and assert their state, that can be trusted to work.
|
|
10
|
+
|
|
11
|
+
Since the version of test utils are kept in sync with the Vivid version, these operations will also continue to work in the future, even when things change underneath.
|
|
12
|
+
|
|
13
|
+
## Testing Frameworks
|
|
14
|
+
|
|
15
|
+
The library supports the following testing frameworks:
|
|
16
|
+
|
|
17
|
+
- Playwright
|
|
18
|
+
- Cypress
|
|
19
|
+
- DOM: Can be used with a simulated DOM like JSDOM, e.g. in combination with Vue Test Utils or React Testing Library
|
|
20
|
+
|
|
21
|
+
The usage across all testing frameworks is the same. The only difference is in initialization and whether certain operations are asynchronous or not.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Installation
|
|
26
|
+
|
|
27
|
+
The library is provided as the `@vonage/vivid-test-utils` package. The version number is kept in sync with the Vivid library itself that it supports.
|
|
28
|
+
|
|
29
|
+
### Initialization
|
|
30
|
+
|
|
31
|
+
#### Playwright
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import { vividPlaywright } from '@vonage/vivid-test-utils/playwright';
|
|
35
|
+
|
|
36
|
+
// Create the vvd object using the Playwright page object and Playwright's expect function:
|
|
37
|
+
const vvd = vividPlaywright(page, expect);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
#### Cypress
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
import { vividCypress } from '@vonage/vivid-test-utils/cypress';
|
|
44
|
+
|
|
45
|
+
// Create the vvd object using the cy object:
|
|
46
|
+
const vvd = vividCypress(cy);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
#### DOM with Vue Test Utils
|
|
50
|
+
|
|
51
|
+
If you run your tests in a simulated DOM environment, it may not provide all features needed by Vivid.
|
|
52
|
+
|
|
53
|
+
The library comes with a polyfill for JSDOM that fills these gaps. You can load it as follows, e.g. in a global test setup file:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
import '@vonage/vivid-test-utils/jsdom-polyfill';
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
import { vividDOM } from '@vonage/vivid-test-utils/dom';
|
|
61
|
+
|
|
62
|
+
const wrapper = mount(Component, { attachTo: document.body });
|
|
63
|
+
// Create the vvd object using a Jest/Vitest or other Jasmine-style expect function and a root DOM node:
|
|
64
|
+
const vvd = vividDOM(expect, document.body);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Selecting Components
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
// Select with a component specific selector:
|
|
71
|
+
vvd.textField.byLabel('Email');
|
|
72
|
+
// Or by test ID, which will work for all components:
|
|
73
|
+
vvd.textField.byTestId('#email');
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Performing Actions
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
// After selecting a component, you can perform component specific actions:
|
|
80
|
+
vvd.textField.byLabel('Email').fill('user@example.com');
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
When using Playwright or DOM, actions will need to be awaited.
|
|
84
|
+
|
|
85
|
+
### Asserting Component State
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
// Use vvd.expect to make component specific assertions:
|
|
89
|
+
vvd.expect(vvd.textField.byLabel('Email')).toHaveValue('user@example.com');
|
|
90
|
+
// You can also assert the value of a specific prop:
|
|
91
|
+
vvd.expect(vvd.textField.byLabel('Email')).toHaveProp('appearance', 'ghost');
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
When using Playwright, expectations will need to be awaited.
|
|
95
|
+
|
|
96
|
+
### Selecting Multiple Components
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
// The all selector returns a collection of components:
|
|
100
|
+
vvd.textField.all().nth(0).fill('user@example.com');
|
|
101
|
+
vvd.expect(vvd.textField.all()).toHaveCount(2);
|
|
102
|
+
```
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { DriverT } from './drivers/driver';
|
|
2
|
+
import { BaseWrapper } from './base';
|
|
3
|
+
import { type AccordionItemWrapper, type ButtonWrapper, type ComboboxWrapper, type DatePickerWrapper, type DateRangePickerWrapper, type DateTimePickerWrapper, type NavDisclosureWrapper, type PaginationWrapper, TagWrapper, type TimePickerWrapper } from './components.generated';
|
|
4
|
+
export declare function click<D extends DriverT>(this: BaseWrapper<D>, locator: () => D['locator']): D['actionReturn'];
|
|
5
|
+
export declare function fill<D extends DriverT>(this: BaseWrapper<D>, locator: () => D['locator'], text: string): D['actionReturn'];
|
|
6
|
+
export declare function comboboxFill<D extends DriverT>(this: ComboboxWrapper<D>, text: string): D['actionReturn'];
|
|
7
|
+
export declare function clear<D extends DriverT>(this: BaseWrapper<D>, locator: () => D['locator']): D['actionReturn'];
|
|
8
|
+
export declare function comboboxClear<D extends DriverT>(this: ComboboxWrapper<D>): D['actionReturn'];
|
|
9
|
+
export declare function check<D extends DriverT>(this: BaseWrapper<D>, locator: () => D['locator']): D['actionReturn'];
|
|
10
|
+
export declare function uncheck<D extends DriverT>(this: BaseWrapper<D>, locator: () => D['locator']): D['actionReturn'];
|
|
11
|
+
export declare function focus<D extends DriverT>(this: BaseWrapper<D>, locator: () => D['locator']): D['actionReturn'];
|
|
12
|
+
export declare function blur<D extends DriverT>(this: BaseWrapper<D>, locator: () => D['locator']): D['actionReturn'];
|
|
13
|
+
export declare function hover<D extends DriverT>(this: BaseWrapper<D>, locator: () => D['locator']): D['actionReturn'];
|
|
14
|
+
export declare function selectOptionByValue<D extends DriverT>(this: BaseWrapper<D>, value: string): D['actionReturn'];
|
|
15
|
+
export declare function selectOptionByText<D extends DriverT>(this: BaseWrapper<D>, text: string): D['actionReturn'];
|
|
16
|
+
export declare function clickButton<D extends DriverT>(this: BaseWrapper<D>, locator: () => ButtonWrapper<D>): D['actionReturn'];
|
|
17
|
+
export declare function selectDate<D extends DriverT>(this: DatePickerWrapper<D>, date: string): D['actionReturn'];
|
|
18
|
+
interface PickerWrapper<D extends DriverT> extends BaseWrapper<D> {
|
|
19
|
+
pickerButton(): ButtonWrapper<D>;
|
|
20
|
+
clearButton(): ButtonWrapper<D>;
|
|
21
|
+
}
|
|
22
|
+
export declare function clearPicker<D extends DriverT>(this: PickerWrapper<D>): D['actionReturn'];
|
|
23
|
+
export declare function selectTime<D extends DriverT>(this: TimePickerWrapper<D>, time: string): D['actionReturn'];
|
|
24
|
+
export declare function selectDateRange<D extends DriverT>(this: DateRangePickerWrapper<D>, range: [string, string]): D['actionReturn'];
|
|
25
|
+
export declare function selectDateTime<D extends DriverT>(this: DateTimePickerWrapper<D>, dateTime: string): D['actionReturn'];
|
|
26
|
+
export declare function slideTo<D extends DriverT>(this: BaseWrapper<D>, track: () => D['locator'], thumb: () => D['locator'], value: number): D['actionReturn'];
|
|
27
|
+
export declare function clickPaginationPage<D extends DriverT>(this: PaginationWrapper<D>, pageIndex: number): D['actionReturn'];
|
|
28
|
+
export declare function toggleAccordionItem<D extends DriverT>(this: AccordionItemWrapper<D>, expand: boolean): D['actionReturn'];
|
|
29
|
+
export declare function toggleNavDisclosure<D extends DriverT>(this: NavDisclosureWrapper<D>, expand: boolean): D['actionReturn'];
|
|
30
|
+
export declare function toggleTag<D extends DriverT>(this: TagWrapper<D>, select: boolean): D['actionReturn'];
|
|
31
|
+
export {};
|
package/dist/base.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Driver, DriverT } from './drivers/driver';
|
|
2
|
+
export type Context<D extends DriverT> = {
|
|
3
|
+
rootLocator: D['rootLocator'];
|
|
4
|
+
driver: Driver<D>;
|
|
5
|
+
};
|
|
6
|
+
export type ComponentInfo = {
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
9
|
+
export declare abstract class BaseWrapper<D extends DriverT, E extends HTMLElement = HTMLElement> {
|
|
10
|
+
protected readonly ctx: Context<D>;
|
|
11
|
+
protected readonly locator: D['locator'];
|
|
12
|
+
constructor(ctx: Context<D>, locator: D['locator']);
|
|
13
|
+
abstract componentInfo: ComponentInfo;
|
|
14
|
+
unwrap(): D["locator"];
|
|
15
|
+
protected assert<A = unknown, Q = unknown>(message: string, query: (el: E, arg: A) => Q, expectedValue: Q, arg?: A): D["expectReturn"];
|
|
16
|
+
}
|
|
17
|
+
export declare abstract class BaseComponent<D extends DriverT, W extends BaseWrapper<D>> {
|
|
18
|
+
protected readonly ctx: Context<D>;
|
|
19
|
+
constructor(ctx: Context<D>);
|
|
20
|
+
abstract componentInfo: ComponentInfo;
|
|
21
|
+
abstract wrap(locator: D['locator']): W;
|
|
22
|
+
all: any;
|
|
23
|
+
}
|
|
24
|
+
export type ComponentCollectionLocator<D extends DriverT, W extends BaseWrapper<D>> = ComponentCollection<D, W>;
|
|
25
|
+
export declare class ComponentCollection<D extends DriverT, W extends BaseWrapper<D>> {
|
|
26
|
+
private ctx;
|
|
27
|
+
private readonly component;
|
|
28
|
+
private readonly locator;
|
|
29
|
+
constructor(ctx: Context<D>, component: BaseComponent<D, W>, locator: D['locatorMultiple']);
|
|
30
|
+
type: "collection";
|
|
31
|
+
nth: (n: number) => W;
|
|
32
|
+
}
|
|
33
|
+
export declare class ComponentCollectionExpectations<D extends DriverT> {
|
|
34
|
+
private readonly ctx;
|
|
35
|
+
private readonly locator;
|
|
36
|
+
constructor(ctx: Context<D>, locator: ComponentCollectionLocator<D, any>);
|
|
37
|
+
toHaveCount: (n: number) => D["expectReturn"];
|
|
38
|
+
}
|