Skip to content

Commit a68183c

Browse files
committed
Block editor: Isolate mutable test fixtures
1 parent f4ef42d commit a68183c

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
@@ -4254,7 +4254,7 @@ describe( 'state', () => {
42544254

42554255
describe( 'edit mode', () => {
42564256
let initialState;
4257-
beforeAll( () => {
4257+
beforeEach( () => {
42584258
initialState = dispatchActions(
42594259
[
42604260
{
@@ -4308,7 +4308,7 @@ describe( 'state', () => {
43084308

43094309
describe( 'synced patterns', () => {
43104310
let initialState;
4311-
beforeAll( () => {
4311+
beforeEach( () => {
43124312
// Simulates how the editor typically inserts controlled blocks,
43134313
// - first the pattern is inserted with no inner blocks.
43144314
// - next the pattern is marked as a controlled block.
@@ -4873,7 +4873,7 @@ describe( 'state', () => {
48734873

48744874
describe( 'contentOnly template locking', () => {
48754875
let initialState;
4876-
beforeAll( () => {
4876+
beforeEach( () => {
48774877
initialState = dispatchActions(
48784878
[
48794879
{
@@ -5131,7 +5131,7 @@ describe( 'state', () => {
51315131
describe( 'zoom out mode', () => {
51325132
let initialState;
51335133

5134-
beforeAll( () => {
5134+
beforeEach( () => {
51355135
initialState = dispatchActions(
51365136
[
51375137
{
@@ -5322,7 +5322,7 @@ describe( 'state', () => {
53225322

53235323
describe( 'unsynced patterns', () => {
53245324
let initialState;
5325-
beforeAll( () => {
5325+
beforeEach( () => {
53265326
initialState = dispatchActions(
53275327
[
53285328
{
@@ -5484,7 +5484,7 @@ describe( 'state', () => {
54845484

54855485
describe( 'unsynced patterns with disableContentOnlyForUnsyncedPatterns enabled', () => {
54865486
let initialState;
5487-
beforeAll( () => {
5487+
beforeEach( () => {
54885488
initialState = dispatchActions(
54895489
[
54905490
{
@@ -5592,7 +5592,7 @@ describe( 'state', () => {
55925592

55935593
describe( 'isIsolatedEditor setting', () => {
55945594
let stateWithUnsyncedPatternAndTemplatePart;
5595-
beforeAll( () => {
5595+
beforeEach( () => {
55965596
// Set up a state with both an unsynced pattern and a template part.
55975597
stateWithUnsyncedPatternAndTemplatePart = dispatchActions(
55985598
[
@@ -5762,7 +5762,7 @@ describe( 'state', () => {
57625762

57635763
describe( 'template parts', () => {
57645764
let initialState;
5765-
beforeAll( () => {
5765+
beforeEach( () => {
57665766
// Simulates how the editor typically inserts controlled blocks,
57675767
// - first the template part is inserted with no inner blocks.
57685768
// - next the template part is marked as a controlled block.
@@ -5876,7 +5876,7 @@ describe( 'state', () => {
58765876

58775877
describe( 'template parts with disableContentOnlyForTemplateParts enabled', () => {
58785878
let initialState;
5879-
beforeAll( () => {
5879+
beforeEach( () => {
58805880
initialState = dispatchActions(
58815881
[
58825882
{

‎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)