Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks committed Aug 21, 2023
1 parent 30381b0 commit 787b0f2
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/edit-site/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { store as preferencesStore } from '@wordpress/preferences';
* Internal dependencies
*/
import { store as editSiteStore } from '..';
import { setHasPageContentFocus } from '../actions';
import { setHasPageContentFocus, setPageContentFocusType } from '../actions';

const ENTITY_TYPES = {
wp_template: {
Expand Down Expand Up @@ -246,4 +246,13 @@ describe( 'actions', () => {
} );
} );
} );

describe( 'setPageContentFocusType', () => {
it( 'sets the page content focus type', () => {
expect( setPageContentFocusType( 'disableTemplate' ) ).toEqual( {
type: 'SET_PAGE_CONTENT_FOCUS_TYPE',
pageContentFocusType: 'disableTemplate',
} );
} );
} );
} );
18 changes: 18 additions & 0 deletions packages/edit-site/src/store/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
blockInserterPanel,
listViewPanel,
hasPageContentFocus,
pageContentFocusType,
} from '../reducer';

import { setIsInserterOpened, setIsListViewOpened } from '../actions';
Expand Down Expand Up @@ -179,4 +180,21 @@ describe( 'state', () => {
).toBe( false );
} );
} );

describe( 'pageContentFocusType', () => {
it( 'defaults to disableTemplate', () => {
expect( pageContentFocusType( undefined, {} ) ).toBe(
'disableTemplate'
);
} );

it( 'can be set', () => {
expect(
pageContentFocusType( 'disableTemplate', {
type: 'SET_PAGE_CONTENT_FOCUS_TYPE',
pageContentFocusType: 'enableTemplate',
} )
).toBe( 'enableTemplate' );
} );
} );
} );
38 changes: 38 additions & 0 deletions packages/edit-site/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
__unstableGetPreference,
isPage,
hasPageContentFocus,
getPageContentFocusType,
} from '../selectors';

describe( 'selectors', () => {
Expand Down Expand Up @@ -204,4 +205,41 @@ describe( 'selectors', () => {
expect( hasPageContentFocus( state ) ).toBe( false );
} );
} );

describe( 'getPageContentFocusType', () => {
it( 'returns the current content focus type', () => {
const state = {
editedPost: {
postType: 'wp_template',
context: { postType: 'page', postId: 123 },
},
hasPageContentFocus: true,
pageContentFocusType: 'disableTemplate',
};
expect( getPageContentFocusType( state ) ).toBe(
'disableTemplate'
);
} );

it( 'returns null if the page does not have content focus', () => {
const state = {
editedPost: {
postType: 'wp_template',
context: { postType: 'page', postId: 123 },
},
hasPageContentFocus: false,
};
expect( getPageContentFocusType( state ) ).toBe( null );
} );

it( 'returns null if the edited post type is a template', () => {
const state = {
editedPost: {
postType: 'wp_template',
},
hasPageContentFocus: true,
};
expect( getPageContentFocusType( state ) ).toBe( null );
} );
} );
} );

0 comments on commit 787b0f2

Please sign in to comment.