fix: localization e2e (#5555)

* fix: issue with missing locale when duplication localized collections

* chore: fix localization tests
This commit is contained in:
Paul
2024-03-29 17:45:26 -03:00
committed by GitHub
parent 2bc1468fa2
commit 0aeba954d4
4 changed files with 37 additions and 16 deletions

View File

@@ -225,7 +225,7 @@ jobs:
# - fields
- fields/lexical
- live-preview
# - localization
- localization
# - plugin-nested-docs
# - plugin-seo
# - refresh-permissions

View File

@@ -239,7 +239,7 @@ export const duplicateOperation = async <TSlug extends keyof GeneratedTypes['col
const versionDoc = await payload.db.create({
collection: collectionConfig.slug,
data: result,
data: docWithLocales,
req,
})

View File

@@ -117,7 +117,7 @@ export async function openDocControls(page: Page): Promise<void> {
await expect(page.locator('.doc-controls__popup >> .popup__content')).toBeVisible()
}
export async function changeLocale(page: Page, newLocale: string) {
export async function changeLocale(page: Page, newLocale: string, skipURLCheck: boolean = false) {
await page.locator('.localizer >> button').first().click()
await page
.locator(`.localizer`)
@@ -126,9 +126,14 @@ export async function changeLocale(page: Page, newLocale: string) {
})
.first()
.click()
const regexPattern = new RegExp(`locale=${newLocale}`)
await expect(page).toHaveURL(regexPattern)
if (skipURLCheck) {
await wait(500)
} else {
await expect(page).toHaveURL(regexPattern)
}
}
export function exactText(text: string) {

View File

@@ -16,6 +16,7 @@ import {
} from '../helpers.js'
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
import { initPayloadE2E } from '../helpers/initPayloadE2E.js'
import { POLL_TOPASS_TIMEOUT } from '../playwright.config.js'
import config from './config.js'
import {
englishTitle,
@@ -76,12 +77,17 @@ describe('Localization', () => {
await changeLocale(page, 'es')
// Localized field should not be populated
await expect(page.locator('#field-title')).toBeEmpty()
await expect
.poll(() => page.locator('#field-title').inputValue(), {
timeout: 45000,
})
.not.toBe(title)
await expect(page.locator('#field-description')).toHaveValue(description)
await fillValues({ description, title: spanishTitle })
await saveDocAndAssert(page)
await changeLocale(page, defaultLocale)
await changeLocale(page, defaultLocale, true)
// Expect english title
await expect(page.locator('#field-title')).toHaveValue(title)
@@ -100,7 +106,7 @@ describe('Localization', () => {
await saveDocAndAssert(page)
// Change back to English
await changeLocale(page, defaultLocale)
await changeLocale(page, defaultLocale, true)
// Localized field should not be populated
await expect(page.locator('#field-title')).toBeEmpty()
@@ -128,7 +134,7 @@ describe('Localization', () => {
await saveDocAndAssert(page)
// Change back to English
await changeLocale(page, defaultLocale)
await changeLocale(page, defaultLocale, true)
// Localized field should not be populated
await expect(page.locator('#field-title')).toBeEmpty()
@@ -138,7 +144,6 @@ describe('Localization', () => {
await fillValues({ description, title })
await saveDocAndAssert(page)
await saveDocAndAssert(page)
await expect(page.locator('#field-title')).toHaveValue(title)
await expect(page.locator('#field-description')).toHaveValue(description)
@@ -169,6 +174,7 @@ describe('Localization', () => {
})
await page.goto(url.edit(id))
await page.waitForURL(`**${url.edit(id)}`)
await openDocControls(page)
// duplicate document
@@ -178,6 +184,7 @@ describe('Localization', () => {
// check fields
await expect(page.locator('#field-title')).toHaveValue(englishTitle)
await changeLocale(page, spanishLocale)
await expect(page.locator('#field-title')).toHaveValue(spanishTitle)
await expect(page.locator('#field-localizedCheckbox')).not.toBeChecked()
@@ -185,39 +192,48 @@ describe('Localization', () => {
test('should duplicate localized checkbox correctly', async () => {
await page.goto(url.create)
await changeLocale(page, defaultLocale)
await page.waitForURL(`**${url.create}`)
//await changeLocale(page, defaultLocale, true)
await fillValues({ description, title: englishTitle })
await page.locator('#field-localizedCheckbox').click()
await page.locator('#action-save').click()
// wait for navigation to update route
await wait(500)
await expect.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT }).not.toContain('create')
const collectionUrl = page.url()
// ensure spanish is not checked
await changeLocale(page, spanishLocale)
await expect(page.locator('#field-localizedCheckbox')).not.toBeChecked()
// duplicate doc
await changeLocale(page, defaultLocale)
await changeLocale(page, defaultLocale, true)
await openDocControls(page)
await page.locator('#action-duplicate').click()
// wait for navigation to update route
await wait(500)
await expect
.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT })
.not.toContain(collectionUrl)
// finally change locale to spanish
await changeLocale(page, spanishLocale)
await expect(page.locator('#field-localizedCheckbox')).not.toBeChecked()
})
test('should duplicate even if missing some localized data', async () => {
// create a localized required doc
await page.goto(urlWithRequiredLocalizedFields.create)
await changeLocale(page, defaultLocale)
await changeLocale(page, defaultLocale, true)
await page.locator('#field-title').fill(englishTitle)
await page.locator('#field-layout .blocks-field__drawer-toggler').click()
await page.locator('button[title="Text"]').click()
await page.fill('#field-layout__0__text', 'test')
await expect(page.locator('#field-layout__0__text')).toHaveValue('test')
await wait(5000)
await saveDocAndAssert(page)
const originalID = await page.locator('.id-label').innerText()