mirror of
https://github.com/strapi/strapi.git
synced 2025-11-13 08:38:09 +00:00
ModelPage Unit tests with context
This commit is contained in:
parent
7db8366492
commit
b961ef38b7
@ -3,12 +3,7 @@ import { mount } from 'enzyme';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { IntlProvider, intlShape } from 'react-intl';
|
import { IntlProvider, intlShape } from 'react-intl';
|
||||||
|
|
||||||
const mountWithIntl = (
|
const mountWithIntl = (componentToMount, pluginTrads, context = {}) => {
|
||||||
componentToMount,
|
|
||||||
pluginTrads,
|
|
||||||
context = {},
|
|
||||||
childContextTypes = {}
|
|
||||||
) => {
|
|
||||||
const intlProvider = new IntlProvider(
|
const intlProvider = new IntlProvider(
|
||||||
{ locale: 'en', messages: pluginTrads },
|
{ locale: 'en', messages: pluginTrads },
|
||||||
{}
|
{}
|
||||||
@ -17,11 +12,7 @@ const mountWithIntl = (
|
|||||||
|
|
||||||
return mount(React.cloneElement(componentToMount, { intl }), {
|
return mount(React.cloneElement(componentToMount, { intl }), {
|
||||||
context: { intl, ...context },
|
context: { intl, ...context },
|
||||||
childContextTypes: {
|
childContextTypes: { intl: intlShape, emitEvent: PropTypes.func },
|
||||||
intl: intlShape,
|
|
||||||
emitEvent: PropTypes.func,
|
|
||||||
...childContextTypes,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import pluginId from '../../../pluginId';
|
|||||||
import pluginTradsEn from '../../../translations/en.json';
|
import pluginTradsEn from '../../../translations/en.json';
|
||||||
|
|
||||||
import LeftMenu from '../../LeftMenu';
|
import LeftMenu from '../../LeftMenu';
|
||||||
|
import MenuContext from '../../MenuContext';
|
||||||
import Block from '../../../components/Block';
|
import Block from '../../../components/Block';
|
||||||
|
|
||||||
import { clearTemporaryAttribute, onChangeAttribute } from '../../App/actions';
|
import { clearTemporaryAttribute, onChangeAttribute } from '../../App/actions';
|
||||||
@ -24,14 +25,23 @@ import initialData from './initialData.json';
|
|||||||
const messages = formatMessagesWithPluginId(pluginId, pluginTradsEn);
|
const messages = formatMessagesWithPluginId(pluginId, pluginTradsEn);
|
||||||
|
|
||||||
const context = { emitEvent: jest.fn() };
|
const context = { emitEvent: jest.fn() };
|
||||||
const renderComponent = (props = {}) =>
|
const renderComponent = (props = {}) => {
|
||||||
mountWithIntl(
|
const menucontext = {
|
||||||
|
canOpenModal: true,
|
||||||
|
groups: [],
|
||||||
|
models: [],
|
||||||
|
push: jest.fn(),
|
||||||
|
};
|
||||||
|
return mountWithIntl(
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
|
<MenuContext.Provider value={menucontext}>
|
||||||
<ModelPage {...props} />
|
<ModelPage {...props} />
|
||||||
|
</MenuContext.Provider>
|
||||||
</BrowserRouter>,
|
</BrowserRouter>,
|
||||||
messages,
|
messages,
|
||||||
context
|
context
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// @soupette
|
// @soupette
|
||||||
// TODO update the test when switching to react testing lib
|
// TODO update the test when switching to react testing lib
|
||||||
@ -321,14 +331,14 @@ describe('<ModelPage />', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// describe('RenderLeftMenu', () => {
|
describe('RenderLeftMenu', () => {
|
||||||
// it('should render a LeftMenu', () => {
|
it('should render a LeftMenu', () => {
|
||||||
// const wrapper = shallow(<ModelPage {...props} />);
|
const wrapper = shallow(<ModelPage {...props} />);
|
||||||
// const leftMenu = wrapper.find(LeftMenu);
|
const leftMenu = wrapper.find(LeftMenu);
|
||||||
|
|
||||||
// expect(leftMenu).toHaveLength(1);
|
expect(leftMenu).toHaveLength(1);
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// describe('GetSectionTitle', () => {
|
// describe('GetSectionTitle', () => {
|
||||||
// it('should return a singular string for the product', () => {
|
// it('should return a singular string for the product', () => {
|
||||||
@ -490,222 +500,222 @@ describe('<ModelPage /> lifecycle', () => {
|
|||||||
topCompo.unmount();
|
topCompo.unmount();
|
||||||
});
|
});
|
||||||
|
|
||||||
// describe('HandleClickEditAttribute', () => {
|
describe('HandleClickEditAttribute', () => {
|
||||||
// it('should emit the event editFieldOfContentType', async () => {
|
it('should emit the event editFieldOfContentType', async () => {
|
||||||
// topCompo = renderComponent(props);
|
topCompo = renderComponent(props);
|
||||||
// const wrapper = topCompo.find(ModelPage);
|
const wrapper = topCompo.find(ModelPage);
|
||||||
|
|
||||||
// const spyOnWait = jest.spyOn(wrapper.instance(), 'wait');
|
const spyOnWait = jest.spyOn(wrapper.instance(), 'wait');
|
||||||
// const { handleClickEditAttribute } = wrapper.instance();
|
const { handleClickEditAttribute } = wrapper.instance();
|
||||||
|
|
||||||
// handleClickEditAttribute('username', 'string');
|
handleClickEditAttribute('username', 'string');
|
||||||
|
|
||||||
// expect(spyOnWait).toHaveBeenCalled();
|
expect(spyOnWait).toHaveBeenCalled();
|
||||||
|
|
||||||
// await wait();
|
await wait();
|
||||||
|
|
||||||
// expect(context.emitEvent).toHaveBeenCalledWith(
|
expect(context.emitEvent).toHaveBeenCalledWith(
|
||||||
// 'willEditFieldOfContentType'
|
'willEditFieldOfContentType'
|
||||||
// );
|
);
|
||||||
// expect(props.history.push).toHaveBeenCalledWith({
|
expect(props.history.push).toHaveBeenCalledWith({
|
||||||
// search:
|
search:
|
||||||
// 'modalType=attributeForm&attributeType=string&settingType=base&actionType=edit&attributeName=username',
|
'modalType=attributeForm&attributeType=string&settingType=base&actionType=edit&attributeName=username',
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// it('should handle the <number> type correctly', async () => {
|
it('should handle the <number> type correctly', async () => {
|
||||||
// topCompo = renderComponent(props);
|
topCompo = renderComponent(props);
|
||||||
// const wrapper = topCompo.find(ModelPage);
|
const wrapper = topCompo.find(ModelPage);
|
||||||
|
|
||||||
// const spyOnWait = jest.spyOn(wrapper.instance(), 'wait');
|
const spyOnWait = jest.spyOn(wrapper.instance(), 'wait');
|
||||||
// const { handleClickEditAttribute } = wrapper.instance();
|
const { handleClickEditAttribute } = wrapper.instance();
|
||||||
|
|
||||||
// handleClickEditAttribute('username', 'float');
|
handleClickEditAttribute('username', 'float');
|
||||||
|
|
||||||
// expect(spyOnWait).toHaveBeenCalled();
|
expect(spyOnWait).toHaveBeenCalled();
|
||||||
|
|
||||||
// await wait();
|
await wait();
|
||||||
|
|
||||||
// expect(context.emitEvent).toHaveBeenCalledWith(
|
expect(context.emitEvent).toHaveBeenCalledWith(
|
||||||
// 'willEditFieldOfContentType'
|
'willEditFieldOfContentType'
|
||||||
// );
|
);
|
||||||
// expect(props.history.push).toHaveBeenCalledWith({
|
expect(props.history.push).toHaveBeenCalledWith({
|
||||||
// search:
|
search:
|
||||||
// 'modalType=attributeForm&attributeType=number&settingType=base&actionType=edit&attributeName=username',
|
'modalType=attributeForm&attributeType=number&settingType=base&actionType=edit&attributeName=username',
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// describe('HandleClickEditModelMainInfos', () => {
|
describe('HandleClickEditModelMainInfos', () => {
|
||||||
// it('should display a notification if thee modal cannot be opened', async () => {
|
it('should display a notification if thee modal cannot be opened', async () => {
|
||||||
// props.canOpenModal = false;
|
props.canOpenModal = false;
|
||||||
|
|
||||||
// topCompo = renderComponent(props);
|
topCompo = renderComponent(props);
|
||||||
// const wrapper = topCompo.find(ModelPage);
|
const wrapper = topCompo.find(ModelPage);
|
||||||
|
|
||||||
// const spyOnWait = jest.spyOn(wrapper.instance(), 'wait');
|
const spyOnWait = jest.spyOn(wrapper.instance(), 'wait');
|
||||||
// const spyOnDisplayNotification = jest.spyOn(
|
const spyOnDisplayNotification = jest.spyOn(
|
||||||
// wrapper.instance(),
|
wrapper.instance(),
|
||||||
// 'displayNotificationCTNotSaved'
|
'displayNotificationCTNotSaved'
|
||||||
// );
|
);
|
||||||
// const { handleClickEditModelMainInfos } = wrapper.instance();
|
const { handleClickEditModelMainInfos } = wrapper.instance();
|
||||||
|
|
||||||
// handleClickEditModelMainInfos();
|
handleClickEditModelMainInfos();
|
||||||
|
|
||||||
// expect(spyOnWait).toHaveBeenCalled();
|
expect(spyOnWait).toHaveBeenCalled();
|
||||||
|
|
||||||
// await wait();
|
await wait();
|
||||||
|
|
||||||
// expect(context.emitEvent).not.toHaveBeenCalledWith(
|
expect(context.emitEvent).not.toHaveBeenCalledWith(
|
||||||
// 'willEditNameOfContentType'
|
'willEditNameOfContentType'
|
||||||
// );
|
);
|
||||||
// expect(props.history.push).not.toHaveBeenCalled();
|
expect(props.history.push).not.toHaveBeenCalled();
|
||||||
// expect(spyOnDisplayNotification).toHaveBeenCalled();
|
expect(spyOnDisplayNotification).toHaveBeenCalled();
|
||||||
// });
|
});
|
||||||
|
|
||||||
// it('should emit the event editFieldOfContentType', async () => {
|
it('should emit the event editFieldOfContentType', async () => {
|
||||||
// props.canOpenModal = true;
|
props.canOpenModal = true;
|
||||||
// topCompo = renderComponent(props);
|
topCompo = renderComponent(props);
|
||||||
// const wrapper = topCompo.find(ModelPage);
|
const wrapper = topCompo.find(ModelPage);
|
||||||
|
|
||||||
// const spyOnWait = jest.spyOn(wrapper.instance(), 'wait');
|
const spyOnWait = jest.spyOn(wrapper.instance(), 'wait');
|
||||||
// const { handleClickEditModelMainInfos } = wrapper.instance();
|
const { handleClickEditModelMainInfos } = wrapper.instance();
|
||||||
|
|
||||||
// handleClickEditModelMainInfos();
|
handleClickEditModelMainInfos();
|
||||||
|
|
||||||
// expect(spyOnWait).toHaveBeenCalled();
|
expect(spyOnWait).toHaveBeenCalled();
|
||||||
|
|
||||||
// await wait();
|
await wait();
|
||||||
|
|
||||||
// expect(context.emitEvent).toHaveBeenCalledWith(
|
expect(context.emitEvent).toHaveBeenCalledWith(
|
||||||
// 'willEditNameOfContentType'
|
'willEditNameOfContentType'
|
||||||
// );
|
);
|
||||||
// expect(props.history.push).toHaveBeenCalledWith({
|
expect(props.history.push).toHaveBeenCalledWith({
|
||||||
// search:
|
search:
|
||||||
// 'modalType=model&settingType=base&actionType=edit&modelName=product',
|
'modalType=model&settingType=base&actionType=edit&modelName=product',
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// describe('HandleClickOpenModalChooseAttributes', () => {
|
describe('HandleClickOpenModalChooseAttributes', () => {
|
||||||
// it('should display a notification if thee modal cannot be opened', async () => {
|
it('should display a notification if thee modal cannot be opened', async () => {
|
||||||
// props.canOpenModal = false;
|
props.canOpenModal = false;
|
||||||
|
|
||||||
// topCompo = renderComponent(props);
|
topCompo = renderComponent(props);
|
||||||
// const wrapper = topCompo.find(ModelPage);
|
const wrapper = topCompo.find(ModelPage);
|
||||||
|
|
||||||
// const spyOnWait = jest.spyOn(wrapper.instance(), 'wait');
|
const spyOnWait = jest.spyOn(wrapper.instance(), 'wait');
|
||||||
// const spyOnDisplayNotification = jest.spyOn(
|
const spyOnDisplayNotification = jest.spyOn(
|
||||||
// wrapper.instance(),
|
wrapper.instance(),
|
||||||
// 'displayNotificationCTNotSaved'
|
'displayNotificationCTNotSaved'
|
||||||
// );
|
);
|
||||||
// const { handleClickOpenModalChooseAttributes } = wrapper.instance();
|
const { handleClickOpenModalChooseAttributes } = wrapper.instance();
|
||||||
|
|
||||||
// handleClickOpenModalChooseAttributes();
|
handleClickOpenModalChooseAttributes();
|
||||||
|
|
||||||
// expect(spyOnWait).toHaveBeenCalled();
|
expect(spyOnWait).toHaveBeenCalled();
|
||||||
|
|
||||||
// await wait();
|
await wait();
|
||||||
|
|
||||||
// expect(props.history.push).not.toHaveBeenCalled();
|
expect(props.history.push).not.toHaveBeenCalled();
|
||||||
// expect(spyOnDisplayNotification).toHaveBeenCalled();
|
expect(spyOnDisplayNotification).toHaveBeenCalled();
|
||||||
// });
|
});
|
||||||
|
|
||||||
// it('should emit the event editFieldOfContentType', async () => {
|
it('should emit the event editFieldOfContentType', async () => {
|
||||||
// props.canOpenModal = true;
|
props.canOpenModal = true;
|
||||||
// topCompo = renderComponent(props);
|
topCompo = renderComponent(props);
|
||||||
// const wrapper = topCompo.find(ModelPage);
|
const wrapper = topCompo.find(ModelPage);
|
||||||
|
|
||||||
// const spyOnWait = jest.spyOn(wrapper.instance(), 'wait');
|
const spyOnWait = jest.spyOn(wrapper.instance(), 'wait');
|
||||||
// const { handleClickOpenModalChooseAttributes } = wrapper.instance();
|
const { handleClickOpenModalChooseAttributes } = wrapper.instance();
|
||||||
|
|
||||||
// handleClickOpenModalChooseAttributes();
|
handleClickOpenModalChooseAttributes();
|
||||||
|
|
||||||
// expect(spyOnWait).toHaveBeenCalled();
|
expect(spyOnWait).toHaveBeenCalled();
|
||||||
|
|
||||||
// await wait();
|
await wait();
|
||||||
|
|
||||||
// expect(context.emitEvent).toHaveBeenCalledWith(
|
expect(context.emitEvent).toHaveBeenCalledWith(
|
||||||
// 'willEditNameOfContentType'
|
'willEditNameOfContentType'
|
||||||
// );
|
);
|
||||||
// expect(props.history.push).toHaveBeenCalledWith({
|
expect(props.history.push).toHaveBeenCalledWith({
|
||||||
// search: 'modalType=chooseAttributes',
|
search: 'modalType=chooseAttributes',
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// describe('handleClickOpenModalCreateCT', () => {
|
describe('handleClickOpenModalCreateCT', () => {
|
||||||
// it('should display a notification if thee modal cannot be opened', async () => {
|
it('should display a notification if thee modal cannot be opened', async () => {
|
||||||
// props.canOpenModal = false;
|
props.canOpenModal = false;
|
||||||
// topCompo = renderComponent(props);
|
topCompo = renderComponent(props);
|
||||||
|
|
||||||
// const wrapper = topCompo.find(ModelPage);
|
const wrapper = topCompo.find(ModelPage);
|
||||||
// const spyOnDisplayNotification = jest.spyOn(
|
const spyOnDisplayNotification = jest.spyOn(
|
||||||
// wrapper.instance(),
|
wrapper.instance(),
|
||||||
// 'displayNotificationCTNotSaved'
|
'displayNotificationCTNotSaved'
|
||||||
// );
|
);
|
||||||
// const { handleClickOpenModalCreateCT } = wrapper.instance();
|
const { handleClickOpenModalCreateCT } = wrapper.instance();
|
||||||
|
|
||||||
// handleClickOpenModalCreateCT();
|
handleClickOpenModalCreateCT();
|
||||||
|
|
||||||
// expect(props.history.push).not.toHaveBeenCalled();
|
expect(props.history.push).not.toHaveBeenCalled();
|
||||||
// expect(spyOnDisplayNotification).toHaveBeenCalled();
|
expect(spyOnDisplayNotification).toHaveBeenCalled();
|
||||||
// });
|
});
|
||||||
|
|
||||||
// it('should emit the event editFieldOfContentType', async () => {
|
it('should emit the event editFieldOfContentType', async () => {
|
||||||
// props.canOpenModal = true;
|
props.canOpenModal = true;
|
||||||
// topCompo = renderComponent(props);
|
topCompo = renderComponent(props);
|
||||||
|
|
||||||
// const wrapper = topCompo.find(ModelPage);
|
const wrapper = topCompo.find(ModelPage);
|
||||||
// const { handleClickOpenModalCreateCT } = wrapper.instance();
|
const { handleClickOpenModalCreateCT } = wrapper.instance();
|
||||||
|
|
||||||
// handleClickOpenModalCreateCT();
|
handleClickOpenModalCreateCT();
|
||||||
|
|
||||||
// expect(props.history.push).toHaveBeenCalledWith({
|
expect(props.history.push).toHaveBeenCalledWith({
|
||||||
// search: 'modalType=model&settingType=base&actionType=create',
|
search: 'modalType=model&settingType=base&actionType=create',
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
|
||||||
// describe('HandleClickOnTrashIcon', () => {
|
describe('HandleClickOnTrashIcon', () => {
|
||||||
// it('should display a notification if thee modal cannot be opened', async () => {
|
it('should display a notification if thee modal cannot be opened', async () => {
|
||||||
// props.canOpenModal = false;
|
props.canOpenModal = false;
|
||||||
// topCompo = renderComponent(props);
|
topCompo = renderComponent(props);
|
||||||
|
|
||||||
// const wrapper = topCompo.find(ModelPage);
|
const wrapper = topCompo.find(ModelPage);
|
||||||
// const spyOnDisplayNotification = jest.spyOn(
|
const spyOnDisplayNotification = jest.spyOn(
|
||||||
// wrapper.instance(),
|
wrapper.instance(),
|
||||||
// 'displayNotificationCTNotSaved'
|
'displayNotificationCTNotSaved'
|
||||||
// );
|
);
|
||||||
// const { handleClickOnTrashIcon } = wrapper.instance();
|
const { handleClickOnTrashIcon } = wrapper.instance();
|
||||||
|
|
||||||
// handleClickOnTrashIcon('username');
|
handleClickOnTrashIcon('username');
|
||||||
|
|
||||||
// expect(context.emitEvent).not.toHaveBeenCalledWith(
|
expect(context.emitEvent).not.toHaveBeenCalledWith(
|
||||||
// 'willDeleteFieldOfContentType'
|
'willDeleteFieldOfContentType'
|
||||||
// );
|
);
|
||||||
// expect(spyOnDisplayNotification).toHaveBeenCalled();
|
expect(spyOnDisplayNotification).toHaveBeenCalled();
|
||||||
// });
|
});
|
||||||
|
|
||||||
// it('should emit the event willDeleteFieldOfContentType', async () => {
|
it('should emit the event willDeleteFieldOfContentType', async () => {
|
||||||
// props.canOpenModal = true;
|
props.canOpenModal = true;
|
||||||
// topCompo = renderComponent(props);
|
topCompo = renderComponent(props);
|
||||||
|
|
||||||
// const wrapper = topCompo.find(ModelPage);
|
const wrapper = topCompo.find(ModelPage);
|
||||||
// const { handleClickOnTrashIcon } = wrapper.instance();
|
const { handleClickOnTrashIcon } = wrapper.instance();
|
||||||
|
|
||||||
// handleClickOnTrashIcon('username');
|
handleClickOnTrashIcon('username');
|
||||||
|
|
||||||
// expect(wrapper.state()).toEqual({
|
expect(wrapper.state()).toEqual({
|
||||||
// showWarning: true,
|
showWarning: true,
|
||||||
// removePrompt: false,
|
removePrompt: false,
|
||||||
// attrToDelete: 'username',
|
attrToDelete: 'username',
|
||||||
// });
|
});
|
||||||
// expect(context.emitEvent).toHaveBeenCalledWith(
|
expect(context.emitEvent).toHaveBeenCalledWith(
|
||||||
// 'willDeleteFieldOfContentType'
|
'willDeleteFieldOfContentType'
|
||||||
// );
|
);
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('CTB <ModelPage />, mapDispatchToProps', () => {
|
describe('CTB <ModelPage />, mapDispatchToProps', () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user