mirror of
https://github.com/strapi/strapi.git
synced 2025-11-13 16:52:18 +00:00
Add missing tests
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
c2acc31212
commit
7a9c3c0edc
@ -1,6 +1,8 @@
|
|||||||
const extendCTBAttributeInitialDataMiddleware = () => {
|
const extendCTBAttributeInitialDataMiddleware = () => {
|
||||||
return ({ getState }) => next => action => {
|
return ({ getState }) => next => action => {
|
||||||
const enhanceAction = () => {
|
const enhanceAction = () => {
|
||||||
|
// the block here is to catch the error when trying to access the state
|
||||||
|
// of the ctb when the plugin is not mounted
|
||||||
try {
|
try {
|
||||||
const hasi18nEnabled = getState().getIn([
|
const hasi18nEnabled = getState().getIn([
|
||||||
'content-type-builder_dataManagerProvider',
|
'content-type-builder_dataManagerProvider',
|
||||||
|
|||||||
@ -0,0 +1,124 @@
|
|||||||
|
import extendCTBAttributeInitialDataMiddleware from '../extendCTBAttributeInitialDataMiddleware';
|
||||||
|
|
||||||
|
describe('i18n | middlewares | extendCTBAttributeInitialDataMiddleware', () => {
|
||||||
|
it('should forward the action if the type is undefined', () => {
|
||||||
|
const middleware = extendCTBAttributeInitialDataMiddleware();
|
||||||
|
const action = { test: true, type: undefined };
|
||||||
|
const getState = jest.fn();
|
||||||
|
|
||||||
|
const next = jest.fn();
|
||||||
|
|
||||||
|
middleware({ getState })(next)(action);
|
||||||
|
|
||||||
|
expect(next).toBeCalledWith(action);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should forward if the type is not correct', () => {
|
||||||
|
const middleware = extendCTBAttributeInitialDataMiddleware();
|
||||||
|
const action = { test: true, type: 'TEST' };
|
||||||
|
const getState = jest.fn();
|
||||||
|
|
||||||
|
const next = jest.fn();
|
||||||
|
|
||||||
|
middleware({ getState })(next)(action);
|
||||||
|
|
||||||
|
expect(next).toBeCalledWith(action);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('should forward when the type is ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA', () => {
|
||||||
|
it('should forward if the forTarget is not contentType', () => {
|
||||||
|
const middleware = extendCTBAttributeInitialDataMiddleware();
|
||||||
|
const action = {
|
||||||
|
forTarget: 'contentType',
|
||||||
|
type: 'ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA',
|
||||||
|
};
|
||||||
|
const getState = jest.fn();
|
||||||
|
|
||||||
|
const next = jest.fn();
|
||||||
|
|
||||||
|
middleware({ getState })(next)(action);
|
||||||
|
|
||||||
|
expect(next).toBeCalledWith(action);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should forward if the i18n is not activated is not contentType', () => {
|
||||||
|
const middleware = extendCTBAttributeInitialDataMiddleware();
|
||||||
|
const action = {
|
||||||
|
forTarget: 'contentType',
|
||||||
|
attributeType: 'text',
|
||||||
|
type: 'ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA',
|
||||||
|
};
|
||||||
|
const getState = jest.fn(() => ({
|
||||||
|
getIn: jest.fn(() => false),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const next = jest.fn();
|
||||||
|
|
||||||
|
middleware({ getState })(next)(action);
|
||||||
|
|
||||||
|
expect(next).toBeCalledWith(action);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should forward if the ctb is not mounted', () => {
|
||||||
|
const middleware = extendCTBAttributeInitialDataMiddleware();
|
||||||
|
const action = {
|
||||||
|
forTarget: 'contentType',
|
||||||
|
attributeType: 'text',
|
||||||
|
type: 'ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA',
|
||||||
|
};
|
||||||
|
const getState = jest.fn(() => ({
|
||||||
|
getIn: undefined,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const next = jest.fn();
|
||||||
|
|
||||||
|
middleware({ getState })(next)(action);
|
||||||
|
|
||||||
|
expect(next).toBeCalledWith(action);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add the action.pluginOptions if the type is correct and i18n is activated', () => {
|
||||||
|
const middleware = extendCTBAttributeInitialDataMiddleware();
|
||||||
|
const action = {
|
||||||
|
forTarget: 'contentType',
|
||||||
|
attributeType: 'text',
|
||||||
|
type: 'ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA',
|
||||||
|
};
|
||||||
|
const getState = jest.fn(() => ({
|
||||||
|
// i18n is activated
|
||||||
|
getIn: jest.fn(() => true),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const next = jest.fn();
|
||||||
|
|
||||||
|
middleware({ getState })(next)(action);
|
||||||
|
|
||||||
|
expect(next).toBeCalledWith({
|
||||||
|
...action,
|
||||||
|
options: { pluginOptions: { i18n: { localized: true } } },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should modify the options.pluginOptions when it exists', () => {
|
||||||
|
const middleware = extendCTBAttributeInitialDataMiddleware();
|
||||||
|
const action = {
|
||||||
|
forTarget: 'contentType',
|
||||||
|
type: 'ContentTypeBuilder/FormModal/RESET_PROPS_AND_SET_FORM_FOR_ADDING_AN_EXISTING_COMPO',
|
||||||
|
options: { pluginOptions: { pluginTest: { ok: true } } },
|
||||||
|
};
|
||||||
|
const getState = jest.fn(() => ({
|
||||||
|
// i18n is activated
|
||||||
|
getIn: jest.fn(() => true),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const next = jest.fn();
|
||||||
|
|
||||||
|
middleware({ getState })(next)(action);
|
||||||
|
|
||||||
|
expect(next).toBeCalledWith({
|
||||||
|
...action,
|
||||||
|
options: { pluginOptions: { pluginTest: { ok: true }, i18n: { localized: true } } },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -1,6 +1,6 @@
|
|||||||
import middleware from '../extendCTBInitialDataMiddleware';
|
import middleware from '../extendCTBInitialDataMiddleware';
|
||||||
|
|
||||||
describe('extendCTBInitialDataMiddleware', () => {
|
describe('i18n | middlewares | extendCTBInitialDataMiddleware', () => {
|
||||||
describe('the action type matches "ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT"', () => {
|
describe('the action type matches "ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT"', () => {
|
||||||
it('forwards the action when the action type does not match', () => {
|
it('forwards the action when the action type does not match', () => {
|
||||||
const extendCTBInitialDataMiddleware = middleware();
|
const extendCTBInitialDataMiddleware = middleware();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user