Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Oct 11, 2024
1 parent c2fc971 commit 21d0043
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/block-editor/src/store/test/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
isDragging,
getBlockStyles,
} from '../private-selectors';
import { getBlockEditingMode } from '../selectors';
import { getBlockEditingMode, __unstableGetEditorMode } from '../selectors';

describe( 'private selectors', () => {
describe( 'isBlockInterfaceHidden', () => {
Expand Down Expand Up @@ -125,11 +125,17 @@ describe( 'private selectors', () => {
};

const hasContentRoleAttribute = jest.fn( () => false );
const get = jest.fn( () => 'edit' );
getBlockEditingMode.registry = {
select: jest.fn( () => ( {
hasContentRoleAttribute,
} ) ),
};
__unstableGetEditorMode.registry = {
select: jest.fn( () => ( {
get,
} ) ),
};

it( 'should return false when top level block is not disabled', () => {
const state = {
Expand Down
15 changes: 13 additions & 2 deletions packages/block-editor/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { RawHTML } from '@wordpress/element';
import { symbol } from '@wordpress/icons';
import { select, dispatch } from '@wordpress/data';
import { store as preferencesStore } from '@wordpress/preferences';

/**
* Internal dependencies
Expand Down Expand Up @@ -4470,7 +4471,6 @@ describe( 'getBlockEditingMode', () => {

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

const fauxPrivateAPIs = {};

lock( fauxPrivateAPIs, { hasContentRoleAttribute } );
lock( fauxPrivateAPIs, {
hasContentRoleAttribute,
} );

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

afterEach( () => {
dispatch( preferencesStore ).set( 'core', 'editorTool', undefined );
} );

it( 'should return default by default', () => {
expect(
getBlockEditingMode(
Expand Down Expand Up @@ -4610,6 +4616,7 @@ describe( 'getBlockEditingMode', () => {
} );

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

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

it( 'in navigation mode, sections are contentOnly', () => {
dispatch( preferencesStore ).set( 'core', 'editorTool', 'navigation' );
expect(
getBlockEditingMode(
navigationModeStateWithRootSection,
Expand All @@ -4643,6 +4652,7 @@ describe( 'getBlockEditingMode', () => {
} );

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

it( 'in navigation mode, blocks without content attributes within sections are disabled', () => {
dispatch( preferencesStore ).set( 'core', 'editorTool', 'navigation' );
expect(
getBlockEditingMode(
navigationModeStateWithRootSection,
Expand Down
2 changes: 2 additions & 0 deletions packages/reusable-blocks/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {

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

/**
* Internal dependencies
Expand All @@ -31,6 +32,7 @@ function createRegistryWithStores() {
registry.register( blockEditorStore );
registry.register( reusableBlocksStore );
registry.register( blocksStore );
registry.register( preferencesStore );

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

0 comments on commit 21d0043

Please sign in to comment.