Skip to content

Commit

Permalink
Extract the isValidTemplate from the setupEditorState action
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Feb 23, 2018
1 parent 15e8f10 commit be44df7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
4 changes: 1 addition & 3 deletions editor/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,15 @@ export function resetPost( post ) {
* @param {Object} post Post object.
* @param {Array} blocks Array of blocks.
* @param {Object} edits Initial edited attributes object.
* @param {boolean} isValidTemplate Whether the template is valid or not.
*
* @return {Object} Action object.
*/
export function setupEditorState( post, blocks, edits, isValidTemplate ) {
export function setupEditorState( post, blocks, edits ) {
return {
type: 'SETUP_EDITOR_STATE',
post,
blocks,
edits,
isValidTemplate,
};
}

Expand Down
5 changes: 4 additions & 1 deletion editor/store/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,10 @@ export default {
edits.status = 'draft';
}

return setupEditorState( post, blocks, edits, isValidTemplate );
return [
setTemplateValidity( isValidTemplate ),
setupEditorState( post, blocks, edits ),
];
},
SYNCHRONIZE_TEMPLATE( action, { getState } ) {
const state = getState();
Expand Down
5 changes: 0 additions & 5 deletions editor/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,11 +649,6 @@ export function template( state = { isValid: true }, action ) {
template: action.settings.template,
lock: action.settings.templateLock,
};
case 'SETUP_EDITOR_STATE':
return {
...state,
isValid: action.isValidTemplate,
};
case 'SET_TEMPLATE_VALIDITY':
return {
...state,
Expand Down
18 changes: 14 additions & 4 deletions editor/store/test/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
convertBlockToStatic,
convertBlockToReusable,
selectBlock,
setTemplateValidity,
} from '../../store/actions';
import reducer from '../reducer';
import effects from '../effects';
Expand Down Expand Up @@ -417,7 +418,10 @@ describe( 'effects', () => {

const result = handler( { post, settings: {} } );

expect( result ).toEqual( setupEditorState( post, [], {}, true ) );
expect( result ).toEqual( [
setTemplateValidity( true ),
setupEditorState( post, [], {} ),
] );
} );

it( 'should return block reset with non-empty content', () => {
Expand All @@ -435,8 +439,11 @@ describe( 'effects', () => {

const result = handler( { post, settings: {} } );

expect( result.blocks ).toHaveLength( 1 );
expect( result ).toEqual( setupEditorState( post, result.blocks, {}, true ) );
expect( result[ 1 ].blocks ).toHaveLength( 1 );
expect( result ).toEqual( [
setTemplateValidity( true ),
setupEditorState( post, result[ 1 ].blocks, {} ),
] );
} );

it( 'should return post setup action only if auto-draft', () => {
Expand All @@ -453,7 +460,10 @@ describe( 'effects', () => {

const result = handler( { post, settings: {} } );

expect( result ).toEqual( setupEditorState( post, [], { title: 'A History of Pork', status: 'draft' }, true ) );
expect( result ).toEqual( [
setTemplateValidity( true ),
setupEditorState( post, [], { title: 'A History of Pork', status: 'draft' } ),
] );
} );
} );

Expand Down
10 changes: 0 additions & 10 deletions editor/store/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1776,16 +1776,6 @@ describe( 'state', () => {
expect( state ).toEqual( { isValid: true, template: blockTemplate, lock: 'all' } );
} );

it( 'should set the validity flag', () => {
const original = deepFreeze( { isValid: true, template: [] } );
const state = template( original, {
type: 'SETUP_EDITOR_STATE',
isValidTemplate: false,
} );

expect( state ).toEqual( { isValid: false, template: [] } );
} );

it( 'should reset the validity flag', () => {
const original = deepFreeze( { isValid: false, template: [] } );
const state = template( original, {
Expand Down

0 comments on commit be44df7

Please sign in to comment.