@@ -6,18 +6,17 @@ LICENSE file in the root directory of this source tree.
6
6
*/
7
7
import { urls } from "../const" ;
8
8
9
- jest . setTimeout ( 20 * 1000 ) ;
9
+ import { test , expect } from "@playwright/test" ;
10
10
11
- describe ( "Basic knobs" , ( ) => {
12
- beforeAll ( async ( ) => {
11
+ test . describe ( "Basic knobs" , ( ) => {
12
+ test . beforeEach ( async ( { page } ) => {
13
13
await page . goto ( urls . basic ) ;
14
- } ) ;
15
-
16
- beforeEach ( async ( ) => {
14
+ await page . waitForSelector ( "[data-storyloaded]" ) ;
17
15
await page . click ( '[data-testid="rv-reset"]' ) ;
18
16
} ) ;
19
-
20
- it ( "should select size compact, update component and input" , async ( ) => {
17
+ test ( "should select size compact, update component and input" , async ( {
18
+ page,
19
+ } ) => {
21
20
const codeOutput = `import * as React from "react";
22
21
import { Button, SIZE } from "your-button-component";
23
22
@@ -39,11 +38,13 @@ export default () => {
39
38
) ;
40
39
expect ( fontSize ) . toBe ( "14px" ) ;
41
40
const editorTextarea = await page . $ ( '[data-testid="rv-editor"] textarea' ) ;
42
- const text = await page . evaluate ( ( el ) => el . value , editorTextarea ) ;
41
+ const text = await page . evaluate ( ( el : any ) => el . value , editorTextarea ) ;
43
42
expect ( text ) . toBe ( codeOutput ) ;
44
43
} ) ;
45
44
46
- it ( "should check disabled, update component and input" , async ( ) => {
45
+ test ( "should check disabled, update component and input" , async ( {
46
+ page,
47
+ } ) => {
47
48
const codeOutput = `import * as React from "react";
48
49
import { Button } from "your-button-component";
49
50
@@ -61,11 +62,13 @@ export default () => {
61
62
) ;
62
63
expect ( isDisabled ) . toBeTruthy ( ) ;
63
64
const editorTextarea = await page . $ ( '[data-testid="rv-editor"] textarea' ) ;
64
- const text = await page . evaluate ( ( el ) => el . value , editorTextarea ) ;
65
+ const text = await page . evaluate ( ( el : any ) => el . value , editorTextarea ) ;
65
66
expect ( text ) . toBe ( codeOutput ) ;
66
67
} ) ;
67
68
68
- it ( "should change the children knob, update component and code" , async ( ) => {
69
+ test ( "should change the children knob, update component and code" , async ( {
70
+ page,
71
+ } ) => {
69
72
const childrenPropValue = "e2etest" ;
70
73
const codeOutput = `import * as React from "react";
71
74
import { Button } from "your-button-component";
@@ -77,20 +80,20 @@ export default () => {
77
80
</Button>
78
81
);
79
82
}` ;
80
- await page . focus ( '[data-testid="rv-knob-children"] textarea' ) ;
81
- for ( let i = 0 ; i < 5 ; i ++ ) {
82
- await page . keyboard . press ( "Delete" ) ;
83
- }
84
- await page . keyboard . type ( childrenPropValue ) ;
85
- await expect ( page ) . toMatchElement ( "#example-btn" , {
86
- text : childrenPropValue ,
87
- } ) ;
83
+ const textareaSelector = '[data-testid="rv-knob-children"] textarea' ;
84
+ await page . waitForSelector ( textareaSelector ) ;
85
+ await page . fill ( textareaSelector , childrenPropValue ) ;
86
+ await page . waitForTimeout ( 300 ) ; // waiting for debounce
87
+ const exampleBtn = await page . $ ( "#example-btn" ) ;
88
+ await expect ( exampleBtn ! . textContent ( ) ) . resolves . toBe ( childrenPropValue ) ;
88
89
const editorTextarea = await page . $ ( '[data-testid="rv-editor"] textarea' ) ;
89
- const text = await page . evaluate ( ( el ) => el . value , editorTextarea ) ;
90
+ const text = await page . evaluate ( ( el : any ) => el . value , editorTextarea ) ;
90
91
expect ( text ) . toBe ( codeOutput ) ;
91
92
} ) ;
92
93
93
- it ( "should change the onClick knob, update component and code" , async ( ) => {
94
+ test ( "should change the onClick knob, update component and code" , async ( {
95
+ page,
96
+ } ) => {
94
97
const onClickPropValue = `() => {document.querySelector('h1').innerText = "foo"}` ;
95
98
const codeOutput = `import * as React from "react";
96
99
import { Button } from "your-button-component";
@@ -106,36 +109,36 @@ export default () => {
106
109
</Button>
107
110
);
108
111
}` ;
109
- await page . focus ( '[data-testid="rv-knob-onClick"] textarea' ) ;
110
- for ( let i = 0 ; i < 20 ; i ++ ) {
111
- await page . keyboard . press ( "Delete" ) ;
112
- }
113
- await page . keyboard . type ( onClickPropValue ) ;
114
- await page . waitFor ( 300 ) ; // waiting for debounce
112
+ await page
113
+ . locator ( '[data-testid="rv-knob-onClick"] textarea' )
114
+ . fill ( onClickPropValue ) ;
115
+ await page . waitForTimeout ( 300 ) ; // waiting for debounce
115
116
await page . click ( "#example-btn" ) ;
116
117
const text = await page . evaluate ( ( ) => {
117
118
const h1 = document . querySelector ( "h1" ) ;
118
119
return h1 ? h1 . innerText : "" ;
119
120
} ) ;
120
121
expect ( text ) . toBe ( "foo" ) ;
121
122
const editorTextarea = await page . $ ( '[data-testid="rv-editor"] textarea' ) ;
122
- const editorText = await page . evaluate ( ( el ) => el . value , editorTextarea ) ;
123
+ const editorText = await page . evaluate (
124
+ ( el : any ) => el . value ,
125
+ editorTextarea ,
126
+ ) ;
123
127
expect ( editorText ) . toBe ( codeOutput ) ;
124
128
} ) ;
125
129
} ) ;
126
130
127
- describe ( "Basic actions" , ( ) => {
128
- beforeAll ( async ( ) => {
131
+ test . describe ( "Basic actions" , ( ) => {
132
+ test . beforeEach ( async ( { page } ) => {
129
133
await page . goto ( urls . basic ) ;
130
- } ) ;
131
-
132
- beforeEach ( async ( ) => {
134
+ await page . waitForSelector ( "[data-storyloaded]" ) ;
133
135
await page . click ( '[data-testid="rv-reset"]' ) ;
134
136
} ) ;
135
137
136
- it ( "should format the code snippet" , async ( ) => {
138
+ test ( "should format the code snippet" , async ( { page } ) => {
139
+ // todo fix bug with prettier formatting
137
140
const formattedCode = `import * as React from "react";
138
- import { Button } from "your-button-component";
141
+ import { value Button } from "your-button-component";
139
142
140
143
export default () => {
141
144
return (
@@ -151,29 +154,29 @@ export default () => {
151
154
</Button>
152
155
);
153
156
}` ;
154
- await page . focus ( '[data-testid="rv-editor"] textarea' ) ;
155
- for ( let i = 0 ; i < 232 ; i ++ ) {
156
- await page . keyboard . press ( "Delete" ) ;
157
- }
158
- await page . keyboard . type ( messyCode ) ;
159
- await page . waitFor ( 300 ) ; // waiting for debounce
157
+ await page . locator ( '[data-testid="rv-editor"] textarea' ) . fill ( messyCode ) ;
158
+ // for (let i = 0; i < 232; i++) {
159
+ // await page.keyboard.press("Delete");
160
+ // }
161
+ // await page.keyboard.type(messyCode);
162
+ await page . waitForTimeout ( 300 ) ; // waiting for debounce
160
163
await page . click ( '[data-testid="rv-format"]' ) ;
161
164
const editorTextarea = await page . $ ( '[data-testid="rv-editor"] textarea' ) ;
162
- const text = await page . evaluate ( ( el ) => el . value , editorTextarea ) ;
165
+ const text = await page . evaluate ( ( el : any ) => el . value , editorTextarea ) ;
163
166
expect ( text ) . toBe ( formattedCode ) ;
164
167
} ) ;
165
168
} ) ;
166
169
167
- describe ( "Basic editor" , ( ) => {
168
- beforeAll ( async ( ) => {
170
+ test . describe ( "Basic editor" , ( ) => {
171
+ test . beforeEach ( async ( { page } ) => {
169
172
await page . goto ( urls . basic ) ;
170
- } ) ;
171
-
172
- beforeEach ( async ( ) => {
173
+ await page . waitForSelector ( "[data-storyloaded]" ) ;
173
174
await page . click ( '[data-testid="rv-reset"]' ) ;
174
175
} ) ;
175
176
176
- it ( "should edit the code and update the knob and component" , async ( ) => {
177
+ test ( "should edit the code and update the knob and component" , async ( {
178
+ page,
179
+ } ) => {
177
180
const newCode = `import * as React from "react";
178
181
import { Button } from "your-button-component";
179
182
@@ -182,12 +185,8 @@ export default () => {
182
185
<Button onClick={() => alert("click")} disabled>Hello</Button>
183
186
);
184
187
}` ;
185
- await page . focus ( '[data-testid="rv-editor"] textarea' ) ;
186
- for ( let i = 0 ; i < 232 ; i ++ ) {
187
- await page . keyboard . press ( "Delete" ) ;
188
- }
189
- await page . keyboard . type ( newCode ) ;
190
- await page . waitFor ( 300 ) ; // waiting for debounce
188
+ await page . locator ( '[data-testid="rv-editor"] textarea' ) . fill ( newCode ) ;
189
+ await page . waitForTimeout ( 300 ) ; // waiting for debounce
191
190
const isButtonDisabled = await page . $eval (
192
191
"#example-btn" ,
193
192
( e ) => ( e as any ) . disabled ,
0 commit comments