mirror of
https://github.com/strapi/strapi.git
synced 2025-11-10 07:10:11 +00:00
Add tests
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
c68dc0fc33
commit
fa83bc1508
@ -8,8 +8,7 @@ const extendCTBInitialDataMiddleware = () => {
|
|||||||
) {
|
) {
|
||||||
const i18n = { localized: false };
|
const i18n = { localized: false };
|
||||||
|
|
||||||
const pluginOptions =
|
const pluginOptions = action.data.pluginOptions
|
||||||
action.data && action.data.pluginOptions
|
|
||||||
? { ...action.data.pluginOptions, i18n }
|
? { ...action.data.pluginOptions, i18n }
|
||||||
: { i18n };
|
: { i18n };
|
||||||
|
|
||||||
@ -21,7 +20,7 @@ const extendCTBInitialDataMiddleware = () => {
|
|||||||
|
|
||||||
// Override the action if the pluginOption config does not contain i18n
|
// Override the action if the pluginOption config does not contain i18n
|
||||||
// In this case we need to set the proper initialData shape
|
// In this case we need to set the proper initialData shape
|
||||||
if (!has(action.data.pluginOptions, 'i18n')) {
|
if (!has(action.data.pluginOptions, 'i18n.localized')) {
|
||||||
return next({ ...action, data });
|
return next({ ...action, data });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import middlewares from '../middlewares';
|
import middlewares from '../middlewares';
|
||||||
|
|
||||||
describe('extendCTBInitialDataMiddleware', () => {
|
describe('extendCTBInitialDataMiddleware', () => {
|
||||||
it('forwards the action when the action, type does not match', () => {
|
describe('the action type matches "ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT"', () => {
|
||||||
|
it('forwards the action when the action type does not match', () => {
|
||||||
const extendCTBInitialDataMiddleware = middlewares[0]();
|
const extendCTBInitialDataMiddleware = middlewares[0]();
|
||||||
const next = jest.fn();
|
const next = jest.fn();
|
||||||
const action = {};
|
const action = {};
|
||||||
@ -11,7 +12,7 @@ describe('extendCTBInitialDataMiddleware', () => {
|
|||||||
expect(next).toBeCalledWith(action);
|
expect(next).toBeCalledWith(action);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('forwards the action when the action type is "ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT" but modalType and actionType are undefined', () => {
|
it('forwards the action when the modalType and actionType are undefined', () => {
|
||||||
const extendCTBInitialDataMiddleware = middlewares[0]();
|
const extendCTBInitialDataMiddleware = middlewares[0]();
|
||||||
const next = jest.fn();
|
const next = jest.fn();
|
||||||
const action = {
|
const action = {
|
||||||
@ -25,13 +26,14 @@ describe('extendCTBInitialDataMiddleware', () => {
|
|||||||
expect(next).toBeCalledWith(action);
|
expect(next).toBeCalledWith(action);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('forwards the action when the action type is "ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT" and modalType is "contentType" but actionType are undefined', () => {
|
it('forwards the action when the action.data.pluginOptions.i18n.localized path exists', () => {
|
||||||
const extendCTBInitialDataMiddleware = middlewares[0]();
|
const extendCTBInitialDataMiddleware = middlewares[0]();
|
||||||
const next = jest.fn();
|
const next = jest.fn();
|
||||||
const action = {
|
const action = {
|
||||||
type: 'ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT',
|
type: 'ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT',
|
||||||
modalType: 'contentType',
|
modalType: undefined,
|
||||||
actionType: undefined,
|
actionType: undefined,
|
||||||
|
data: { pluginOptions: { i18n: { localized: false } } },
|
||||||
};
|
};
|
||||||
|
|
||||||
extendCTBInitialDataMiddleware()(next)(action);
|
extendCTBInitialDataMiddleware()(next)(action);
|
||||||
@ -39,35 +41,13 @@ describe('extendCTBInitialDataMiddleware', () => {
|
|||||||
expect(next).toBeCalledWith(action);
|
expect(next).toBeCalledWith(action);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('adds a pluginOptions to the action when action.data is undefined', () => {
|
it('adds a pluginOptions to the action when data is defined and the action', () => {
|
||||||
const extendCTBInitialDataMiddleware = middlewares[0]();
|
const extendCTBInitialDataMiddleware = middlewares[0]();
|
||||||
const next = jest.fn();
|
const next = jest.fn();
|
||||||
const action = {
|
const action = {
|
||||||
type: 'ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT',
|
type: 'ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT',
|
||||||
modalType: 'contentType',
|
modalType: 'contentType',
|
||||||
actionType: 'create',
|
actionType: 'edit',
|
||||||
data: undefined,
|
|
||||||
};
|
|
||||||
|
|
||||||
extendCTBInitialDataMiddleware()(next)(action);
|
|
||||||
|
|
||||||
expect(next).toBeCalledWith({
|
|
||||||
type: 'ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT',
|
|
||||||
modalType: 'contentType',
|
|
||||||
actionType: 'create',
|
|
||||||
data: {
|
|
||||||
pluginOptions: { i18n: { localized: true } },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('adds a pluginOptions to the action when data is defined', () => {
|
|
||||||
const extendCTBInitialDataMiddleware = middlewares[0]();
|
|
||||||
const next = jest.fn();
|
|
||||||
const action = {
|
|
||||||
type: 'ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT',
|
|
||||||
modalType: 'contentType',
|
|
||||||
actionType: 'create',
|
|
||||||
data: {},
|
data: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -76,9 +56,9 @@ describe('extendCTBInitialDataMiddleware', () => {
|
|||||||
expect(next).toBeCalledWith({
|
expect(next).toBeCalledWith({
|
||||||
type: 'ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT',
|
type: 'ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT',
|
||||||
modalType: 'contentType',
|
modalType: 'contentType',
|
||||||
actionType: 'create',
|
actionType: 'edit',
|
||||||
data: {
|
data: {
|
||||||
pluginOptions: { i18n: { localized: true } },
|
pluginOptions: { i18n: { localized: false } },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -89,7 +69,7 @@ describe('extendCTBInitialDataMiddleware', () => {
|
|||||||
const action = {
|
const action = {
|
||||||
type: 'ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT',
|
type: 'ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT',
|
||||||
modalType: 'contentType',
|
modalType: 'contentType',
|
||||||
actionType: 'create',
|
actionType: 'edit',
|
||||||
data: {
|
data: {
|
||||||
pluginOptions: {
|
pluginOptions: {
|
||||||
somePluginThings: true,
|
somePluginThings: true,
|
||||||
@ -102,10 +82,11 @@ describe('extendCTBInitialDataMiddleware', () => {
|
|||||||
expect(next).toBeCalledWith({
|
expect(next).toBeCalledWith({
|
||||||
type: 'ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT',
|
type: 'ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT',
|
||||||
modalType: 'contentType',
|
modalType: 'contentType',
|
||||||
actionType: 'create',
|
actionType: 'edit',
|
||||||
data: {
|
data: {
|
||||||
pluginOptions: { i18n: { localized: true }, somePluginThings: true },
|
pluginOptions: { i18n: { localized: false }, somePluginThings: true },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user