Skip to content

Commit a8965ea

Browse files
committed
Added 1 e2e test for DiffScene
1 parent 7e8e558 commit a8965ea

File tree

1 file changed

+73
-2
lines changed

1 file changed

+73
-2
lines changed

packages/api-explorer/e2e/diffScene.spec.ts

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const resultCardsSelector =
3636
'section#top div[class*=SpaceVertical] div[class*=Card]'
3737
const baseInputSelector = 'input#listbox-input-base'
3838
const compInputSelector = 'input#listbox-input-compare'
39+
const compOptionsInputSelector = 'input#listbox-input-options'
3940
const globalOptionsSelector = '#modal-root [role=option] span'
4041
const switchButtonSelector = '.switch-button'
4142

@@ -225,7 +226,9 @@ describe('Diff Scene', () => {
225226
// Check the URL
226227
// Would like to do this earlier, but not sure what to wait on
227228
const compUrl = page.url()
228-
expect(compUrl).toEqual(`${BASE_URL}/3.1/diff/4.0?sdk=py`)
229+
expect(compUrl).toEqual(
230+
`${BASE_URL}/3.1/diff/4.0?sdk=py&opts=missing%2Cparams%2Ctype%2Cbody%2Cresponse`
231+
)
229232

230233
// Check the results
231234
const diffResultCards = await page.$$(resultCardsSelector)
@@ -253,7 +256,9 @@ describe('Diff Scene', () => {
253256
await page.waitForTimeout(150)
254257

255258
const switchUrl = page.url()
256-
expect(switchUrl).toEqual(`${BASE_URL}/4.0/diff/3.1?sdk=py`)
259+
expect(switchUrl).toEqual(
260+
`${BASE_URL}/4.0/diff/3.1?sdk=py&opts=missing%2Cparams%2Ctype%2Cbody%2Cresponse`
261+
)
257262

258263
// Check the results again, even though they should be the same
259264
const diff40to31Page1Methods = await Promise.all(
@@ -265,4 +270,70 @@ describe('Diff Scene', () => {
265270
expect(diff40to31Page1Methods).toHaveLength(15)
266271
expect(diff40to31Page1Methods).toContain('delete_board_item')
267272
})
273+
274+
it('updates when a comparison option is toggled', async () => {
275+
await goToPage(`${BASE_URL}/3.1/diff/4.0`)
276+
277+
// expect default diff options in url
278+
expect(page.url()).toEqual(
279+
`${BASE_URL}/3.1/diff/4.0?sdk=py&opts=missing%2Cparams%2Ctype%2Cbody%2Cresponse`
280+
)
281+
282+
// "Base" input element
283+
const baseInputElement = await page.$(baseInputSelector)
284+
expect(baseInputElement).not.toBeNull()
285+
286+
// "Comparison" input element
287+
const compInputElement = await page.$(compInputSelector)
288+
expect(compInputElement).not.toBeNull()
289+
290+
// "Comparison Options" input element
291+
const compOptionsInputElement = await page.$(compOptionsInputSelector)
292+
expect(compOptionsInputElement).not.toBeNull()
293+
294+
// Check that initial results exist with default comparison options
295+
const initDiffResults = await page.$$(resultCardsSelector)
296+
expect(initDiffResults).not.toHaveLength(0)
297+
const initDiff31to40Page1Methods = await Promise.all(
298+
initDiffResults.map((resultCard) =>
299+
page.evaluate((el) => el.innerText.match(/^[a-z_]*/)[0], resultCard)
300+
)
301+
)
302+
expect(initDiff31to40Page1Methods).toHaveLength(15)
303+
expect(initDiff31to40Page1Methods).toContain('delete_alert')
304+
305+
// Click comparison input
306+
await compOptionsInputElement!.click()
307+
const compOptionsOnClick = await page.$$(globalOptionsSelector)
308+
expect(compOptionsOnClick).toHaveLength(6)
309+
310+
// Find an option containing the text Missing
311+
const missingOptionIndex = await page.$$eval(globalOptionsSelector, (els) =>
312+
els.findIndex((el) => el?.textContent?.match('Missing'))
313+
)
314+
const missingOption = compOptionsOnClick[missingOptionIndex]
315+
expect(missingOption).not.toBeUndefined()
316+
317+
// Click that option
318+
await missingOption.click()
319+
await page.waitForSelector(resultCardsSelector, { timeout: 5000 })
320+
321+
// Check the URL
322+
// Would like to do this earlier, but not sure what to wait on
323+
const compUrl = page.url()
324+
expect(compUrl).toEqual(
325+
`${BASE_URL}/3.1/diff/4.0?sdk=py&opts=params%2Ctype%2Cbody%2Cresponse`
326+
)
327+
328+
// Check that there are new results
329+
const newDiffResults = await page.$$(resultCardsSelector)
330+
expect(newDiffResults).not.toHaveLength(0)
331+
const newDiff31to40Page1Methods = await Promise.all(
332+
newDiffResults.map((resultCard) =>
333+
page.evaluate((el) => el.innerText.match(/^[a-z_]*/)[0], resultCard)
334+
)
335+
)
336+
expect(newDiff31to40Page1Methods).toHaveLength(15)
337+
expect(newDiff31to40Page1Methods).not.toContain('delete_alert')
338+
})
268339
})

0 commit comments

Comments
 (0)