chore: uses defaultLocale for local operations locale and fallbackLocale
This commit is contained in:
21
test/localization/collections/Array/index.ts
Normal file
21
test/localization/collections/Array/index.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import type { CollectionConfig } from '../../../../src/collections/config/types';
|
||||
|
||||
export const arrayCollectionSlug = 'array-fields';
|
||||
|
||||
export const ArrayCollection: CollectionConfig = {
|
||||
slug: arrayCollectionSlug,
|
||||
fields: [
|
||||
{
|
||||
name: 'items',
|
||||
type: 'array',
|
||||
localized: true,
|
||||
fields: [
|
||||
{
|
||||
name: 'text',
|
||||
type: 'text',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
import { buildConfig } from '../buildConfig';
|
||||
import { devUser } from '../credentials';
|
||||
import { GlobalArray } from './Array';
|
||||
import { ArrayCollection } from './collections/Array';
|
||||
import { LocalizedPost, RelationshipLocalized } from './payload-types';
|
||||
import {
|
||||
defaultLocale,
|
||||
@@ -36,6 +36,7 @@ export default buildConfig({
|
||||
localization: {
|
||||
locales: [defaultLocale, spanishLocale],
|
||||
defaultLocale,
|
||||
fallback: true,
|
||||
},
|
||||
collections: [
|
||||
{
|
||||
@@ -65,27 +66,7 @@ export default buildConfig({
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
slug: 'arrays',
|
||||
fields: [
|
||||
{
|
||||
type: 'text',
|
||||
name: 'requiredText',
|
||||
localized: true,
|
||||
},
|
||||
{
|
||||
type: 'array',
|
||||
name: 'arrayFields',
|
||||
localized: true,
|
||||
fields: [
|
||||
{
|
||||
name: 'text',
|
||||
type: 'text',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
ArrayCollection,
|
||||
{
|
||||
slug: withRequiredLocalizedFields,
|
||||
fields: [
|
||||
|
||||
@@ -22,8 +22,9 @@ import {
|
||||
spanishTitle,
|
||||
} from './shared';
|
||||
import type { Where } from '../../src/types';
|
||||
import { arrayCollectionSlug } from './collections/Array';
|
||||
|
||||
const collection = config.collections[1]?.slug;
|
||||
const collection = slug;
|
||||
|
||||
let serverURL;
|
||||
|
||||
@@ -199,6 +200,7 @@ describe('Localization', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Localized Relationship', () => {
|
||||
let localizedRelation: LocalizedPost;
|
||||
let localizedRelation2: LocalizedPost;
|
||||
@@ -650,6 +652,73 @@ describe('Localization', () => {
|
||||
expect(result.title[spanishLocale]).toStrictEqual(spanishTitle);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Localized - Arrays', () => {
|
||||
let docID;
|
||||
|
||||
beforeAll(async () => {
|
||||
const englishDoc = await payload.create({
|
||||
collection: arrayCollectionSlug,
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
text: englishTitle,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
docID = englishDoc.id;
|
||||
});
|
||||
|
||||
it('should use default locale as fallback', async () => {
|
||||
const spanishDoc = await payload.findByID({
|
||||
locale: spanishLocale,
|
||||
collection: arrayCollectionSlug,
|
||||
id: docID,
|
||||
});
|
||||
|
||||
expect(spanishDoc.items[0].text).toStrictEqual(englishTitle);
|
||||
});
|
||||
|
||||
it('should use empty array as value', async () => {
|
||||
const updatedSpanishDoc = await payload.update({
|
||||
collection: arrayCollectionSlug,
|
||||
locale: spanishLocale,
|
||||
id: docID,
|
||||
data: {
|
||||
items: [],
|
||||
},
|
||||
});
|
||||
|
||||
expect(updatedSpanishDoc.items).toStrictEqual([]);
|
||||
});
|
||||
|
||||
it('should use fallback value if setting null', async () => {
|
||||
await payload.update({
|
||||
collection: arrayCollectionSlug,
|
||||
locale: spanishLocale,
|
||||
id: docID,
|
||||
data: {
|
||||
items: [],
|
||||
},
|
||||
});
|
||||
|
||||
const updatedSpanishDoc = await payload.update({
|
||||
collection: arrayCollectionSlug,
|
||||
locale: spanishLocale,
|
||||
id: docID,
|
||||
data: {
|
||||
items: null,
|
||||
},
|
||||
});
|
||||
|
||||
// should return the value of the fallback locale
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
expect(updatedSpanishDoc.items[0].text).toStrictEqual(englishTitle);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
async function createLocalizedPost(data: {
|
||||
|
||||
Reference in New Issue
Block a user