Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Nov 21, 2024
1 parent 3d7eb2e commit 63d0d2f
Showing 1 changed file with 197 additions and 1 deletion.
198 changes: 197 additions & 1 deletion packages/block-editor/src/store/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3655,7 +3655,7 @@ describe( 'state', () => {
select.mockRestore();
} );

it( 'returns the no block editing modes when zoomed out / navigation mode are not active and there are no synced patterns', () => {
it( 'returns no block editing modes when zoomed out / navigation mode are not active and there are no synced patterns', () => {
expect( initialState.derivedBlockEditingModes ).toEqual(
new Map()
);
Expand Down Expand Up @@ -4016,6 +4016,104 @@ describe( 'state', () => {
);
} );

it( 'removes block editing modes when blocks are removed', () => {
const { derivedBlockEditingModes } = dispatchActions(
[
{
type: 'REMOVE_BLOCKS',
clientIds: [ 'group-2' ],
},
],
testReducer,
initialState
);

expect( derivedBlockEditingModes ).toEqual(
new Map(
Object.entries( {
'': 'contentOnly',
'group-1': 'contentOnly',
'paragraph-1': 'contentOnly',
} )
)
);
} );

it( 'updates block editing modes when new blocks are inserted', () => {
const { derivedBlockEditingModes } = dispatchActions(
[
{
type: 'INSERT_BLOCKS',
rootClientId: '',
blocks: [
{
name: 'core/group',
clientId: 'group-3',
attributes: {},
innerBlocks: [
{
name: 'core/paragraph',
clientId: 'paragraph-3',
attributes: {},
innerBlocks: [],
},
{
name: 'core/group',
clientId: 'group-4',
attributes: {},
innerBlocks: [],
},
],
},
],
},
],
testReducer,
initialState
);

expect( derivedBlockEditingModes ).toEqual(
new Map(
Object.entries( {
'': 'contentOnly', // Section root.
'group-1': 'contentOnly', // Section block.
'paragraph-1': 'contentOnly', // Content block in section.
'group-2': 'disabled', // Non-content block in section.
'paragraph-2': 'contentOnly', // Content block in section.
'group-3': 'contentOnly', // New section block.
'paragraph-3': 'contentOnly', // New content block in section.
'group-4': 'disabled', // Non-content block in section.
} )
)
);
} );

it( 'updates block editing modes when blocks are moved to a new position', () => {
const { derivedBlockEditingModes } = dispatchActions(
[
{
type: 'MOVE_BLOCKS_TO_POSITION',
clientIds: [ 'group-2' ],
fromRootClientId: 'group-1',
toRootClientId: '',
},
],
testReducer,
initialState
);
expect( derivedBlockEditingModes ).toEqual(
new Map(
Object.entries( {
'': 'contentOnly', // Section root.
'group-1': 'contentOnly', // Section block.
'paragraph-1': 'contentOnly', // Content block in section.
'group-2': 'contentOnly', // New section block.
'paragraph-2': 'contentOnly', // Still a content block in a section.
} )
)
);
} );

it( 'handles changes to the section root', () => {
const { derivedBlockEditingModes } = dispatchActions(
[
Expand Down Expand Up @@ -4153,6 +4251,104 @@ describe( 'state', () => {
} );
} );

it( 'removes block editing modes when blocks are removed', () => {
const { derivedBlockEditingModes } = dispatchActions(
[
{
type: 'REMOVE_BLOCKS',
clientIds: [ 'group-2' ],
},
],
testReducer,
initialState
);

expect( derivedBlockEditingModes ).toEqual(
new Map(
Object.entries( {
'': 'contentOnly',
'group-1': 'contentOnly',
'paragraph-1': 'disabled',
} )
)
);
} );

it( 'updates block editing modes when new blocks are inserted', () => {
const { derivedBlockEditingModes } = dispatchActions(
[
{
type: 'INSERT_BLOCKS',
rootClientId: '',
blocks: [
{
name: 'core/group',
clientId: 'group-3',
attributes: {},
innerBlocks: [
{
name: 'core/paragraph',
clientId: 'paragraph-3',
attributes: {},
innerBlocks: [],
},
{
name: 'core/group',
clientId: 'group-4',
attributes: {},
innerBlocks: [],
},
],
},
],
},
],
testReducer,
initialState
);

expect( derivedBlockEditingModes ).toEqual(
new Map(
Object.entries( {
'': 'contentOnly', // Section root.
'group-1': 'contentOnly', // Section block.
'paragraph-1': 'disabled',
'group-2': 'disabled',
'paragraph-2': 'disabled',
'group-3': 'contentOnly', // New section block.
'paragraph-3': 'disabled',
'group-4': 'disabled',
} )
)
);
} );

it( 'updates block editing modes when blocks are moved to a new position', () => {
const { derivedBlockEditingModes } = dispatchActions(
[
{
type: 'MOVE_BLOCKS_TO_POSITION',
clientIds: [ 'group-2' ],
fromRootClientId: 'group-1',
toRootClientId: '',
},
],
testReducer,
initialState
);
expect( derivedBlockEditingModes ).toEqual(
new Map(
Object.entries( {
'': 'contentOnly', // Section root.
'group-1': 'contentOnly', // Section block.
'paragraph-1': 'disabled',
'group-2': 'contentOnly', // New section block.
'paragraph-2': 'disabled',
} )
)
);
} );

it( 'handles changes to the section root', () => {
const { derivedBlockEditingModes } = dispatchActions(
[
Expand Down

0 comments on commit 63d0d2f

Please sign in to comment.