Skip to content

Commit 548b2f5

Browse files
committed
Reduce one level of nesting in e2e test
1 parent ec39664 commit 548b2f5

File tree

1 file changed

+123
-125
lines changed

1 file changed

+123
-125
lines changed

test/e2e/graphql-interactive.spec.ts

Lines changed: 123 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -61,154 +61,152 @@ async function expectJsonResult(
6161
.toStrictEqual(expectedResult)
6262
}
6363

64-
test.describe("interactive examples", () => {
65-
test.describe("Learn", () => {
66-
test("adds appearsIn field to hero query and gets correct response", async ({
67-
page,
68-
}) => {
69-
await page.goto("/learn")
70-
await page.waitForSelector(".cm-editor", { timeout: 10000 })
64+
test.describe("Learn", () => {
65+
test("adds appearsIn field to hero query and gets correct response", async ({
66+
page,
67+
}) => {
68+
await page.goto("/learn")
69+
await page.waitForSelector(".cm-editor", { timeout: 10000 })
7170

72-
const heroEditor = await findEditorByContent(page, "hero")
71+
const heroEditor = await findEditorByContent(page, "hero")
7372

74-
await typeInQuery(page, heroEditor, "name", "ap")
75-
await page.keyboard.press("Control+Space")
73+
await typeInQuery(page, heroEditor, "name", "ap")
74+
await page.keyboard.press("Control+Space")
7675

77-
const autoCompleteMenu = page.locator(".cm-tooltip-autocomplete")
78-
await expect(autoCompleteMenu).toBeVisible({ timeout: 5000 })
76+
const autoCompleteMenu = page.locator(".cm-tooltip-autocomplete")
77+
await expect(autoCompleteMenu).toBeVisible({ timeout: 5000 })
7978

80-
const appearsInSuggestion = page
81-
.locator(".cm-completionLabel")
82-
.filter({ hasText: "appearsIn" })
79+
const appearsInSuggestion = page
80+
.locator(".cm-completionLabel")
81+
.filter({ hasText: "appearsIn" })
8382

84-
expect(page.locator(".cm-completionDetail").first()).toHaveText(
85-
"[Episode]!",
86-
)
83+
expect(page.locator(".cm-completionDetail").first()).toHaveText(
84+
"[Episode]!",
85+
)
8786

88-
if (await appearsInSuggestion.isVisible()) {
89-
await appearsInSuggestion.click()
90-
} else {
91-
await page.keyboard.press("Enter")
92-
}
87+
if (await appearsInSuggestion.isVisible()) {
88+
await appearsInSuggestion.click()
89+
} else {
90+
await page.keyboard.press("Enter")
91+
}
92+
93+
const resultViewer = page.locator(".result-window").first()
9394

94-
const resultViewer = page.locator(".result-window").first()
95+
await expectJsonResult(resultViewer, {
96+
data: {
97+
hero: {
98+
name: "R2-D2",
99+
appearsIn: ["NEWHOPE", "EMPIRE", "JEDI"],
100+
},
101+
},
102+
})
103+
})
104+
105+
test("edits variables and receives an expected mutation result", async ({
106+
page,
107+
}) => {
108+
await page.goto("/learn/mutations")
109+
await page.waitForLoadState("networkidle")
110+
111+
const mutationEditor = await findEditorByContent(
112+
page,
113+
"CreateReviewForEpisode",
114+
)
115+
116+
const variableEditor = mutationEditor.locator(".variable-editor").first()
117+
118+
if (await variableEditor.isVisible()) {
119+
await variableEditor.click()
120+
121+
await page.getByText('"This is a great movie!"').first().click()
122+
await page.keyboard.press("ControlOrMeta+ArrowRight")
123+
for (let i = 0; i < 4; i++)
124+
await page.keyboard.press("Alt+Shift+ArrowLeft")
125+
await page.keyboard.type('almost as good as Andor"')
126+
127+
const resultViewer = mutationEditor.locator(".result-window")
95128

96129
await expectJsonResult(resultViewer, {
97130
data: {
98-
hero: {
99-
name: "R2-D2",
100-
appearsIn: ["NEWHOPE", "EMPIRE", "JEDI"],
131+
createReview: {
132+
stars: 5,
133+
commentary: "This is almost as good as Andor",
101134
},
102135
},
103136
})
104-
})
137+
}
138+
})
139+
})
105140

106-
test("edits variables and receives an expected mutation result", async ({
107-
page,
108-
}) => {
109-
await page.goto("/learn/mutations")
110-
await page.waitForLoadState("networkidle")
111-
112-
const mutationEditor = await findEditorByContent(
113-
page,
114-
"CreateReviewForEpisode",
115-
)
116-
117-
const variableEditor = mutationEditor.locator(".variable-editor").first()
118-
119-
if (await variableEditor.isVisible()) {
120-
await variableEditor.click()
121-
122-
await page.getByText('"This is a great movie!"').first().click()
123-
await page.keyboard.press("ControlOrMeta+ArrowRight")
124-
for (let i = 0; i < 4; i++)
125-
await page.keyboard.press("Alt+Shift+ArrowLeft")
126-
await page.keyboard.type('almost as good as Andor"')
127-
128-
const resultViewer = mutationEditor.locator(".result-window")
129-
130-
await expectJsonResult(resultViewer, {
131-
data: {
132-
createReview: {
133-
stars: 5,
134-
commentary: "This is almost as good as Andor",
135-
},
136-
},
137-
})
138-
}
139-
})
141+
test.describe("Landing", () => {
142+
test.beforeEach(async ({ page }) => {
143+
await page.goto("/")
144+
await page.waitForLoadState("networkidle")
145+
page.locator(`text="How it works"`).scrollIntoViewIfNeeded()
140146
})
141147

142-
test.describe("Landing", () => {
143-
test.beforeEach(async ({ page }) => {
144-
await page.goto("/")
145-
await page.waitForLoadState("networkidle")
146-
page.locator(`text="How it works"`).scrollIntoViewIfNeeded()
147-
})
148+
test("allows editing query and gets updated results", async ({ page }) => {
149+
await page.waitForSelector(".cm-editor", { timeout: 10000 })
150+
151+
const editor = page.locator(".cm-editor").first()
152+
153+
await editor.click()
154+
155+
await typeInQuery(page, editor, "tagline", "contr")
156+
157+
await page.keyboard.press("Control+Space")
158+
let autoCompleteMenu = page.locator(".cm-tooltip-autocomplete")
159+
await expect(autoCompleteMenu).toBeVisible({ timeout: 5000 })
160+
await page.locator(".cm-completionLabel").click()
148161

149-
test("allows editing query and gets updated results", async ({ page }) => {
150-
await page.waitForSelector(".cm-editor", { timeout: 10000 })
151-
152-
const editor = page.locator(".cm-editor").first()
153-
154-
await editor.click()
155-
156-
await typeInQuery(page, editor, "tagline", "contr")
157-
158-
await page.keyboard.press("Control+Space")
159-
let autoCompleteMenu = page.locator(".cm-tooltip-autocomplete")
160-
await expect(autoCompleteMenu).toBeVisible({ timeout: 5000 })
161-
await page.locator(".cm-completionLabel").click()
162-
163-
await page.keyboard.type("(first: 2) {\n")
164-
await page.keyboard.type("cont")
165-
166-
await page.keyboard.press("Control+Space")
167-
autoCompleteMenu = page.locator(".cm-tooltip-autocomplete")
168-
await expect(autoCompleteMenu).toBeVisible({ timeout: 5000 })
169-
await page.locator(".cm-completionLabel").click()
170-
171-
const resultViewer = page.locator(".result-window").first()
172-
await expect(resultViewer).toBeVisible()
173-
174-
await expect
175-
.poll(async () => {
176-
const resultContent = await resultViewer.textContent()
177-
const jsonMatch = resultContent?.match(/\{[\s\S]*\}/)
178-
if (jsonMatch) {
179-
try {
180-
const data = JSON.parse(jsonMatch[0])
181-
if (data?.project?.contributors?.length === 2) {
182-
const contributors = data.project.contributors
183-
return (
184-
contributors[0].contributions >= contributors[1].contributions
185-
)
186-
}
187-
return false
188-
} catch {
189-
return false
162+
await page.keyboard.type("(first: 2) {\n")
163+
await page.keyboard.type("cont")
164+
165+
await page.keyboard.press("Control+Space")
166+
autoCompleteMenu = page.locator(".cm-tooltip-autocomplete")
167+
await expect(autoCompleteMenu).toBeVisible({ timeout: 5000 })
168+
await page.locator(".cm-completionLabel").click()
169+
170+
const resultViewer = page.locator(".result-window").first()
171+
await expect(resultViewer).toBeVisible()
172+
173+
await expect
174+
.poll(async () => {
175+
const resultContent = await resultViewer.textContent()
176+
const jsonMatch = resultContent?.match(/\{[\s\S]*\}/)
177+
if (jsonMatch) {
178+
try {
179+
const data = JSON.parse(jsonMatch[0])
180+
if (data?.project?.contributors?.length === 2) {
181+
const contributors = data.project.contributors
182+
return (
183+
contributors[0].contributions >= contributors[1].contributions
184+
)
190185
}
186+
return false
187+
} catch {
188+
return false
191189
}
192-
return false
193-
})
194-
.toBe(true)
195-
})
190+
}
191+
return false
192+
})
193+
.toBe(true)
194+
})
196195

197-
test("shows syntax errors", async ({ page }) => {
198-
await page.waitForSelector(".cm-editor", { timeout: 10000 })
196+
test("shows syntax errors", async ({ page }) => {
197+
await page.waitForSelector(".cm-editor", { timeout: 10000 })
199198

200-
const editor = page.locator(".cm-editor").first()
199+
const editor = page.locator(".cm-editor").first()
201200

202-
await editor.click()
203-
await page.keyboard.press("ControlOrMeta+a")
204-
await page.keyboard.press("Backspace")
201+
await editor.click()
202+
await page.keyboard.press("ControlOrMeta+a")
203+
await page.keyboard.press("Backspace")
205204

206-
const playButton = page.getByText("Run query")
207-
await playButton.click()
205+
const playButton = page.getByText("Run query")
206+
await playButton.click()
208207

209-
const resultViewer = page.locator(".result-window").first()
210-
const resultContent = await resultViewer.textContent()
211-
expect(resultContent).toContain("Syntax Error: Unexpected <EOF>.")
212-
})
208+
const resultViewer = page.locator(".result-window").first()
209+
const resultContent = await resultViewer.textContent()
210+
expect(resultContent).toContain("Syntax Error: Unexpected <EOF>.")
213211
})
214212
})

0 commit comments

Comments
 (0)