-
Notifications
You must be signed in to change notification settings - Fork 4k
/
container-blocks.test.js
130 lines (112 loc) · 3.82 KB
/
container-blocks.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* WordPress dependencies
*/
import {
activatePlugin,
createNewPost,
deactivatePlugin,
getEditedPostContent,
insertBlock,
switchEditorModeTo,
pressKeyWithModifier,
canvas,
} from '@wordpress/e2e-test-utils';
describe( 'InnerBlocks Template Sync', () => {
beforeAll( async () => {
await activatePlugin( 'gutenberg-test-innerblocks-templates' );
} );
beforeEach( async () => {
await createNewPost();
} );
afterAll( async () => {
await deactivatePlugin( 'gutenberg-test-innerblocks-templates' );
} );
const insertBlockAndAddParagraphInside = async ( blockName, blockSlug ) => {
const paragraphToAdd = `
<!-- wp:paragraph -->
<p>added paragraph</p>
<!-- /wp:paragraph -->
`;
await insertBlock( blockName );
await switchEditorModeTo( 'Code' );
await page.$eval(
'.editor-post-text-editor',
( element, _paragraph, _blockSlug ) => {
const blockDelimiter = `<!-- /wp:${ _blockSlug } -->`;
element.value = element.value.replace(
blockDelimiter,
`${ _paragraph }${ blockDelimiter }`
);
},
paragraphToAdd,
blockSlug
);
// Press "Enter" inside the code editor to fire the `onChange` event for the new value.
await page.click( '.editor-post-text-editor' );
await pressKeyWithModifier( 'primary', 'A' );
await page.keyboard.press( 'ArrowRight' );
await page.keyboard.press( 'Enter' );
await switchEditorModeTo( 'Visual' );
};
it( 'Ensures blocks without locking are kept intact even if they do not match the template', async () => {
await insertBlockAndAddParagraphInside(
'Test Inner Blocks no locking',
'test/test-inner-blocks-no-locking'
);
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'Removes blocks that are not expected by the template if a lock all exists', async () => {
await insertBlockAndAddParagraphInside(
'Test InnerBlocks locking all',
'test/test-inner-blocks-locking-all'
);
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
// Test for regressions of https://github.com/WordPress/gutenberg/issues/27897.
it( `Synchronizes blocks if lock 'all' is set and the template prop is changed`, async () => {
// Insert the template and assert that the template has its initial value.
await insertBlock( 'Test Inner Blocks update locked template' );
expect( await getEditedPostContent() ).toMatchSnapshot();
// Trigger a template update and assert that a second block is now present.
const [ button ] = await canvas().$x(
`//button[contains(text(), 'Update template')]`
);
await button.click();
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'Ensure inner block writing flow works as expected without additional paragraphs added', async () => {
const TEST_BLOCK_NAME = 'Test Inner Blocks Paragraph Placeholder';
await insertBlock( TEST_BLOCK_NAME );
await page.keyboard.type( 'Test Paragraph' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );
describe( 'Container block without paragraph support', () => {
beforeAll( async () => {
await activatePlugin(
'gutenberg-test-container-block-without-paragraph'
);
} );
beforeEach( async () => {
await createNewPost();
} );
afterAll( async () => {
await deactivatePlugin(
'gutenberg-test-container-block-without-paragraph'
);
} );
it( 'ensures we can use the alternative block appender properly', async () => {
await insertBlock( 'Container without paragraph' );
// Open the specific appender used when there's no paragraph support.
await page.click(
'.block-editor-inner-blocks .block-list-appender .block-list-appender__toggle'
);
// Insert an image block.
const insertButton = (
await page.$x( `//button//span[contains(text(), 'Image')]` )
)[ 0 ];
await insertButton.click();
// Check the inserted content.
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );