Skip to content

Commit b32a8a5

Browse files
committed
Block editor: Isolate mutable test fixtures
1 parent b40716d commit b32a8a5

5 files changed

Lines changed: 91 additions & 75 deletions

File tree

‎packages/block-editor/src/hooks/test/custom-class-name.jsdom.test.jsx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { applyFilters } from '@wordpress/hooks';
33
import customClassName from '../custom-class-name';
44

55
describe( 'custom className', () => {
6-
const blockSettings = {
6+
const getBlockSettings = () => ( {
77
save: () => <div className="default" />,
88
category: 'text',
99
title: 'block title',
10-
};
10+
} );
1111

1212
describe( 'addAttribute()', () => {
1313
const addAttribute = applyFilters.bind(
@@ -17,7 +17,7 @@ describe( 'custom className', () => {
1717

1818
it( 'should do nothing if the block settings disable custom className support', () => {
1919
const settings = addAttribute( {
20-
...blockSettings,
20+
...getBlockSettings(),
2121
supports: {
2222
customClassName: false,
2323
},
@@ -27,7 +27,7 @@ describe( 'custom className', () => {
2727
} );
2828

2929
it( 'should assign a new custom className attribute', () => {
30-
const settings = addAttribute( blockSettings );
30+
const settings = addAttribute( getBlockSettings() );
3131

3232
expect( settings.attributes ).toHaveProperty( 'className' );
3333
} );
@@ -39,7 +39,7 @@ describe( 'custom className', () => {
3939
const extraProps = customClassName.addSaveProps(
4040
{},
4141
{
42-
...blockSettings,
42+
...getBlockSettings(),
4343
supports: {
4444
customClassName: false,
4545
},
@@ -54,7 +54,7 @@ describe( 'custom className', () => {
5454
const attributes = { className: 'bar' };
5555
const extraProps = customClassName.addSaveProps(
5656
{ className: 'foo' },
57-
blockSettings,
57+
getBlockSettings(),
5858
attributes
5959
);
6060

‎packages/block-editor/src/hooks/test/style.jsdom.test.jsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,14 @@ describe( 'addSaveProps', () => {
578578
};
579579

580580
const applySkipSerialization = ( features ) => {
581-
const updatedSettings = { ...blockSettings };
581+
const updatedSettings = {
582+
...blockSettings,
583+
supports: {
584+
spacing: { ...blockSettings.supports.spacing },
585+
color: { ...blockSettings.supports.color },
586+
typography: { ...blockSettings.supports.typography },
587+
},
588+
};
582589
Object.keys( features ).forEach( ( key ) => {
583590
updatedSettings.supports[ key ].__experimentalSkipSerialization =
584591
features[ key ];

‎packages/block-editor/src/store/test/performance.js‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it } from 'vitest';
1+
import { beforeAll, describe, expect, it } from 'vitest';
22
import reducer from '../reducer';
33

44
describe( 'performance', () => {
@@ -13,13 +13,19 @@ describe( 'performance', () => {
1313
}
1414

1515
let preparedState;
16+
beforeAll( () => {
17+
preparedState = reducer( state, {
18+
type: 'RESET_BLOCKS',
19+
blocks,
20+
} );
21+
}, 60_000 );
1622

1723
it( 'should reset blocks', () => {
18-
preparedState = reducer( state, {
24+
const updatedState = reducer( state, {
1925
type: 'RESET_BLOCKS',
2026
blocks,
2127
} );
22-
expect( preparedState ).toBeDefined();
28+
expect( updatedState ).toBeDefined();
2329
}, 60_000 );
2430

2531
it( 'should update blocks', () => {

‎packages/block-editor/src/store/test/reducer.js‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4260,7 +4260,7 @@ describe( 'state', () => {
42604260

42614261
describe( 'edit mode', () => {
42624262
let initialState;
4263-
beforeAll( () => {
4263+
beforeEach( () => {
42644264
initialState = dispatchActions(
42654265
[
42664266
{
@@ -4314,7 +4314,7 @@ describe( 'state', () => {
43144314

43154315
describe( 'synced patterns', () => {
43164316
let initialState;
4317-
beforeAll( () => {
4317+
beforeEach( () => {
43184318
// Simulates how the editor typically inserts controlled blocks,
43194319
// - first the pattern is inserted with no inner blocks.
43204320
// - next the pattern is marked as a controlled block.
@@ -4879,7 +4879,7 @@ describe( 'state', () => {
48794879

48804880
describe( 'contentOnly template locking', () => {
48814881
let initialState;
4882-
beforeAll( () => {
4882+
beforeEach( () => {
48834883
initialState = dispatchActions(
48844884
[
48854885
{
@@ -5137,7 +5137,7 @@ describe( 'state', () => {
51375137
describe( 'zoom out mode', () => {
51385138
let initialState;
51395139

5140-
beforeAll( () => {
5140+
beforeEach( () => {
51415141
initialState = dispatchActions(
51425142
[
51435143
{
@@ -5328,7 +5328,7 @@ describe( 'state', () => {
53285328

53295329
describe( 'unsynced patterns', () => {
53305330
let initialState;
5331-
beforeAll( () => {
5331+
beforeEach( () => {
53325332
initialState = dispatchActions(
53335333
[
53345334
{
@@ -5490,7 +5490,7 @@ describe( 'state', () => {
54905490

54915491
describe( 'unsynced patterns with disableContentOnlyForUnsyncedPatterns enabled', () => {
54925492
let initialState;
5493-
beforeAll( () => {
5493+
beforeEach( () => {
54945494
initialState = dispatchActions(
54955495
[
54965496
{
@@ -5598,7 +5598,7 @@ describe( 'state', () => {
55985598

55995599
describe( 'isIsolatedEditor setting', () => {
56005600
let stateWithUnsyncedPatternAndTemplatePart;
5601-
beforeAll( () => {
5601+
beforeEach( () => {
56025602
// Set up a state with both an unsynced pattern and a template part.
56035603
stateWithUnsyncedPatternAndTemplatePart = dispatchActions(
56045604
[
@@ -5768,7 +5768,7 @@ describe( 'state', () => {
57685768

57695769
describe( 'template parts', () => {
57705770
let initialState;
5771-
beforeAll( () => {
5771+
beforeEach( () => {
57725772
// Simulates how the editor typically inserts controlled blocks,
57735773
// - first the template part is inserted with no inner blocks.
57745774
// - next the template part is marked as a controlled block.
@@ -5882,7 +5882,7 @@ describe( 'state', () => {
58825882

58835883
describe( 'template parts with disableContentOnlyForTemplateParts enabled', () => {
58845884
let initialState;
5885-
beforeAll( () => {
5885+
beforeEach( () => {
58865886
initialState = dispatchActions(
58875887
[
58885888
{

‎packages/block-editor/src/store/test/selectors.jsdom.test.jsx‎

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4658,64 +4658,67 @@ describe( 'selectors', () => {
46584658
} );
46594659

46604660
describe( 'getActiveBlockIdByBlockName', () => {
4661-
const state = {
4662-
selection: {
4663-
selectionStart: {
4664-
clientId: 'client-id-04',
4665-
},
4666-
selectionEnd: {
4667-
clientId: 'client-id-04',
4661+
let state;
4662+
beforeEach( () => {
4663+
state = {
4664+
selection: {
4665+
selectionStart: {
4666+
clientId: 'client-id-04',
4667+
},
4668+
selectionEnd: {
4669+
clientId: 'client-id-04',
4670+
},
46684671
},
4669-
},
4670-
blocks: {
4671-
parents: new Map(
4672-
Object.entries( {
4673-
'client-id-01': '',
4674-
'client-id-02': 'client-id-01',
4675-
'client-id-03': 'client-id-02',
4676-
'client-id-04': 'client-id-03',
4677-
'client-id-05': 'client-id-03',
4678-
} )
4679-
),
4680-
byClientId: new Map(
4681-
Object.entries( {
4682-
'client-id-01': {
4683-
clientId: 'client-id-01',
4684-
name: 'core/columns',
4685-
},
4686-
'client-id-02': {
4687-
clientId: 'client-id-02',
4688-
name: 'core/navigation',
4689-
},
4690-
'client-id-03': {
4691-
clientId: 'client-id-03',
4692-
name: 'core/navigation-link',
4693-
},
4694-
'client-id-04': {
4695-
clientId: 'client-id-04',
4696-
name: 'core/navigation-link',
4697-
},
4698-
'client-id-05': {
4699-
clientId: 'client-id-05',
4700-
name: 'core/navigation-link',
4701-
},
4702-
} )
4703-
),
4704-
cache: {
4705-
'client-id-01': {},
4706-
'client-id-02': {},
4707-
'client-id-03': {},
4708-
'client-id-04': {},
4709-
'client-id-05': {},
4672+
blocks: {
4673+
parents: new Map(
4674+
Object.entries( {
4675+
'client-id-01': '',
4676+
'client-id-02': 'client-id-01',
4677+
'client-id-03': 'client-id-02',
4678+
'client-id-04': 'client-id-03',
4679+
'client-id-05': 'client-id-03',
4680+
} )
4681+
),
4682+
byClientId: new Map(
4683+
Object.entries( {
4684+
'client-id-01': {
4685+
clientId: 'client-id-01',
4686+
name: 'core/columns',
4687+
},
4688+
'client-id-02': {
4689+
clientId: 'client-id-02',
4690+
name: 'core/navigation',
4691+
},
4692+
'client-id-03': {
4693+
clientId: 'client-id-03',
4694+
name: 'core/navigation-link',
4695+
},
4696+
'client-id-04': {
4697+
clientId: 'client-id-04',
4698+
name: 'core/navigation-link',
4699+
},
4700+
'client-id-05': {
4701+
clientId: 'client-id-05',
4702+
name: 'core/navigation-link',
4703+
},
4704+
} )
4705+
),
4706+
cache: {
4707+
'client-id-01': {},
4708+
'client-id-02': {},
4709+
'client-id-03': {},
4710+
'client-id-04': {},
4711+
'client-id-05': {},
4712+
},
4713+
order: new Map(
4714+
Object.entries( {
4715+
'client-id-03': [ 'client-id-04', 'client-id-05' ],
4716+
} )
4717+
),
4718+
controlledInnerBlocks: new Set(),
47104719
},
4711-
order: new Map(
4712-
Object.entries( {
4713-
'client-id-03': [ 'client-id-04', 'client-id-05' ],
4714-
} )
4715-
),
4716-
controlledInnerBlocks: new Set(),
4717-
},
4718-
};
4720+
};
4721+
} );
47194722
it( 'Should return first active matching block (including self) when single block selected', () => {
47204723
expect(
47214724
getActiveBlockIdByBlockNames( state, [

0 commit comments

Comments
 (0)