Skip to content

Commit 6e364fa

Browse files
test: deflakes localization e2e suite (#14639)
The localization e2e suite would use the `runCopy` helper function which copies data from 1 locale to another locale and then navigates to that locale. Tests would fail intermittently because they did not wait for that route change to happen. Scenarios would arise where the request took longer than the next `changeLocale` call which changes the locale and navigates to that locale. So it looked like: - `runCopy` is called **but has not finished** - `changeLocale` runs and navigates user to new locale - `runCopy` finishes and navigates to the locale it copied to
1 parent 78d5be6 commit 6e364fa

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

test/localization/e2e.spec.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
arrayWithFallbackCollectionSlug,
3939
defaultLocale,
4040
englishTitle,
41+
hungarianLocale,
4142
localizedDraftsSlug,
4243
localizedPostsSlug,
4344
relationshipLocalizedSlug,
@@ -404,7 +405,7 @@ describe('Localization', () => {
404405
await createAndSaveDoc(page, url, { title })
405406
await openCopyToLocaleDrawer(page)
406407
await setToLocale(page, 'Spanish')
407-
await runCopy(page)
408+
await runCopy({ page, toLocale: spanishLocale })
408409
await expect(page.locator('#field-title')).toHaveValue(title)
409410
await changeLocale(page, defaultLocale)
410411
})
@@ -419,7 +420,7 @@ describe('Localization', () => {
419420

420421
await openCopyToLocaleDrawer(page)
421422
await setToLocale(page, 'Spanish')
422-
await runCopy(page)
423+
await runCopy({ page, toLocale: spanishLocale })
423424

424425
await expect(richTextField).toContainText(richTextContent)
425426
})
@@ -438,7 +439,7 @@ describe('Localization', () => {
438439

439440
await openCopyToLocaleDrawer(page)
440441
await setToLocale(page, 'English')
441-
await runCopy(page)
442+
await runCopy({ page, toLocale: defaultLocale })
442443

443444
await expect(arrayField).toHaveValue(sampleText)
444445
})
@@ -465,7 +466,7 @@ describe('Localization', () => {
465466
await setToLocale(page, 'Spanish')
466467
const overwriteCheckbox = page.locator('#field-overwriteExisting')
467468
await expect(overwriteCheckbox).not.toBeChecked()
468-
await runCopy(page)
469+
await runCopy({ page, toLocale: spanishLocale })
469470

470471
await expect(page.locator('#field-title')).toHaveValue(spanishTitle)
471472
await expect(page.locator('#field-description')).toHaveValue('Spanish description')
@@ -482,7 +483,7 @@ describe('Localization', () => {
482483
await setToLocale(page, 'Spanish')
483484
const overwriteCheckbox = page.locator('#field-overwriteExisting')
484485
await overwriteCheckbox.click()
485-
await runCopy(page)
486+
await runCopy({ page, toLocale: spanishLocale })
486487
await expect(page.locator('#field-title')).toHaveValue(englishTitle)
487488
await changeLocale(page, defaultLocale)
488489
})
@@ -508,15 +509,15 @@ describe('Localization', () => {
508509

509510
await openCopyToLocaleDrawer(page)
510511
await setToLocale(page, 'Spanish')
511-
await runCopy(page)
512+
await runCopy({ page, toLocale: spanishLocale })
512513
await expect(page.locator('#field-title')).toHaveValue(title)
513514

514515
const regexPattern = /locale=es/
515516
await expect(page).toHaveURL(regexPattern)
516517

517518
await openCopyToLocaleDrawer(page)
518519
await setToLocale(page, 'Hungarian')
519-
await runCopy(page)
520+
await runCopy({ page, toLocale: hungarianLocale })
520521
await expect(page.locator('#field-title')).toHaveValue(title)
521522
})
522523

@@ -797,8 +798,11 @@ async function fillValues(data: Partial<LocalizedPost>) {
797798
}
798799
}
799800

800-
async function runCopy(page) {
801+
async function runCopy({ page, toLocale }: { page: Page; toLocale: string }) {
801802
await page.locator('.copy-locale-data__sub-header button').click()
803+
804+
const regexPattern = new RegExp(`locale=${toLocale}`)
805+
await expect(page).toHaveURL(regexPattern)
802806
}
803807

804808
async function createAndSaveDoc(page, url, values) {

0 commit comments

Comments
 (0)