forked from antvis/G2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec-tooltip.spec.ts
58 lines (54 loc) · 1.74 KB
/
spec-tooltip.spec.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
55
56
57
58
import { Canvas } from '@antv/g';
import * as chartTests from '../plots/tooltip';
import { kebabCase } from './utils/kebabCase';
import { filterTests } from './utils/filterTests';
import { renderSpec } from './utils/renderSpec';
import { sleep } from './utils/sleep';
import './utils/useSnapshotMatchers';
import './utils/useCustomFetch';
import { disableAnimation } from './utils/preprocess';
describe('Tooltips', () => {
const tests = filterTests(chartTests);
for (const [name, generateOptions] of tests) {
let gCanvas: Canvas;
it(`[Tooltip]: ${name}`, async () => {
try {
// @ts-ignore
const { steps: S } = generateOptions;
if (!S) {
throw new Error(`Missing steps for ${name}`);
}
// @ts-ignore
const { className = 'g2-tooltip' } = generateOptions;
// @ts-ignore
generateOptions.preprocess = disableAnimation;
// Render chart.
// @ts-ignore
generateOptions.before?.();
gCanvas = await renderSpec(generateOptions);
// Asset each state.
const steps = S({ canvas: gCanvas });
const dir = `${__dirname}/snapshots/tooltip/${kebabCase(name)}`;
for (let i = 0; i < steps.length; i++) {
const { changeState, skip = false } = steps[i];
if (!skip) {
await changeState();
await sleep(100);
await expect(gCanvas).toMatchDOMSnapshot(dir, `step${i}`, {
fileFormat: 'html',
selector: `.${className}`,
});
}
}
} finally {
gCanvas?.destroy();
// @ts-ignore
generateOptions.after?.();
await sleep(100);
}
});
}
afterEach(() => {
document.body.innerHTML = '';
});
});