/
githubmirror
/
strapi
Обзор
Документация
Войти
/
githubmirror
/
strapi
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/plugins/i18n/admin/src/utils/tests/schemas.test.ts
150 строк
4 KB
Alexandre Bodin
feat: ctb lifting
22 апр 2025, 16:20
22 апр 2025, 16:20
0ffa0c9
Код
Авторство
О чём код?
import { mutateCTBContentTypeSchema } from '../schemas'; describe('schemas ', () => { describe('mutateCTBContentTypeSchema', () => { it('should forward the data the pluginOptions.i18n.localized key does not exist in the content type', () => { const data = { pluginOptions: { test: true } }; // @ts-expect-error – Test purposes expect(mutateCTBContentTypeSchema(data, null)).toEqual(data); }); it('should remove the pluginOptions.i18n key from the content type schema', () => { const ctSchema = { pluginOptions: { pluginA: { foo: 'bar' }, i18n: { localized: false }, pluginB: { foo: 'bar' }, }, kind: 'test', attributes: [ { name: 'one', type: 'string', pluginOptions: { i18n: { localized: true }, }, required: true, }, { name: 'two', type: 'number', pluginOptions: { pluginA: { test: true }, i18n: { localized: true }, }, }, ], }; const expected = { pluginOptions: { pluginA: { foo: 'bar' }, pluginB: { foo: 'bar' }, }, kind: 'test', attributes: [ { name: 'one', type: 'string', pluginOptions: {}, required: true, }, { name: 'two', type: 'number', pluginOptions: { pluginA: { test: true }, }, }, ], }; // @ts-expect-error – Test purposes expect(mutateCTBContentTypeSchema(ctSchema, {})).toEqual(expected); }); it('should return the data if the initial schema already has i18n enabled', () => { const ctSchema = { pluginOptions: { pluginA: { foo: 'bar' }, i18n: { localized: true }, pluginB: { foo: 'bar' }, }, kind: 'test', attributes: [ { name: 'one', type: 'string', pluginOptions: { i18n: { localized: true }, }, required: true, }, { name: 'two', type: 'number', pluginOptions: { pluginA: { test: true }, i18n: { localized: true }, }, }, ], }; expect( // @ts-expect-error – Test purposes mutateCTBContentTypeSchema(ctSchema, { schema: { pluginOptions: { pluginA: { foo: 'bar' }, i18n: { localized: true }, pluginB: { foo: 'bar' }, }, }, }) ).toEqual(ctSchema); }); it('should set the pluginOptions.i18n.localized to true an all attributes', () => { const nextSchema = { pluginOptions: { pluginA: { ok: true }, i18n: { localized: true } }, attributes: [ { name: 'cover', type: 'media', pluginOptions: { pluginA: { ok: true } } }, { name: 'name', type: 'text', pluginOptions: { pluginA: { ok: true }, i18n: { localized: false } }, }, { name: 'price', type: 'text', }, ], }; const expected = { pluginOptions: { pluginA: { ok: true }, i18n: { localized: true } }, attributes: [ { name: 'cover', type: 'media', pluginOptions: { pluginA: { ok: true }, i18n: { localized: true } }, }, { name: 'name', type: 'text', pluginOptions: { pluginA: { ok: true }, i18n: { localized: true } }, }, { name: 'price', type: 'text', pluginOptions: { i18n: { localized: true } }, }, ], }; // @ts-expect-error – Test purposes expect(mutateCTBContentTypeSchema(nextSchema, {})).toEqual(expected); }); }); });