Skip to content

Commit 21d0043

Browse files
committed
Fix unit tests
1 parent c2fc971 commit 21d0043

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

packages/block-editor/src/store/test/private-selectors.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
isDragging,
1212
getBlockStyles,
1313
} from '../private-selectors';
14-
import { getBlockEditingMode } from '../selectors';
14+
import { getBlockEditingMode, __unstableGetEditorMode } from '../selectors';
1515

1616
describe( 'private selectors', () => {
1717
describe( 'isBlockInterfaceHidden', () => {
@@ -125,11 +125,17 @@ describe( 'private selectors', () => {
125125
};
126126

127127
const hasContentRoleAttribute = jest.fn( () => false );
128+
const get = jest.fn( () => 'edit' );
128129
getBlockEditingMode.registry = {
129130
select: jest.fn( () => ( {
130131
hasContentRoleAttribute,
131132
} ) ),
132133
};
134+
__unstableGetEditorMode.registry = {
135+
select: jest.fn( () => ( {
136+
get,
137+
} ) ),
138+
};
133139

134140
it( 'should return false when top level block is not disabled', () => {
135141
const state = {

packages/block-editor/src/store/test/selectors.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { RawHTML } from '@wordpress/element';
1010
import { symbol } from '@wordpress/icons';
1111
import { select, dispatch } from '@wordpress/data';
12+
import { store as preferencesStore } from '@wordpress/preferences';
1213

1314
/**
1415
* Internal dependencies
@@ -4470,7 +4471,6 @@ describe( 'getBlockEditingMode', () => {
44704471

44714472
const navigationModeStateWithRootSection = {
44724473
...baseState,
4473-
editorMode: 'navigation',
44744474
settings: {
44754475
[ sectionRootClientIdKey ]: 'ef45d5fd-5234-4fd5-ac4f-c3736c7f9337', // The group is the "main" container
44764476
},
@@ -4480,12 +4480,18 @@ describe( 'getBlockEditingMode', () => {
44804480

44814481
const fauxPrivateAPIs = {};
44824482

4483-
lock( fauxPrivateAPIs, { hasContentRoleAttribute } );
4483+
lock( fauxPrivateAPIs, {
4484+
hasContentRoleAttribute,
4485+
} );
44844486

44854487
getBlockEditingMode.registry = {
44864488
select: jest.fn( () => fauxPrivateAPIs ),
44874489
};
44884490

4491+
afterEach( () => {
4492+
dispatch( preferencesStore ).set( 'core', 'editorTool', undefined );
4493+
} );
4494+
44894495
it( 'should return default by default', () => {
44904496
expect(
44914497
getBlockEditingMode(
@@ -4610,6 +4616,7 @@ describe( 'getBlockEditingMode', () => {
46104616
} );
46114617

46124618
it( 'in navigation mode, the root section container is default', () => {
4619+
dispatch( preferencesStore ).set( 'core', 'editorTool', 'navigation' );
46134620
expect(
46144621
getBlockEditingMode(
46154622
navigationModeStateWithRootSection,
@@ -4619,6 +4626,7 @@ describe( 'getBlockEditingMode', () => {
46194626
} );
46204627

46214628
it( 'in navigation mode, anything outside the section container is disabled', () => {
4629+
dispatch( preferencesStore ).set( 'core', 'editorTool', 'navigation' );
46224630
expect(
46234631
getBlockEditingMode(
46244632
navigationModeStateWithRootSection,
@@ -4628,6 +4636,7 @@ describe( 'getBlockEditingMode', () => {
46284636
} );
46294637

46304638
it( 'in navigation mode, sections are contentOnly', () => {
4639+
dispatch( preferencesStore ).set( 'core', 'editorTool', 'navigation' );
46314640
expect(
46324641
getBlockEditingMode(
46334642
navigationModeStateWithRootSection,
@@ -4643,6 +4652,7 @@ describe( 'getBlockEditingMode', () => {
46434652
} );
46444653

46454654
it( 'in navigation mode, blocks with content attributes within sections are contentOnly', () => {
4655+
dispatch( preferencesStore ).set( 'core', 'editorTool', 'navigation' );
46464656
hasContentRoleAttribute.mockReturnValueOnce( true );
46474657
expect(
46484658
getBlockEditingMode(
@@ -4661,6 +4671,7 @@ describe( 'getBlockEditingMode', () => {
46614671
} );
46624672

46634673
it( 'in navigation mode, blocks without content attributes within sections are disabled', () => {
4674+
dispatch( preferencesStore ).set( 'core', 'editorTool', 'navigation' );
46644675
expect(
46654676
getBlockEditingMode(
46664677
navigationModeStateWithRootSection,

packages/reusable-blocks/src/store/test/actions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212

1313
import { store as coreStore } from '@wordpress/core-data';
1414
import apiFetch from '@wordpress/api-fetch';
15+
import { store as preferencesStore } from '@wordpress/preferences';
1516

1617
/**
1718
* Internal dependencies
@@ -31,6 +32,7 @@ function createRegistryWithStores() {
3132
registry.register( blockEditorStore );
3233
registry.register( reusableBlocksStore );
3334
registry.register( blocksStore );
35+
registry.register( preferencesStore );
3436

3537
// Register entity here instead of mocking API handlers for loadPostTypeEntities()
3638
registry.dispatch( coreStore ).addEntities( [

0 commit comments

Comments
 (0)