Skip to content

Commit 064717a

Browse files
committed
test: Update tests to match latest logic
1 parent 3be705a commit 064717a

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/utils/editor-environment.test.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { initializeVideoPressAjaxBridge } from './videopress-bridge.js';
1515
import { configureLocale } from './localization.js';
1616
import { initializeApiFetch } from './api-fetch.js';
1717
import { initializeEditor } from './editor.jsx';
18-
import { unregisterDisallowedBlocks } from './blocks.js';
1918

2019
vi.mock( './bridge.js' );
2120
vi.mock( './logger.js' );
@@ -43,10 +42,6 @@ vi.mock( './editor.jsx', () => ( {
4342
initializeEditor: vi.fn(),
4443
} ) );
4544

46-
vi.mock( './blocks.js', () => ( {
47-
unregisterDisallowedBlocks: vi.fn(),
48-
} ) );
49-
5045
describe( 'setUpEditorEnvironment', () => {
5146
beforeEach( () => {
5247
vi.clearAllMocks();
@@ -105,7 +100,7 @@ describe( 'setUpEditorEnvironment', () => {
105100
] );
106101
} );
107102

108-
it( 'loads plugins and unregisters disallowed blocks when plugins enabled', async () => {
103+
it( 'loads plugins when plugins enabled', async () => {
109104
getGBKit.mockReturnValue( { plugins: true } );
110105

111106
const allowedTypes = [ 'core/paragraph', 'core/heading', 'core/image' ];
@@ -116,9 +111,6 @@ describe( 'setUpEditorEnvironment', () => {
116111
await setUpEditorEnvironment();
117112

118113
expect( loadEditorAssets ).toHaveBeenCalledTimes( 1 );
119-
expect( unregisterDisallowedBlocks ).toHaveBeenCalledWith(
120-
allowedTypes
121-
);
122114
} );
123115

124116
it( 'skips plugin loading when plugins configuration is disabled', async () => {
@@ -127,7 +119,6 @@ describe( 'setUpEditorEnvironment', () => {
127119
await setUpEditorEnvironment();
128120

129121
expect( loadEditorAssets ).not.toHaveBeenCalled();
130-
expect( unregisterDisallowedBlocks ).not.toHaveBeenCalled();
131122
} );
132123

133124
it( 'skips plugin loading when plugins configuration is undefined', async () => {
@@ -136,7 +127,6 @@ describe( 'setUpEditorEnvironment', () => {
136127
await setUpEditorEnvironment();
137128

138129
expect( loadEditorAssets ).not.toHaveBeenCalled();
139-
expect( unregisterDisallowedBlocks ).not.toHaveBeenCalled();
140130
} );
141131

142132
it( 'handles errors during initialization', async () => {
@@ -188,7 +178,9 @@ describe( 'setUpEditorEnvironment', () => {
188178
getGBKit.mockReturnValue( { plugins: true } );
189179

190180
const testError = new Error( 'Plugin loading failed' );
191-
loadEditorAssets.mockRejectedValue( testError );
181+
initializeEditor.mockImplementation( () => {
182+
throw testError;
183+
} );
192184

193185
await setUpEditorEnvironment();
194186

src/utils/editor.test.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import { registerCoreBlocks } from '@wordpress/block-library';
1111
import { initializeEditor } from './editor';
1212
import { getGBKit, getPost } from './bridge';
1313
import { getDefaultEditorSettings } from './editor-settings';
14+
import { unregisterDisallowedBlocks } from './blocks';
1415

1516
vi.mock( '@wordpress/editor', () => ( {
1617
store: { name: 'core/editor' },
1718
} ) );
1819
vi.mock( '@wordpress/data' );
1920
vi.mock( '@wordpress/preferences' );
2021
vi.mock( '@wordpress/block-library' );
22+
vi.mock( './blocks' );
2123
vi.mock( './bridge' );
2224
vi.mock( './editor-settings' );
2325
vi.mock( '../components/layout', () => ( {
@@ -137,6 +139,16 @@ describe( 'initializeEditor', () => {
137139
);
138140
} );
139141

142+
it( 'should pass allowedBlockTypes to unregisterDisallowedBlocks', () => {
143+
const allowedBlockTypes = [ 'core/paragraph', 'core/heading' ];
144+
145+
initializeEditor( { allowedBlockTypes } );
146+
147+
expect( unregisterDisallowedBlocks ).toHaveBeenCalledWith(
148+
allowedBlockTypes
149+
);
150+
} );
151+
140152
it( 'should register core blocks', () => {
141153
initializeEditor();
142154

0 commit comments

Comments
 (0)