-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
utils.ts
54 lines (48 loc) · 1.18 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { DisplayObject, Canvas, Document, CustomEvent } from '@antv/g';
import { G2Context, G2Spec, render } from '../../../src';
// @ts-ignore
// global.fetch = fetch;
export function assetElementStyle(
element: DisplayObject,
key: string,
value: any,
): void {
expect(element.getAttribute(key)).toBe(value);
}
export function assetElementsStyle(
elements: DisplayObject[],
key: string,
value: any,
): void {
elements.forEach((e) => assetElementStyle(e, key, value));
}
export function renderSync(
options: G2Spec,
context: G2Context = {},
): Promise<Document> {
return new Promise<Document>((resolve) => {
render(options, context, () => {
resolve((context.canvas as Canvas).document);
});
});
}
export function step(
element: DisplayObject,
event,
{ skip = false, ...rest }: Record<string, any> = {},
) {
return {
skip,
changeState: async () => {
element.dispatchEvent(new CustomEvent(event, rest));
},
};
}
export function disableDelay(options): G2Spec {
const { interactions = [] } = options;
const newInteractions = interactions.map((d) => ({ ...d, delay: 0 }));
return {
...options,
interactions: newInteractions,
};
}