Add test for form saving started reducer
[MAILPOET-2451]
This commit is contained in:
committed by
Jack Kitterhing
parent
fe204ec53f
commit
3a65f103b0
@ -1,15 +1,18 @@
|
|||||||
|
import MailPoet from 'mailpoet';
|
||||||
import changeFormName from './reducers/change_form_name.jsx';
|
import changeFormName from './reducers/change_form_name.jsx';
|
||||||
import changeFormSettings from './reducers/change_form_settings.jsx';
|
import changeFormSettings from './reducers/change_form_settings.jsx';
|
||||||
import changeFormStyles from './reducers/change_form_styles.jsx';
|
import changeFormStyles from './reducers/change_form_styles.jsx';
|
||||||
import removeNotice from './reducers/remove_notice.jsx';
|
import removeNotice from './reducers/remove_notice.jsx';
|
||||||
import saveFormDone from './reducers/save_form_done.jsx';
|
import saveFormDone from './reducers/save_form_done.jsx';
|
||||||
import saveFormFailed from './reducers/save_form_failed.jsx';
|
import saveFormFailed from './reducers/save_form_failed.jsx';
|
||||||
import saveFormStarted from './reducers/save_form_started.jsx';
|
import saveFormStartedFactory from './reducers/save_form_started.jsx';
|
||||||
import switchSidebarTab from './reducers/switch_sidebar_tab.jsx';
|
import switchSidebarTab from './reducers/switch_sidebar_tab.jsx';
|
||||||
import toggleSidebar from './reducers/toggle_sidebar.jsx';
|
import toggleSidebar from './reducers/toggle_sidebar.jsx';
|
||||||
import toggleSidebarPanel from './reducers/toggle_sidebar_panel.jsx';
|
import toggleSidebarPanel from './reducers/toggle_sidebar_panel.jsx';
|
||||||
import changeFormBlocks from './reducers/change_form_blocks.jsx';
|
import changeFormBlocks from './reducers/change_form_blocks.jsx';
|
||||||
|
|
||||||
|
const saveFormStarted = saveFormStartedFactory(MailPoet);
|
||||||
|
|
||||||
export default (defaultState) => (state = defaultState, action) => {
|
export default (defaultState) => (state = defaultState, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'CHANGE_FORM_BLOCKS': return changeFormBlocks(state, action);
|
case 'CHANGE_FORM_BLOCKS': return changeFormBlocks(state, action);
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import MailPoet from 'mailpoet';
|
export default (MailPoet) => (state) => {
|
||||||
|
|
||||||
export default (state) => {
|
|
||||||
// remove all form saving related notices
|
// remove all form saving related notices
|
||||||
const notices = state.notices.filter((notice) => !['save-form', 'missing-lists', 'missing-block'].includes(notice.id));
|
const notices = state.notices.filter((notice) => !['save-form', 'missing-lists', 'missing-block'].includes(notice.id));
|
||||||
const hasMissingLists = state.formErrors.includes('missing-lists');
|
const hasMissingLists = state.formErrors.includes('missing-lists');
|
||||||
|
@ -0,0 +1,99 @@
|
|||||||
|
import { expect } from 'chai';
|
||||||
|
import { identity } from 'lodash';
|
||||||
|
import reducerFactory from '../../../../../assets/js/src/form_editor/store/reducers/save_form_started.jsx';
|
||||||
|
|
||||||
|
const MailPoetStub = {
|
||||||
|
I18n: {
|
||||||
|
t: identity,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const reducer = reducerFactory(MailPoetStub);
|
||||||
|
|
||||||
|
describe.only('Save Form Started Reducer', () => {
|
||||||
|
let initialState = null;
|
||||||
|
beforeEach(() => {
|
||||||
|
initialState = {
|
||||||
|
notices: [],
|
||||||
|
formErrors: [],
|
||||||
|
isFormSaving: false,
|
||||||
|
sidebar: {
|
||||||
|
activeTab: 'block',
|
||||||
|
openedPanels: [],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should set isFormSaving when there are no errors', () => {
|
||||||
|
const action = {
|
||||||
|
type: 'SAVE_FORM_STARTED',
|
||||||
|
};
|
||||||
|
const finalState = reducer(initialState, action);
|
||||||
|
expect(finalState.isFormSaving).to.equal(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should clean all form related notices', () => {
|
||||||
|
const action = {
|
||||||
|
type: 'SAVE_FORM_STARTED',
|
||||||
|
};
|
||||||
|
const state = {
|
||||||
|
...initialState,
|
||||||
|
notices: [
|
||||||
|
{
|
||||||
|
id: 'missing-lists',
|
||||||
|
content: 'message',
|
||||||
|
status: 'error',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'save-form',
|
||||||
|
content: 'message',
|
||||||
|
status: 'error',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'missing-block',
|
||||||
|
content: 'message',
|
||||||
|
status: 'error',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'some-notice',
|
||||||
|
content: 'message',
|
||||||
|
status: 'error',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const finalState = reducer(state, action);
|
||||||
|
expect(finalState.notices.length).to.equal(1);
|
||||||
|
expect(finalState.notices[0].id).to.equal('some-notice');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should set proper state for missing-lists error', () => {
|
||||||
|
const action = {
|
||||||
|
type: 'SAVE_FORM_STARTED',
|
||||||
|
};
|
||||||
|
const state = {
|
||||||
|
...initialState,
|
||||||
|
formErrors: ['missing-lists'],
|
||||||
|
};
|
||||||
|
const finalState = reducer(state, action);
|
||||||
|
expect(finalState.sidebar.activeTab).to.equal('form');
|
||||||
|
expect(finalState.sidebar.openedPanels).to.contain('basic-settings');
|
||||||
|
const listsNotice = finalState.notices.find((notice) => (notice.id === 'missing-lists'));
|
||||||
|
expect(listsNotice).to.not.equal(null);
|
||||||
|
expect(listsNotice.status).to.equal('error');
|
||||||
|
expect(listsNotice.isDismissible).to.equal(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should set proper state for missing email input error', () => {
|
||||||
|
const action = {
|
||||||
|
type: 'SAVE_FORM_STARTED',
|
||||||
|
};
|
||||||
|
const state = {
|
||||||
|
...initialState,
|
||||||
|
formErrors: ['missing-email-input'],
|
||||||
|
};
|
||||||
|
const finalState = reducer(state, action);
|
||||||
|
const listsNotice = finalState.notices.find((notice) => (notice.id === 'missing-block'));
|
||||||
|
expect(listsNotice).to.not.equal(null);
|
||||||
|
expect(listsNotice.status).to.equal('error');
|
||||||
|
expect(listsNotice.isDismissible).to.equal(true);
|
||||||
|
});
|
||||||
|
});
|
Reference in New Issue
Block a user