|
|
|
|
@@ -17,10 +17,10 @@ import {
|
|
|
|
|
relationSpanishTitle,
|
|
|
|
|
relationSpanishTitle2,
|
|
|
|
|
relationshipLocalizedSlug,
|
|
|
|
|
withLocalizedRelSlug,
|
|
|
|
|
withRequiredLocalizedFields,
|
|
|
|
|
spanishLocale,
|
|
|
|
|
spanishTitle,
|
|
|
|
|
withLocalizedRelSlug,
|
|
|
|
|
withRequiredLocalizedFields,
|
|
|
|
|
} from './shared'
|
|
|
|
|
|
|
|
|
|
const collection = localizedPostsSlug
|
|
|
|
|
@@ -36,6 +36,7 @@ describe('Localization', () => {
|
|
|
|
|
;({ serverURL } = await initPayloadTest({ __dirname, init: { local: false } }))
|
|
|
|
|
config = await configPromise
|
|
|
|
|
|
|
|
|
|
// @ts-expect-error Force typing
|
|
|
|
|
post1 = await payload.create({
|
|
|
|
|
collection,
|
|
|
|
|
data: {
|
|
|
|
|
@@ -43,6 +44,7 @@ describe('Localization', () => {
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// @ts-expect-error Force typing
|
|
|
|
|
postWithLocalizedData = await payload.create({
|
|
|
|
|
collection,
|
|
|
|
|
data: {
|
|
|
|
|
@@ -89,7 +91,7 @@ describe('Localization', () => {
|
|
|
|
|
|
|
|
|
|
expect(updated.title).toEqual(spanishTitle)
|
|
|
|
|
|
|
|
|
|
const localized = await payload.findByID({
|
|
|
|
|
const localized: any = await payload.findByID({
|
|
|
|
|
collection,
|
|
|
|
|
id: post1.id,
|
|
|
|
|
locale: 'all',
|
|
|
|
|
@@ -111,7 +113,7 @@ describe('Localization', () => {
|
|
|
|
|
|
|
|
|
|
expect(updated.title).toEqual(englishTitle)
|
|
|
|
|
|
|
|
|
|
const localizedFallback = await payload.findByID({
|
|
|
|
|
const localizedFallback: any = await payload.findByID({
|
|
|
|
|
collection,
|
|
|
|
|
id: post1.id,
|
|
|
|
|
locale: 'all',
|
|
|
|
|
@@ -131,6 +133,7 @@ describe('Localization', () => {
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// @ts-expect-error Force typing
|
|
|
|
|
localizedPost = await payload.update({
|
|
|
|
|
collection,
|
|
|
|
|
id,
|
|
|
|
|
@@ -171,7 +174,7 @@ describe('Localization', () => {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('all locales', async () => {
|
|
|
|
|
const localized = await payload.findByID({
|
|
|
|
|
const localized: any = await payload.findByID({
|
|
|
|
|
collection,
|
|
|
|
|
locale: 'all',
|
|
|
|
|
id: localizedPost.id,
|
|
|
|
|
@@ -191,8 +194,8 @@ describe('Localization', () => {
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(result.docs.map(({ id }) => id)).toContain(localizedPost.id);
|
|
|
|
|
});
|
|
|
|
|
expect(result.docs.map(({ id }) => id)).toContain(localizedPost.id)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('by localized field value - alternate locale', async () => {
|
|
|
|
|
const result = await payload.find({
|
|
|
|
|
@@ -205,8 +208,8 @@ describe('Localization', () => {
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(result.docs.map(({ id }) => id)).toContain(localizedPost.id);
|
|
|
|
|
});
|
|
|
|
|
expect(result.docs.map(({ id }) => id)).toContain(localizedPost.id)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('by localized field value - opposite locale???', async () => {
|
|
|
|
|
const result = await payload.find({
|
|
|
|
|
@@ -219,10 +222,10 @@ describe('Localization', () => {
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(result.docs.map(({ id }) => id)).toContain(localizedPost.id);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
expect(result.docs.map(({ id }) => id)).toContain(localizedPost.id)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('Localized Relationship', () => {
|
|
|
|
|
let localizedRelation: LocalizedPost
|
|
|
|
|
@@ -243,6 +246,7 @@ describe('Localization', () => {
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// @ts-expect-error Force typing
|
|
|
|
|
withRelationship = await payload.create({
|
|
|
|
|
collection: withLocalizedRelSlug,
|
|
|
|
|
data: {
|
|
|
|
|
@@ -304,15 +308,16 @@ describe('Localization', () => {
|
|
|
|
|
|
|
|
|
|
it('populates relationships with all locales', async () => {
|
|
|
|
|
// the relationship fields themselves are localized on this collection
|
|
|
|
|
const result = await payload.find({
|
|
|
|
|
const result: any = await payload.find({
|
|
|
|
|
collection: relationshipLocalizedSlug,
|
|
|
|
|
locale: 'all',
|
|
|
|
|
depth: 1,
|
|
|
|
|
})
|
|
|
|
|
expect((result.docs[0].relationship as any).en.id).toBeDefined()
|
|
|
|
|
expect((result.docs[0].relationshipHasMany as any).en[0].id).toBeDefined()
|
|
|
|
|
expect((result.docs[0].relationMultiRelationTo as any).en.value.id).toBeDefined()
|
|
|
|
|
expect((result.docs[0].relationMultiRelationToHasMany as any).en[0].value.id).toBeDefined()
|
|
|
|
|
|
|
|
|
|
expect(result.docs[0].relationship.en.id).toBeDefined()
|
|
|
|
|
expect(result.docs[0].relationshipHasMany.en[0].id).toBeDefined()
|
|
|
|
|
expect(result.docs[0].relationMultiRelationTo.en.value.id).toBeDefined()
|
|
|
|
|
expect(result.docs[0].relationMultiRelationToHasMany.en[0].value.id).toBeDefined()
|
|
|
|
|
expect(result.docs[0].arrayField.en[0].nestedRelation.id).toBeDefined()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
@@ -328,7 +333,7 @@ describe('Localization', () => {
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(result.docs.map(({ id }) => id)).toContain(withRelationship.id);
|
|
|
|
|
expect(result.docs.map(({ id }) => id)).toContain(withRelationship.id)
|
|
|
|
|
|
|
|
|
|
// Second relationship
|
|
|
|
|
const result2 = await payload.find({
|
|
|
|
|
@@ -340,8 +345,8 @@ describe('Localization', () => {
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(result2.docs.map(({ id }) => id)).toContain(withRelationship.id);
|
|
|
|
|
});
|
|
|
|
|
expect(result2.docs.map(({ id }) => id)).toContain(withRelationship.id)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('specific locale', async () => {
|
|
|
|
|
const result = await payload.find({
|
|
|
|
|
@@ -395,7 +400,7 @@ describe('Localization', () => {
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(result.docs.map(({ id }) => id)).toContain(withRelationship.id);
|
|
|
|
|
expect(result.docs.map(({ id }) => id)).toContain(withRelationship.id)
|
|
|
|
|
|
|
|
|
|
// First relationship - spanish
|
|
|
|
|
const result2 = await queryRelation({
|
|
|
|
|
@@ -404,7 +409,7 @@ describe('Localization', () => {
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(result2.docs.map(({ id }) => id)).toContain(withRelationship.id);
|
|
|
|
|
expect(result2.docs.map(({ id }) => id)).toContain(withRelationship.id)
|
|
|
|
|
|
|
|
|
|
// Second relationship - english
|
|
|
|
|
const result3 = await queryRelation({
|
|
|
|
|
@@ -413,7 +418,7 @@ describe('Localization', () => {
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(result3.docs.map(({ id }) => id)).toContain(withRelationship.id);
|
|
|
|
|
expect(result3.docs.map(({ id }) => id)).toContain(withRelationship.id)
|
|
|
|
|
|
|
|
|
|
// Second relationship - spanish
|
|
|
|
|
const result4 = await queryRelation({
|
|
|
|
|
@@ -509,7 +514,7 @@ describe('Localization', () => {
|
|
|
|
|
|
|
|
|
|
describe('Localized - arrays with nested localized fields', () => {
|
|
|
|
|
it('should allow moving rows and retain existing row locale data', async () => {
|
|
|
|
|
const globalArray = await payload.findGlobal({
|
|
|
|
|
const globalArray: any = await payload.findGlobal({
|
|
|
|
|
slug: 'global-array',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
@@ -753,7 +758,7 @@ async function createLocalizedPost(data: {
|
|
|
|
|
[spanishLocale]: string
|
|
|
|
|
}
|
|
|
|
|
}): Promise<LocalizedPost> {
|
|
|
|
|
const localizedRelation = await payload.create({
|
|
|
|
|
const localizedRelation: any = await payload.create({
|
|
|
|
|
collection,
|
|
|
|
|
data: {
|
|
|
|
|
title: data.title.en,
|
|
|
|
|
|