@@ -16,21 +16,58 @@ declare function valueToPoint(
16
16
}
17
17
18
18
describe ( 'e2e: svg' , ( ) => {
19
- const { page, click, count, setValue } = setupPuppeteer ( )
19
+ const { page, click, count, setValue, typeValue } = setupPuppeteer ( )
20
20
21
- async function assertStats ( total : number ) {
22
- await page ( ) . evaluate (
21
+ // assert the shape of the polygon is correct
22
+ async function assertPolygon ( total : number ) {
23
+ expect (
24
+ await page ( ) . evaluate (
25
+ total => {
26
+ const points = globalStats
27
+ . map ( ( stat , i ) => {
28
+ const point = valueToPoint ( stat . value , i , total )
29
+ return point . x + ',' + point . y
30
+ } )
31
+ . join ( ' ' )
32
+ return (
33
+ document . querySelector ( 'polygon' ) ! . attributes [ 0 ] . value === points
34
+ )
35
+ } ,
36
+ [ total ]
37
+ )
38
+ ) . toBe ( true )
39
+ }
40
+
41
+ // assert the position of each label is correct
42
+ async function assertLabels ( total : number ) {
43
+ const positions = await page ( ) . evaluate (
23
44
total => {
24
- const points = globalStats
25
- . map ( ( stat , i ) => {
26
- const point = valueToPoint ( stat . value , i , total )
27
- return point . x + ',' + point . y
28
- } )
29
- . join ( ' ' )
30
- return document . querySelector ( 'polygon' ) ! . attributes [ 0 ] . value === points
45
+ return globalStats . map ( ( stat , i ) => {
46
+ const point = valueToPoint ( + stat . value + 10 , i , total )
47
+ return [ point . x , point . y ]
48
+ } )
31
49
} ,
32
50
[ total ]
33
51
)
52
+ for ( let i = 0 ; i < total ; i ++ ) {
53
+ const textPosition = await page ( ) . $eval (
54
+ `text:nth-child(${ i + 3 } )` ,
55
+ node => [ + node . attributes [ 0 ] . value , + node . attributes [ 1 ] . value ]
56
+ )
57
+ expect ( textPosition ) . toEqual ( positions [ i ] )
58
+ }
59
+ }
60
+
61
+ // assert each value of stats is correct
62
+ async function assertStats ( expected : number [ ] ) {
63
+ const statsValue = await page ( ) . evaluate ( ( ) => {
64
+ return globalStats . map ( stat => + stat . value )
65
+ } )
66
+ expect ( statsValue ) . toEqual ( expected )
67
+ }
68
+
69
+ function nthRange ( n : number ) {
70
+ return `#demo div:nth-child(${ n + 1 } ) input[type="range"]`
34
71
}
35
72
36
73
async function testSvg ( apiType : 'classic' | 'composition' ) {
@@ -48,22 +85,58 @@ describe('e2e: svg', () => {
48
85
expect ( await count ( 'label' ) ) . toBe ( 6 )
49
86
expect ( await count ( 'button' ) ) . toBe ( 7 )
50
87
expect ( await count ( 'input[type="range"]' ) ) . toBe ( 6 )
51
- await assertStats ( 6 )
88
+ await assertPolygon ( 6 )
89
+ await assertLabels ( 6 )
90
+ await assertStats ( [ 100 , 100 , 100 , 100 , 100 , 100 ] )
91
+
92
+ await setValue ( nthRange ( 1 ) , '10' )
93
+ await assertPolygon ( 6 )
94
+ await assertLabels ( 6 )
95
+ await assertStats ( [ 10 , 100 , 100 , 100 , 100 , 100 ] )
52
96
53
97
await click ( 'button.remove' )
54
98
expect ( await count ( 'text' ) ) . toBe ( 5 )
55
99
expect ( await count ( 'label' ) ) . toBe ( 5 )
56
100
expect ( await count ( 'button' ) ) . toBe ( 6 )
57
101
expect ( await count ( 'input[type="range"]' ) ) . toBe ( 5 )
58
- await assertStats ( 5 )
102
+ await assertPolygon ( 5 )
103
+ await assertLabels ( 5 )
104
+ await assertStats ( [ 100 , 100 , 100 , 100 , 100 ] )
59
105
60
- await setValue ( 'input[name="newlabel"]' , 'foo' )
106
+ await typeValue ( 'input[name="newlabel"]' , 'foo' )
61
107
await click ( '#add > button' )
62
108
expect ( await count ( 'text' ) ) . toBe ( 6 )
63
109
expect ( await count ( 'label' ) ) . toBe ( 6 )
64
110
expect ( await count ( 'button' ) ) . toBe ( 7 )
65
111
expect ( await count ( 'input[type="range"]' ) ) . toBe ( 6 )
66
- await assertStats ( 6 )
112
+ await assertPolygon ( 6 )
113
+ await assertLabels ( 6 )
114
+ await assertStats ( [ 100 , 100 , 100 , 100 , 100 , 100 ] )
115
+
116
+ await setValue ( nthRange ( 1 ) , '10' )
117
+ await assertPolygon ( 6 )
118
+ await assertLabels ( 6 )
119
+ await assertStats ( [ 10 , 100 , 100 , 100 , 100 , 100 ] )
120
+
121
+ await setValue ( nthRange ( 2 ) , '20' )
122
+ await assertPolygon ( 6 )
123
+ await assertLabels ( 6 )
124
+ await assertStats ( [ 10 , 20 , 100 , 100 , 100 , 100 ] )
125
+
126
+ await setValue ( nthRange ( 6 ) , '60' )
127
+ await assertPolygon ( 6 )
128
+ await assertLabels ( 6 )
129
+ await assertStats ( [ 10 , 20 , 100 , 100 , 100 , 60 ] )
130
+
131
+ await click ( 'button.remove' )
132
+ await assertPolygon ( 5 )
133
+ await assertLabels ( 5 )
134
+ await assertStats ( [ 20 , 100 , 100 , 100 , 60 ] )
135
+
136
+ await setValue ( nthRange ( 1 ) , '10' )
137
+ await assertPolygon ( 5 )
138
+ await assertLabels ( 5 )
139
+ await assertStats ( [ 10 , 100 , 100 , 100 , 60 ] )
67
140
}
68
141
69
142
test (
0 commit comments