1
1
import { test , expect , type Locator } from "@playwright/test"
2
2
3
- test . describe ( "interactive examples" , ( ) => {
4
- test ( "adds appearsIn field to hero query and gets correct response" , async ( {
5
- page,
6
- } ) => {
7
- await page . goto ( "/learn" )
8
- await page . waitForSelector ( ".cm-editor" , { timeout : 10000 } )
9
-
10
- const editors = page . locator ( ".cm-editor" )
11
- let heroEditor : Locator | null = null
12
-
13
- for ( let i = 0 ; i < ( await editors . count ( ) ) ; i ++ ) {
14
- const editor = editors . nth ( i )
15
- const content = await editor . textContent ( )
16
- if ( content && content . includes ( "hero" ) ) {
17
- heroEditor = editor
18
- break
19
- }
3
+ test ( "adds appearsIn field to hero query and gets correct response" , async ( {
4
+ page,
5
+ } ) => {
6
+ await page . goto ( "/learn" )
7
+ await page . waitForSelector ( ".cm-editor" , { timeout : 10000 } )
8
+
9
+ const editors = page . locator ( ".cm-editor" )
10
+ let heroEditor : Locator | null = null
11
+
12
+ for ( let i = 0 ; i < ( await editors . count ( ) ) ; i ++ ) {
13
+ const editor = editors . nth ( i )
14
+ const content = await editor . textContent ( )
15
+ if ( content && content . includes ( "hero" ) ) {
16
+ heroEditor = editor
17
+ break
20
18
}
21
-
22
- if ( ! heroEditor ) {
23
- throw new Error ( "Could not find hero GraphQL editor" )
19
+ }
20
+
21
+ if ( ! heroEditor ) {
22
+ throw new Error ( "Could not find hero GraphQL editor" )
23
+ }
24
+
25
+ const codeLines = heroEditor . locator ( ".cm-line" )
26
+
27
+ // Find the line containing "name" and click after it
28
+ for ( let i = 0 ; i < ( await codeLines . count ( ) ) ; i ++ ) {
29
+ const line = codeLines . nth ( i )
30
+ const lineText = await line . textContent ( )
31
+ if ( lineText && lineText . includes ( "name" ) ) {
32
+ await line . click ( )
33
+ // Move to end of line
34
+ await page . keyboard . press ( "End" )
35
+ // Add new line
36
+ await page . keyboard . press ( "Enter" )
37
+ break
24
38
}
39
+ }
25
40
26
- const codeLines = heroEditor . locator ( ".cm-line" )
27
-
28
- // Find the line containing "name" and click after it
29
- for ( let i = 0 ; i < ( await codeLines . count ( ) ) ; i ++ ) {
30
- const line = codeLines . nth ( i )
31
- const lineText = await line . textContent ( )
32
- if ( lineText && lineText . includes ( "name" ) ) {
33
- await line . click ( )
34
- // Move to end of line
35
- await page . keyboard . press ( "End" )
36
- // Add new line
37
- await page . keyboard . press ( "Enter" )
38
- break
39
- }
40
- }
41
+ await page . keyboard . type ( "ap" )
42
+ await page . keyboard . press ( "Control+Space" )
41
43
42
- await page . keyboard . type ( "ap ")
43
- await page . keyboard . press ( "Control+Space" )
44
+ const autoCompleteMenu = page . locator ( ".cm-tooltip-autocomplete ")
45
+ await expect ( autoCompleteMenu ) . toBeVisible ( { timeout : 5000 } )
44
46
45
- const autoCompleteMenu = page . locator ( ".cm-tooltip-autocomplete" )
46
- await expect ( autoCompleteMenu ) . toBeVisible ( { timeout : 5000 } )
47
+ const appearsInSuggestion = page
48
+ . locator ( ".cm-completionLabel" )
49
+ . filter ( { hasText : "appearsIn" } )
47
50
48
- const appearsInSuggestion = page
49
- . locator ( ".cm-completionLabel" )
50
- . filter ( { hasText : "appearsIn" } )
51
+ expect ( page . locator ( ".cm-completionDetail" ) . first ( ) ) . toHaveText ( "[Episode]!" )
51
52
52
- expect ( page . locator ( ".cm-completionDetail" ) . first ( ) ) . toHaveText (
53
- "[Episode]!" ,
54
- )
53
+ if ( await appearsInSuggestion . isVisible ( ) ) {
54
+ await appearsInSuggestion . click ( )
55
+ } else {
56
+ await page . keyboard . press ( "Enter" )
57
+ }
55
58
56
- if ( await appearsInSuggestion . isVisible ( ) ) {
57
- await appearsInSuggestion . click ( )
58
- } else {
59
- await page . keyboard . press ( "Enter" )
59
+ const resultViewer = page . locator ( ".result-window" ) . first ( )
60
+ await expect ( resultViewer ) . toBeVisible ( )
61
+
62
+ await expect
63
+ . poll ( async ( ) => {
64
+ const resultContent = await resultViewer . textContent ( )
65
+ const jsonMatch = resultContent ?. match ( / \{ [ \s \S ] * \} / )
66
+ if ( jsonMatch ) {
67
+ const responseJson = JSON . parse ( jsonMatch [ 0 ] )
68
+ return responseJson
69
+ }
70
+
71
+ return { }
72
+ } )
73
+ . toStrictEqual ( {
74
+ data : {
75
+ hero : {
76
+ name : "R2-D2" ,
77
+ appearsIn : [ "NEWHOPE" , "EMPIRE" , "JEDI" ] ,
78
+ } ,
79
+ } ,
80
+ } )
81
+ } )
82
+
83
+ test ( "edits variables and receives an expected mutation result" , async ( {
84
+ page,
85
+ } ) => {
86
+ await page . goto ( "/learn/mutations" )
87
+ await page . waitForLoadState ( "networkidle" )
88
+
89
+ // Find the mutation example that has GraphiQL enabled
90
+ const editors = page . locator ( ".cm-editor" )
91
+ let mutationEditor : Locator | null = null
92
+
93
+ for ( let i = 0 ; i < ( await editors . count ( ) ) ; i ++ ) {
94
+ const editor = editors . nth ( i )
95
+ const content = await editor . textContent ( )
96
+ if ( content && content . includes ( "CreateReviewForEpisode" ) ) {
97
+ mutationEditor = editor
98
+ break
60
99
}
100
+ }
61
101
62
- const resultViewer = page . locator ( ".result-window" ) . first ( )
102
+ if ( ! mutationEditor ) {
103
+ throw new Error ( "Could not find mutation GraphQL editor" )
104
+ }
105
+
106
+ const variableEditor = mutationEditor . locator ( ".variable-editor" ) . first ( )
107
+
108
+ if ( await variableEditor . isVisible ( ) ) {
109
+ await variableEditor . click ( )
110
+
111
+ await page . getByText ( '"This is a great movie!"' ) . first ( ) . click ( )
112
+ await page . keyboard . press ( "ControlOrMeta+ArrowRight" )
113
+ for ( let i = 0 ; i < 4 ; i ++ ) await page . keyboard . press ( "Alt+Shift+ArrowLeft" )
114
+ await page . keyboard . type ( 'almost as good as Andor"' )
115
+
116
+ const resultViewer = mutationEditor . locator ( ".result-window" )
63
117
await expect ( resultViewer ) . toBeVisible ( )
64
118
65
119
await expect
@@ -70,74 +124,15 @@ test.describe("interactive examples", () => {
70
124
const responseJson = JSON . parse ( jsonMatch [ 0 ] )
71
125
return responseJson
72
126
}
73
-
74
127
return { }
75
128
} )
76
129
. toStrictEqual ( {
77
130
data : {
78
- hero : {
79
- name : "R2-D2" ,
80
- appearsIn : [ "NEWHOPE" , "EMPIRE" , "JEDI" ] ,
131
+ createReview : {
132
+ stars : 5 ,
133
+ commentary : "This is almost as good as Andor" ,
81
134
} ,
82
135
} ,
83
136
} )
84
- } )
85
-
86
- test ( "edits variables and receives an expected mutation result" , async ( {
87
- page,
88
- } ) => {
89
- await page . goto ( "/learn/mutations" )
90
- await page . waitForLoadState ( "networkidle" )
91
-
92
- // Find the mutation example that has GraphiQL enabled
93
- const editors = page . locator ( ".cm-editor" )
94
- let mutationEditor : Locator | null = null
95
-
96
- for ( let i = 0 ; i < ( await editors . count ( ) ) ; i ++ ) {
97
- const editor = editors . nth ( i )
98
- const content = await editor . textContent ( )
99
- if ( content && content . includes ( "CreateReviewForEpisode" ) ) {
100
- mutationEditor = editor
101
- break
102
- }
103
- }
104
-
105
- if ( ! mutationEditor ) {
106
- throw new Error ( "Could not find mutation GraphQL editor" )
107
- }
108
-
109
- const variableEditor = mutationEditor . locator ( ".variable-editor" ) . first ( )
110
-
111
- if ( await variableEditor . isVisible ( ) ) {
112
- await variableEditor . click ( )
113
-
114
- await page . getByText ( '"This is a great movie!"' ) . first ( ) . click ( )
115
- await page . keyboard . press ( "ControlOrMeta+ArrowRight" )
116
- for ( let i = 0 ; i < 4 ; i ++ )
117
- await page . keyboard . press ( "Alt+Shift+ArrowLeft" )
118
- await page . keyboard . type ( 'almost as good as Andor"' )
119
-
120
- const resultViewer = mutationEditor . locator ( ".result-window" )
121
- await expect ( resultViewer ) . toBeVisible ( )
122
-
123
- await expect
124
- . poll ( async ( ) => {
125
- const resultContent = await resultViewer . textContent ( )
126
- const jsonMatch = resultContent ?. match ( / \{ [ \s \S ] * \} / )
127
- if ( jsonMatch ) {
128
- const responseJson = JSON . parse ( jsonMatch [ 0 ] )
129
- return responseJson
130
- }
131
- return { }
132
- } )
133
- . toStrictEqual ( {
134
- data : {
135
- createReview : {
136
- stars : 5 ,
137
- commentary : "This is almost as good as Andor" ,
138
- } ,
139
- } ,
140
- } )
141
- }
142
- } )
137
+ }
143
138
} )
0 commit comments