@akemona-org/strapi-plugin-i18n 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +19 -0
- package/admin/src/assets/images/logo.svg +1 -0
- package/admin/src/components/CMEditViewCopyLocale/index.js +183 -0
- package/admin/src/components/CMEditViewCopyLocale/utils/cleanData.js +36 -0
- package/admin/src/components/CMEditViewCopyLocale/utils/generateOptions.js +22 -0
- package/admin/src/components/CMEditViewCopyLocale/utils/index.js +2 -0
- package/admin/src/components/CMEditViewCopyLocale/utils/removePasswordAndRelationsFieldFromData.js +54 -0
- package/admin/src/components/CMEditViewCopyLocale/utils/tests/cleanData.test.js +83 -0
- package/admin/src/components/CMEditViewCopyLocale/utils/tests/data.js +219 -0
- package/admin/src/components/CMEditViewCopyLocale/utils/tests/generateOptions.test.js +79 -0
- package/admin/src/components/CMEditViewCopyLocale/utils/tests/removePasswordAndRelationsFieldFromData.test.js +40 -0
- package/admin/src/components/CMEditViewInjectedComponents/index.js +58 -0
- package/admin/src/components/CMEditViewLocalePicker/Option.js +66 -0
- package/admin/src/components/CMEditViewLocalePicker/Wrapper.js +8 -0
- package/admin/src/components/CMEditViewLocalePicker/index.js +160 -0
- package/admin/src/components/CMEditViewLocalePicker/utils/addStatusColorToLocale.js +24 -0
- package/admin/src/components/CMEditViewLocalePicker/utils/createLocalesOption.js +20 -0
- package/admin/src/components/CMEditViewLocalePicker/utils/index.js +2 -0
- package/admin/src/components/CheckboxConfirmation/Wrapper.js +12 -0
- package/admin/src/components/CheckboxConfirmation/index.js +70 -0
- package/admin/src/components/DeleteModalAdditionalInfos/index.js +25 -0
- package/admin/src/components/LocaleList/index.js +101 -0
- package/admin/src/components/LocaleListCell/LocaleListCell.js +90 -0
- package/admin/src/components/LocaleListCell/tests/LocaleListCell.test.js +128 -0
- package/admin/src/components/LocalePicker/index.js +126 -0
- package/admin/src/components/LocaleRow/index.js +77 -0
- package/admin/src/components/ModalCreate/AdvancedForm.js +45 -0
- package/admin/src/components/ModalCreate/BaseForm.js +103 -0
- package/admin/src/components/ModalCreate/index.js +136 -0
- package/admin/src/components/ModalDelete/index.js +49 -0
- package/admin/src/components/ModalEdit/AdvancedForm.js +51 -0
- package/admin/src/components/ModalEdit/BaseForm.js +91 -0
- package/admin/src/components/ModalEdit/index.js +122 -0
- package/admin/src/components/SettingsModal.js +66 -0
- package/admin/src/components/index.js +2 -0
- package/admin/src/containers/Initializer.js +31 -0
- package/admin/src/containers/SettingsPage/LocaleSettingsPage.js +69 -0
- package/admin/src/containers/SettingsPage/index.js +33 -0
- package/admin/src/containers/SettingsPage/tests/SettingsPage.test.js +744 -0
- package/admin/src/containers/SettingsPage/tests/__snapshots__/SettingsPage.test.js.snap +241 -0
- package/admin/src/hooks/constants.js +6 -0
- package/admin/src/hooks/reducers.js +63 -0
- package/admin/src/hooks/tests/reducers.test.js +203 -0
- package/admin/src/hooks/useAddLocale/index.js +60 -0
- package/admin/src/hooks/useContentTypePermissions/index.js +16 -0
- package/admin/src/hooks/useDefaultLocales/index.js +27 -0
- package/admin/src/hooks/useDeleteLocale/index.js +45 -0
- package/admin/src/hooks/useEditLocale/index.js +46 -0
- package/admin/src/hooks/useHasI18n/index.js +13 -0
- package/admin/src/hooks/useLocales/index.js +35 -0
- package/admin/src/index.js +169 -0
- package/admin/src/middlewares/addCommonFieldsToInitialDataMiddleware.js +83 -0
- package/admin/src/middlewares/addLocaleColumnToListViewMiddleware.js +32 -0
- package/admin/src/middlewares/addLocaleToCollectionTypesMiddleware.js +25 -0
- package/admin/src/middlewares/addLocaleToSingleTypesMiddleware.js +25 -0
- package/admin/src/middlewares/extendCMEditViewLayoutMiddleware.js +159 -0
- package/admin/src/middlewares/extendCTBAttributeInitialDataMiddleware.js +58 -0
- package/admin/src/middlewares/extendCTBInitialDataMiddleware.js +33 -0
- package/admin/src/middlewares/index.js +21 -0
- package/admin/src/middlewares/localePermissionMiddleware.js +39 -0
- package/admin/src/middlewares/tests/addCommonFieldsToInitialDataMiddleware.test.js +97 -0
- package/admin/src/middlewares/tests/addLocaleColumnToListViewMiddleware.test.js +68 -0
- package/admin/src/middlewares/tests/addLocaleToCollectionTypesMiddleware.test.js +200 -0
- package/admin/src/middlewares/tests/addLocaleToSingleTypesMiddleware.test.js +193 -0
- package/admin/src/middlewares/tests/extendCMEditViewLayoutMiddleware.test.js +556 -0
- package/admin/src/middlewares/tests/extendCTBAttrributeInitialDataMiddleware.test.js +124 -0
- package/admin/src/middlewares/tests/extendCTBInitialDataMiddleware.test.js +92 -0
- package/admin/src/middlewares/tests/localePermissionMiddleware.test.js +150 -0
- package/admin/src/middlewares/utils/addLocaleToLinksSearch.js +56 -0
- package/admin/src/middlewares/utils/tests/addLocaleToLinksSearch.test.js +137 -0
- package/admin/src/permissions.js +9 -0
- package/admin/src/pluginId.js +5 -0
- package/admin/src/schemas.js +7 -0
- package/admin/src/selectors/selectCollectionTypesRelatedPermissions.js +4 -0
- package/admin/src/selectors/selectI18nLocales.js +3 -0
- package/admin/src/translations/en.json +60 -0
- package/admin/src/translations/fr.json +9 -0
- package/admin/src/translations/index.js +11 -0
- package/admin/src/translations/zh-Hans.json +60 -0
- package/admin/src/utils/getDefaultLocale.js +60 -0
- package/admin/src/utils/getInitialLocale.js +14 -0
- package/admin/src/utils/getLocaleFromQuery.js +7 -0
- package/admin/src/utils/getTrad.js +5 -0
- package/admin/src/utils/index.js +2 -0
- package/admin/src/utils/localizedFields.js +23 -0
- package/admin/src/utils/mutateCTBContentTypeSchema.js +66 -0
- package/admin/src/utils/tests/getDefaultLocale.test.js +337 -0
- package/admin/src/utils/tests/getInitialLocale.test.js +106 -0
- package/admin/src/utils/tests/mutateCTBContentTypeSchema.test.js +205 -0
- package/config/functions/bootstrap.js +57 -0
- package/config/functions/migrations/__tests__/content-type.test.js +255 -0
- package/config/functions/migrations/__tests__/field.test.js +150 -0
- package/config/functions/migrations/content-type/disable/index.js +34 -0
- package/config/functions/migrations/content-type/disable/migrate-for-bookshelf.js +58 -0
- package/config/functions/migrations/content-type/disable/migrate-for-mongoose.js +39 -0
- package/config/functions/migrations/content-type/enable/index.js +40 -0
- package/config/functions/migrations/content-type/utils/index.js +27 -0
- package/config/functions/migrations/field/__tests__/utils.test.js +53 -0
- package/config/functions/migrations/field/index.js +37 -0
- package/config/functions/migrations/field/migrate-for-bookshelf.js +72 -0
- package/config/functions/migrations/field/migrate-for-mongoose.js +24 -0
- package/config/functions/migrations/field/migrate.js +55 -0
- package/config/functions/migrations/field/utils.js +58 -0
- package/config/functions/register.js +46 -0
- package/config/policies/validateLocaleCreation.js +68 -0
- package/config/routes.json +64 -0
- package/constants/__tests__/index.test.js +27 -0
- package/constants/index.js +36 -0
- package/constants/iso-locales.json +2002 -0
- package/controllers/__tests__/content-types.test.js +113 -0
- package/controllers/__tests__/iso-locales.test.js +26 -0
- package/controllers/__tests__/locales.test.js +308 -0
- package/controllers/content-types.js +64 -0
- package/controllers/iso-locales.js +11 -0
- package/controllers/locales.js +104 -0
- package/domain/locale.js +10 -0
- package/middlewares/i18n/defaults.json +5 -0
- package/middlewares/i18n/index.js +28 -0
- package/models/Locale.settings.json +31 -0
- package/oas.yml +195 -0
- package/package.json +31 -0
- package/services/__tests__/__snapshots__/iso-locales.test.js.snap +2006 -0
- package/services/__tests__/content-types.test.js +545 -0
- package/services/__tests__/core-api.test.js +106 -0
- package/services/__tests__/entity-service-decorator.test.js +280 -0
- package/services/__tests__/iso-locales.test.js +11 -0
- package/services/__tests__/locales.test.js +237 -0
- package/services/__tests__/localizations.test.js +187 -0
- package/services/__tests__/metrics.test.js +90 -0
- package/services/content-types.js +200 -0
- package/services/core-api.js +296 -0
- package/services/entity-service-decorator.js +155 -0
- package/services/iso-locales.js +9 -0
- package/services/locales.js +97 -0
- package/services/localizations.js +65 -0
- package/services/metrics.js +24 -0
- package/services/permissions/actions.js +124 -0
- package/services/permissions/engine.js +63 -0
- package/services/permissions/sections-builder.js +48 -0
- package/services/permissions.js +11 -0
- package/tests/content-manager/list-relation.test.e2e.js +122 -0
- package/tests/graphql.test.e2e.js +120 -0
- package/tests/locales.test.e2e.js +414 -0
- package/utils/index.js +20 -0
- package/validation/content-types.js +30 -0
- package/validation/locales.js +39 -0
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Globe, GlobeCrossed } from '@buffetjs/icons';
|
|
3
|
+
import { getTrad } from '../../utils';
|
|
4
|
+
import extendCMEditViewLayoutMiddleware, {
|
|
5
|
+
enhanceComponentsLayout,
|
|
6
|
+
enhanceEditLayout,
|
|
7
|
+
enhanceRelationLayout,
|
|
8
|
+
} from '../extendCMEditViewLayoutMiddleware';
|
|
9
|
+
|
|
10
|
+
const localizedTrad = getTrad('Field.localized');
|
|
11
|
+
const localizedTradDefaultMessage = 'This value is unique for the selected locale';
|
|
12
|
+
const notLocalizedTrad = getTrad('Field.not-localized');
|
|
13
|
+
const notLocalizedTradDefaultMessage = 'This value is common to all locales';
|
|
14
|
+
|
|
15
|
+
describe('i18n | Middlewares | extendCMEditViewLayoutMiddleware', () => {
|
|
16
|
+
it('should forward the action if the type is undefined', () => {
|
|
17
|
+
const middleware = extendCMEditViewLayoutMiddleware();
|
|
18
|
+
const action = { test: true, type: undefined };
|
|
19
|
+
|
|
20
|
+
const next = jest.fn();
|
|
21
|
+
|
|
22
|
+
middleware()(next)(action);
|
|
23
|
+
|
|
24
|
+
expect(next).toBeCalledWith(action);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should forward if the type is not correct', () => {
|
|
28
|
+
const middleware = extendCMEditViewLayoutMiddleware();
|
|
29
|
+
const action = { test: true, type: 'TEST' };
|
|
30
|
+
|
|
31
|
+
const next = jest.fn();
|
|
32
|
+
|
|
33
|
+
middleware()(next)(action);
|
|
34
|
+
|
|
35
|
+
expect(next).toBeCalledWith(action);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('should forward when the type is ContentManager/EditViewLayoutManager/SET_LAYOUT', () => {
|
|
39
|
+
it('should forward when i18n is not enabled on the content type', () => {
|
|
40
|
+
const layout = {
|
|
41
|
+
components: {},
|
|
42
|
+
contentType: {
|
|
43
|
+
uid: 'test',
|
|
44
|
+
pluginOptions: { i18n: { localized: false } },
|
|
45
|
+
layouts: {
|
|
46
|
+
edit: ['test'],
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
const action = {
|
|
51
|
+
type: 'ContentManager/EditViewLayoutManager/SET_LAYOUT',
|
|
52
|
+
layout,
|
|
53
|
+
};
|
|
54
|
+
const middleware = extendCMEditViewLayoutMiddleware();
|
|
55
|
+
const next = jest.fn();
|
|
56
|
+
|
|
57
|
+
middleware()(next)(action);
|
|
58
|
+
|
|
59
|
+
expect(next).toBeCalledWith(action);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should forward the action when i18n is enabled and the query.locale is not defined', () => {
|
|
63
|
+
const layout = {
|
|
64
|
+
contentType: {
|
|
65
|
+
uid: 'test',
|
|
66
|
+
pluginOptions: { i18n: { localized: true } },
|
|
67
|
+
layouts: {
|
|
68
|
+
edit: [],
|
|
69
|
+
editRelations: [
|
|
70
|
+
{
|
|
71
|
+
fieldSchema: {},
|
|
72
|
+
metadatas: {},
|
|
73
|
+
name: 'addresses',
|
|
74
|
+
queryInfos: {},
|
|
75
|
+
size: 6,
|
|
76
|
+
targetModelPluginOptions: {},
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const action = {
|
|
84
|
+
type: 'ContentManager/EditViewLayoutManager/SET_LAYOUT',
|
|
85
|
+
layout,
|
|
86
|
+
};
|
|
87
|
+
const middleware = extendCMEditViewLayoutMiddleware();
|
|
88
|
+
|
|
89
|
+
const next = jest.fn();
|
|
90
|
+
middleware()(next)(action);
|
|
91
|
+
|
|
92
|
+
expect(next).toBeCalledWith(action);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should modify the editRelations layout when i18n is enabled and the query.locale is defined', () => {
|
|
96
|
+
const layout = {
|
|
97
|
+
contentType: {
|
|
98
|
+
uid: 'test',
|
|
99
|
+
pluginOptions: { i18n: { localized: true } },
|
|
100
|
+
layouts: {
|
|
101
|
+
edit: [],
|
|
102
|
+
editRelations: [
|
|
103
|
+
{
|
|
104
|
+
fieldSchema: {},
|
|
105
|
+
metadatas: {},
|
|
106
|
+
name: 'addresses',
|
|
107
|
+
queryInfos: {
|
|
108
|
+
test: true,
|
|
109
|
+
defaultParams: {},
|
|
110
|
+
paramsToKeep: ['plugins.i18n.locale'],
|
|
111
|
+
},
|
|
112
|
+
size: 6,
|
|
113
|
+
targetModelPluginOptions: {},
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
components: {},
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const action = {
|
|
122
|
+
type: 'ContentManager/EditViewLayoutManager/SET_LAYOUT',
|
|
123
|
+
layout,
|
|
124
|
+
query: { plugins: { i18n: { locale: 'en' } } },
|
|
125
|
+
};
|
|
126
|
+
const middleware = extendCMEditViewLayoutMiddleware();
|
|
127
|
+
|
|
128
|
+
const next = jest.fn();
|
|
129
|
+
middleware()(next)(action);
|
|
130
|
+
|
|
131
|
+
expect(next).toBeCalledWith({
|
|
132
|
+
...action,
|
|
133
|
+
layout: {
|
|
134
|
+
...layout,
|
|
135
|
+
contentType: {
|
|
136
|
+
...layout.contentType,
|
|
137
|
+
layouts: {
|
|
138
|
+
edit: [],
|
|
139
|
+
editRelations: [
|
|
140
|
+
{
|
|
141
|
+
fieldSchema: {},
|
|
142
|
+
metadatas: {},
|
|
143
|
+
name: 'addresses',
|
|
144
|
+
queryInfos: {
|
|
145
|
+
test: true,
|
|
146
|
+
defaultParams: {},
|
|
147
|
+
paramsToKeep: ['plugins.i18n.locale'],
|
|
148
|
+
},
|
|
149
|
+
size: 6,
|
|
150
|
+
targetModelPluginOptions: {},
|
|
151
|
+
labelIcon: {
|
|
152
|
+
title: { id: localizedTrad, defaultMessage: localizedTradDefaultMessage },
|
|
153
|
+
icon: <Globe />,
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe('enhanceComponentsLayout', () => {
|
|
165
|
+
it('should not enhance the field when the type is not relation', () => {
|
|
166
|
+
const components = {
|
|
167
|
+
test: {
|
|
168
|
+
test: true,
|
|
169
|
+
layouts: {
|
|
170
|
+
edit: [
|
|
171
|
+
[
|
|
172
|
+
{
|
|
173
|
+
name: 'title',
|
|
174
|
+
fieldSchema: { type: 'string' },
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
name: 'content',
|
|
178
|
+
fieldSchema: { type: 'string' },
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
],
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
const expected = {
|
|
186
|
+
test: {
|
|
187
|
+
test: true,
|
|
188
|
+
layouts: {
|
|
189
|
+
edit: [
|
|
190
|
+
[
|
|
191
|
+
{
|
|
192
|
+
name: 'title',
|
|
193
|
+
fieldSchema: { type: 'string' },
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
name: 'content',
|
|
197
|
+
fieldSchema: { type: 'string' },
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
expect(enhanceComponentsLayout(components)).toEqual(expected);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('should not enhance the field when the type is relation and the targetModel.pluginOptions.i18.localized is disabled', () => {
|
|
209
|
+
const components = {
|
|
210
|
+
test: {
|
|
211
|
+
test: true,
|
|
212
|
+
layouts: {
|
|
213
|
+
edit: [
|
|
214
|
+
[
|
|
215
|
+
{
|
|
216
|
+
name: 'title',
|
|
217
|
+
fieldSchema: { type: 'relation' },
|
|
218
|
+
targetModelPluginOptions: { i18n: { localized: false } },
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
name: 'content',
|
|
222
|
+
fieldSchema: { type: 'string' },
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
],
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
const expected = {
|
|
230
|
+
test: {
|
|
231
|
+
test: true,
|
|
232
|
+
layouts: {
|
|
233
|
+
edit: [
|
|
234
|
+
[
|
|
235
|
+
{
|
|
236
|
+
name: 'title',
|
|
237
|
+
fieldSchema: { type: 'relation' },
|
|
238
|
+
targetModelPluginOptions: { i18n: { localized: false } },
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: 'content',
|
|
242
|
+
fieldSchema: { type: 'string' },
|
|
243
|
+
},
|
|
244
|
+
],
|
|
245
|
+
],
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
expect(enhanceComponentsLayout(components)).toEqual(expected);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('should modify the relation field when the targetModelPluginOptions.i18n.localized is enabled', () => {
|
|
254
|
+
const components = {
|
|
255
|
+
foo: {
|
|
256
|
+
test: true,
|
|
257
|
+
layouts: {
|
|
258
|
+
edit: [
|
|
259
|
+
[
|
|
260
|
+
{
|
|
261
|
+
name: 'title',
|
|
262
|
+
fieldSchema: { type: 'relation' },
|
|
263
|
+
targetModelPluginOptions: { i18n: { localized: true } },
|
|
264
|
+
queryInfos: {
|
|
265
|
+
defaultParams: { test: true },
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
name: 'content',
|
|
270
|
+
fieldSchema: { type: 'string' },
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
],
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
bar: {
|
|
277
|
+
test: true,
|
|
278
|
+
layouts: {
|
|
279
|
+
edit: [
|
|
280
|
+
[
|
|
281
|
+
{
|
|
282
|
+
name: 'title',
|
|
283
|
+
fieldSchema: { type: 'relation' },
|
|
284
|
+
targetModelPluginOptions: { i18n: { localized: true } },
|
|
285
|
+
queryInfos: {
|
|
286
|
+
defaultParams: { test: true },
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
name: 'content',
|
|
291
|
+
fieldSchema: { type: 'string' },
|
|
292
|
+
},
|
|
293
|
+
],
|
|
294
|
+
],
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
};
|
|
298
|
+
const expected = {
|
|
299
|
+
foo: {
|
|
300
|
+
test: true,
|
|
301
|
+
layouts: {
|
|
302
|
+
edit: [
|
|
303
|
+
[
|
|
304
|
+
{
|
|
305
|
+
name: 'title',
|
|
306
|
+
fieldSchema: { type: 'relation' },
|
|
307
|
+
targetModelPluginOptions: { i18n: { localized: true } },
|
|
308
|
+
queryInfos: {
|
|
309
|
+
defaultParams: { test: true, _locale: 'en' },
|
|
310
|
+
paramsToKeep: ['plugins.i18n.locale'],
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
name: 'content',
|
|
315
|
+
fieldSchema: { type: 'string' },
|
|
316
|
+
},
|
|
317
|
+
],
|
|
318
|
+
],
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
bar: {
|
|
322
|
+
test: true,
|
|
323
|
+
layouts: {
|
|
324
|
+
edit: [
|
|
325
|
+
[
|
|
326
|
+
{
|
|
327
|
+
name: 'title',
|
|
328
|
+
fieldSchema: { type: 'relation' },
|
|
329
|
+
targetModelPluginOptions: { i18n: { localized: true } },
|
|
330
|
+
queryInfos: {
|
|
331
|
+
defaultParams: { test: true, _locale: 'en' },
|
|
332
|
+
paramsToKeep: ['plugins.i18n.locale'],
|
|
333
|
+
},
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
name: 'content',
|
|
337
|
+
fieldSchema: { type: 'string' },
|
|
338
|
+
},
|
|
339
|
+
],
|
|
340
|
+
],
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
expect(enhanceComponentsLayout(components, 'en')).toEqual(expected);
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
describe('enhanceEditLayout', () => {
|
|
350
|
+
it('should add the label icon to all fields with the localized translation when i18n is enabled', () => {
|
|
351
|
+
const edit = [
|
|
352
|
+
[
|
|
353
|
+
{
|
|
354
|
+
name: 'name',
|
|
355
|
+
size: 6,
|
|
356
|
+
fieldSchema: {
|
|
357
|
+
pluginOptions: { i18n: { localized: true } },
|
|
358
|
+
type: 'string',
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
],
|
|
362
|
+
[
|
|
363
|
+
{
|
|
364
|
+
name: 'test',
|
|
365
|
+
size: 6,
|
|
366
|
+
fieldSchema: {
|
|
367
|
+
pluginOptions: { i18n: { localized: true } },
|
|
368
|
+
type: 'string',
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
name: 'slug',
|
|
373
|
+
size: 6,
|
|
374
|
+
fieldSchema: {
|
|
375
|
+
type: 'uid',
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
],
|
|
379
|
+
];
|
|
380
|
+
const expected = [
|
|
381
|
+
[
|
|
382
|
+
{
|
|
383
|
+
name: 'name',
|
|
384
|
+
size: 6,
|
|
385
|
+
fieldSchema: {
|
|
386
|
+
pluginOptions: { i18n: { localized: true } },
|
|
387
|
+
type: 'string',
|
|
388
|
+
},
|
|
389
|
+
labelIcon: {
|
|
390
|
+
title: { id: localizedTrad, defaultMessage: localizedTradDefaultMessage },
|
|
391
|
+
icon: <Globe />,
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
],
|
|
395
|
+
[
|
|
396
|
+
{
|
|
397
|
+
name: 'test',
|
|
398
|
+
size: 6,
|
|
399
|
+
fieldSchema: {
|
|
400
|
+
pluginOptions: { i18n: { localized: true } },
|
|
401
|
+
type: 'string',
|
|
402
|
+
},
|
|
403
|
+
labelIcon: {
|
|
404
|
+
title: { id: localizedTrad, defaultMessage: localizedTradDefaultMessage },
|
|
405
|
+
icon: <Globe />,
|
|
406
|
+
},
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
name: 'slug',
|
|
410
|
+
size: 6,
|
|
411
|
+
fieldSchema: {
|
|
412
|
+
type: 'uid',
|
|
413
|
+
},
|
|
414
|
+
labelIcon: {
|
|
415
|
+
title: { id: localizedTrad, defaultMessage: localizedTradDefaultMessage },
|
|
416
|
+
icon: <Globe />,
|
|
417
|
+
},
|
|
418
|
+
},
|
|
419
|
+
],
|
|
420
|
+
];
|
|
421
|
+
|
|
422
|
+
expect(enhanceEditLayout(edit)).toEqual(expected);
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it('should add the label icon to all fields with the not localized translation when i18n is disabled', () => {
|
|
426
|
+
const edit = [
|
|
427
|
+
[
|
|
428
|
+
{
|
|
429
|
+
name: 'name',
|
|
430
|
+
size: 6,
|
|
431
|
+
fieldSchema: {
|
|
432
|
+
pluginOptions: { i18n: { localized: true } },
|
|
433
|
+
type: 'string',
|
|
434
|
+
},
|
|
435
|
+
},
|
|
436
|
+
],
|
|
437
|
+
[
|
|
438
|
+
{
|
|
439
|
+
name: 'test',
|
|
440
|
+
size: 6,
|
|
441
|
+
fieldSchema: {
|
|
442
|
+
pluginOptions: { i18n: { localized: false } },
|
|
443
|
+
type: 'string',
|
|
444
|
+
},
|
|
445
|
+
},
|
|
446
|
+
],
|
|
447
|
+
];
|
|
448
|
+
const expected = [
|
|
449
|
+
[
|
|
450
|
+
{
|
|
451
|
+
name: 'name',
|
|
452
|
+
size: 6,
|
|
453
|
+
fieldSchema: {
|
|
454
|
+
pluginOptions: { i18n: { localized: true } },
|
|
455
|
+
type: 'string',
|
|
456
|
+
},
|
|
457
|
+
labelIcon: {
|
|
458
|
+
title: { id: localizedTrad, defaultMessage: localizedTradDefaultMessage },
|
|
459
|
+
icon: <Globe />,
|
|
460
|
+
},
|
|
461
|
+
},
|
|
462
|
+
],
|
|
463
|
+
[
|
|
464
|
+
{
|
|
465
|
+
name: 'test',
|
|
466
|
+
size: 6,
|
|
467
|
+
fieldSchema: {
|
|
468
|
+
pluginOptions: { i18n: { localized: false } },
|
|
469
|
+
type: 'string',
|
|
470
|
+
},
|
|
471
|
+
labelIcon: {
|
|
472
|
+
title: { id: notLocalizedTrad, defaultMessage: notLocalizedTradDefaultMessage },
|
|
473
|
+
icon: <GlobeCrossed />,
|
|
474
|
+
},
|
|
475
|
+
},
|
|
476
|
+
],
|
|
477
|
+
];
|
|
478
|
+
|
|
479
|
+
expect(enhanceEditLayout(edit)).toEqual(expected);
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
describe('enhanceRelationLayout', () => {
|
|
484
|
+
it('should add the labelIcon key to all relations fields', () => {
|
|
485
|
+
const editRelations = [
|
|
486
|
+
{
|
|
487
|
+
fieldSchema: {},
|
|
488
|
+
metadatas: {},
|
|
489
|
+
name: 'addresses',
|
|
490
|
+
queryInfos: {},
|
|
491
|
+
size: 6,
|
|
492
|
+
targetModelPluginOptions: {},
|
|
493
|
+
},
|
|
494
|
+
];
|
|
495
|
+
const expected = [
|
|
496
|
+
{
|
|
497
|
+
fieldSchema: {},
|
|
498
|
+
metadatas: {},
|
|
499
|
+
name: 'addresses',
|
|
500
|
+
queryInfos: {},
|
|
501
|
+
size: 6,
|
|
502
|
+
targetModelPluginOptions: {},
|
|
503
|
+
labelIcon: {
|
|
504
|
+
title: { id: localizedTrad, defaultMessage: localizedTradDefaultMessage },
|
|
505
|
+
icon: <Globe />,
|
|
506
|
+
},
|
|
507
|
+
},
|
|
508
|
+
];
|
|
509
|
+
|
|
510
|
+
expect(enhanceRelationLayout(editRelations, 'en')).toEqual(expected);
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
it('should add the locale to the queryInfos.defaultParams when the targetModelPluginOptions.i18n.localized is enabled', () => {
|
|
514
|
+
const editRelations = [
|
|
515
|
+
{
|
|
516
|
+
fieldSchema: {},
|
|
517
|
+
metadatas: {},
|
|
518
|
+
name: 'addresses',
|
|
519
|
+
queryInfos: {
|
|
520
|
+
defaultParams: {
|
|
521
|
+
test: true,
|
|
522
|
+
},
|
|
523
|
+
},
|
|
524
|
+
size: 6,
|
|
525
|
+
targetModelPluginOptions: {
|
|
526
|
+
i18n: { localized: true },
|
|
527
|
+
},
|
|
528
|
+
},
|
|
529
|
+
];
|
|
530
|
+
const expected = [
|
|
531
|
+
{
|
|
532
|
+
fieldSchema: {},
|
|
533
|
+
metadatas: {},
|
|
534
|
+
name: 'addresses',
|
|
535
|
+
queryInfos: {
|
|
536
|
+
defaultParams: {
|
|
537
|
+
test: true,
|
|
538
|
+
_locale: 'en',
|
|
539
|
+
},
|
|
540
|
+
paramsToKeep: ['plugins.i18n.locale'],
|
|
541
|
+
},
|
|
542
|
+
size: 6,
|
|
543
|
+
targetModelPluginOptions: {
|
|
544
|
+
i18n: { localized: true },
|
|
545
|
+
},
|
|
546
|
+
labelIcon: {
|
|
547
|
+
title: { id: localizedTrad, defaultMessage: localizedTradDefaultMessage },
|
|
548
|
+
icon: <Globe />,
|
|
549
|
+
},
|
|
550
|
+
},
|
|
551
|
+
];
|
|
552
|
+
|
|
553
|
+
expect(enhanceRelationLayout(editRelations, 'en')).toEqual(expected);
|
|
554
|
+
});
|
|
555
|
+
});
|
|
556
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import extendCTBAttributeInitialDataMiddleware from '../extendCTBAttributeInitialDataMiddleware';
|
|
2
|
+
|
|
3
|
+
describe('i18n | middlewares | extendCTBAttributeInitialDataMiddleware', () => {
|
|
4
|
+
it('should forward the action if the type is undefined', () => {
|
|
5
|
+
const middleware = extendCTBAttributeInitialDataMiddleware();
|
|
6
|
+
const action = { test: true, type: undefined };
|
|
7
|
+
const getState = jest.fn();
|
|
8
|
+
|
|
9
|
+
const next = jest.fn();
|
|
10
|
+
|
|
11
|
+
middleware({ getState })(next)(action);
|
|
12
|
+
|
|
13
|
+
expect(next).toBeCalledWith(action);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should forward if the type is not correct', () => {
|
|
17
|
+
const middleware = extendCTBAttributeInitialDataMiddleware();
|
|
18
|
+
const action = { test: true, type: 'TEST' };
|
|
19
|
+
const getState = jest.fn();
|
|
20
|
+
|
|
21
|
+
const next = jest.fn();
|
|
22
|
+
|
|
23
|
+
middleware({ getState })(next)(action);
|
|
24
|
+
|
|
25
|
+
expect(next).toBeCalledWith(action);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('should forward when the type is ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA', () => {
|
|
29
|
+
it('should forward if the forTarget is not contentType', () => {
|
|
30
|
+
const middleware = extendCTBAttributeInitialDataMiddleware();
|
|
31
|
+
const action = {
|
|
32
|
+
forTarget: 'contentType',
|
|
33
|
+
type: 'ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA',
|
|
34
|
+
};
|
|
35
|
+
const getState = jest.fn();
|
|
36
|
+
|
|
37
|
+
const next = jest.fn();
|
|
38
|
+
|
|
39
|
+
middleware({ getState })(next)(action);
|
|
40
|
+
|
|
41
|
+
expect(next).toBeCalledWith(action);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should forward if the i18n is not activated is not contentType', () => {
|
|
45
|
+
const middleware = extendCTBAttributeInitialDataMiddleware();
|
|
46
|
+
const action = {
|
|
47
|
+
forTarget: 'contentType',
|
|
48
|
+
attributeType: 'text',
|
|
49
|
+
type: 'ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA',
|
|
50
|
+
};
|
|
51
|
+
const getState = jest.fn(() => ({
|
|
52
|
+
getIn: jest.fn(() => false),
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
const next = jest.fn();
|
|
56
|
+
|
|
57
|
+
middleware({ getState })(next)(action);
|
|
58
|
+
|
|
59
|
+
expect(next).toBeCalledWith(action);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should forward if the ctb is not mounted', () => {
|
|
63
|
+
const middleware = extendCTBAttributeInitialDataMiddleware();
|
|
64
|
+
const action = {
|
|
65
|
+
forTarget: 'contentType',
|
|
66
|
+
attributeType: 'text',
|
|
67
|
+
type: 'ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA',
|
|
68
|
+
};
|
|
69
|
+
const getState = jest.fn(() => ({
|
|
70
|
+
getIn: undefined,
|
|
71
|
+
}));
|
|
72
|
+
|
|
73
|
+
const next = jest.fn();
|
|
74
|
+
|
|
75
|
+
middleware({ getState })(next)(action);
|
|
76
|
+
|
|
77
|
+
expect(next).toBeCalledWith(action);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should add the action.pluginOptions if the type is correct and i18n is activated', () => {
|
|
82
|
+
const middleware = extendCTBAttributeInitialDataMiddleware();
|
|
83
|
+
const action = {
|
|
84
|
+
forTarget: 'contentType',
|
|
85
|
+
attributeType: 'text',
|
|
86
|
+
type: 'ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA',
|
|
87
|
+
};
|
|
88
|
+
const getState = jest.fn(() => ({
|
|
89
|
+
// i18n is activated
|
|
90
|
+
getIn: jest.fn(() => true),
|
|
91
|
+
}));
|
|
92
|
+
|
|
93
|
+
const next = jest.fn();
|
|
94
|
+
|
|
95
|
+
middleware({ getState })(next)(action);
|
|
96
|
+
|
|
97
|
+
expect(next).toBeCalledWith({
|
|
98
|
+
...action,
|
|
99
|
+
options: { pluginOptions: { i18n: { localized: true } } },
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should modify the options.pluginOptions when it exists', () => {
|
|
104
|
+
const middleware = extendCTBAttributeInitialDataMiddleware();
|
|
105
|
+
const action = {
|
|
106
|
+
forTarget: 'contentType',
|
|
107
|
+
type: 'ContentTypeBuilder/FormModal/RESET_PROPS_AND_SET_FORM_FOR_ADDING_AN_EXISTING_COMPO',
|
|
108
|
+
options: { pluginOptions: { pluginTest: { ok: true } } },
|
|
109
|
+
};
|
|
110
|
+
const getState = jest.fn(() => ({
|
|
111
|
+
// i18n is activated
|
|
112
|
+
getIn: jest.fn(() => true),
|
|
113
|
+
}));
|
|
114
|
+
|
|
115
|
+
const next = jest.fn();
|
|
116
|
+
|
|
117
|
+
middleware({ getState })(next)(action);
|
|
118
|
+
|
|
119
|
+
expect(next).toBeCalledWith({
|
|
120
|
+
...action,
|
|
121
|
+
options: { pluginOptions: { pluginTest: { ok: true }, i18n: { localized: true } } },
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|