mirror of
https://github.com/strapi/strapi.git
synced 2025-09-23 15:29:27 +00:00
Test data manager provider add custom field action
This commit is contained in:
parent
a20ad9955f
commit
be8a45af9f
@ -0,0 +1,59 @@
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import reducer, { initialState } from '../reducer';
|
||||
import { ADD_CUSTOM_FIELD_ATTRIBUTE } from '../constants';
|
||||
|
||||
describe('CTB | components | DataManagerProvider | reducer | ADD_CUSTOM_FIELD_ATTRIBUTE', () => {
|
||||
it('adds a custom field to a contentType', () => {
|
||||
const contentType = {
|
||||
uid: 'api::test.test',
|
||||
schema: {
|
||||
name: 'test',
|
||||
description: '',
|
||||
connection: 'default',
|
||||
collectionName: '',
|
||||
attributes: [{ name: 'test', type: 'string' }],
|
||||
},
|
||||
};
|
||||
|
||||
const action = {
|
||||
type: ADD_CUSTOM_FIELD_ATTRIBUTE,
|
||||
attributeToSet: {
|
||||
type: 'string',
|
||||
name: 'color',
|
||||
options: { format: 'hex' },
|
||||
},
|
||||
forTarget: 'contentType',
|
||||
targetUid: 'api::test.test',
|
||||
initialAttribute: {},
|
||||
};
|
||||
|
||||
const state = {
|
||||
...initialState,
|
||||
modifiedData: {
|
||||
components: {},
|
||||
contentType,
|
||||
},
|
||||
};
|
||||
|
||||
const updatedContentType = cloneDeep(contentType);
|
||||
updatedContentType.schema.attributes.push({
|
||||
name: 'color',
|
||||
// The type is converted to customField on the server,
|
||||
// The underlying data type is expected here
|
||||
type: 'string',
|
||||
options: {
|
||||
format: 'hex',
|
||||
},
|
||||
});
|
||||
|
||||
const expected = {
|
||||
...initialState,
|
||||
modifiedData: {
|
||||
components: {},
|
||||
contentType: updatedContentType,
|
||||
},
|
||||
};
|
||||
|
||||
expect(reducer(state, action)).toEqual(expected);
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user