forked from visa/visa-chart-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit-test-label.ts
121 lines (107 loc) · 3.1 KB
/
unit-test-label.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* Copyright (c) 2020 Visa, Inc.
*
* This source code is licensed under the MIT license
* https://github.com/visa/visa-chart-components/blob/master/LICENSE
*
**/
import { SpecPage } from '@stencil/core/testing';
import { flushTransitions } from './unit-test-utils';
const labelSelector = '[data-testid=dataLabel]';
export const label_visible_default = {
prop: 'label.visible',
group: 'labels',
name: 'label should visible (or not) by default on load',
testProps: {},
testSelector: labelSelector,
testFunc: async (
component: any,
page: SpecPage,
testProps: object,
testSelector: string,
propName: string,
defaultValue: any
) => {
// ARRANGE
const EXPECTEDOPACITY = defaultValue.visible ? 1 : 0;
// if we have any testProps apply them
if (Object.keys(testProps).length) {
Object.keys(testProps).forEach(testProp => {
component[testProp] = testProps[testProp];
});
}
page.root.appendChild(component);
await page.waitForChanges();
// ACT
const label = await page.doc.querySelector(testSelector);
// ASSERT
expect(label).toEqualAttribute('opacity', EXPECTEDOPACITY);
}
};
export const label_visible_load = {
prop: 'label.visible',
group: 'labels',
name: 'label visibility should toggle on load',
testProps: {},
testSelector: labelSelector,
testFunc: async (
component: any,
page: SpecPage,
testProps: object,
testSelector: string,
propName: string,
defaultValue: any
) => {
// ARRANGE
const EXPECTEDOPACITY = defaultValue.visible ? 0 : 1;
component[propName] = { ...defaultValue, visible: !defaultValue.visible };
// if we have any testProps apply them
if (Object.keys(testProps).length) {
Object.keys(testProps).forEach(testProp => {
component[testProp] = testProps[testProp];
});
}
page.root.appendChild(component);
await page.waitForChanges();
// ACT
const label = await page.doc.querySelector(testSelector);
// ASSERT
expect(label).toEqualAttribute('opacity', EXPECTEDOPACITY);
}
};
export const label_visible_update = {
prop: 'label.visible',
group: 'labels',
name: 'label visibility should toggle on update',
testProps: {},
testSelector: labelSelector,
testFunc: async (
component: any,
page: SpecPage,
testProps: object,
testSelector: string,
propName: string,
defaultValue: any
) => {
// ARRANGE
const EXPECTEDOPACITY = defaultValue.visible ? 0 : 1;
// ACT RENDER
page.root.appendChild(component);
await page.waitForChanges();
// ACT UPDATE
// if we have any testProps apply them
component[propName] = { ...defaultValue, visible: !defaultValue.visible };
if (Object.keys(testProps).length) {
Object.keys(testProps).forEach(testProp => {
component[testProp] = testProps[testProp];
});
}
await page.waitForChanges();
// ACT
const label = await page.doc.querySelector(testSelector);
flushTransitions(label);
await page.waitForChanges();
// ASSERT
expect(label).toEqualAttribute('opacity', EXPECTEDOPACITY);
}
};