@wordpress/e2e-tests 4.3.0 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/flaky-tests-reporter.js +3 -3
- package/package.json +6 -6
- package/specs/editor/blocks/cover.test.js +10 -14
- package/specs/editor/blocks/heading.test.js +1 -5
- package/specs/editor/blocks/navigation.test.js +72 -23
- package/specs/editor/plugins/cpt-locking.test.js +2 -3
- package/specs/editor/plugins/iframed-block.test.js +3 -2
- package/specs/editor/plugins/iframed-inline-styles.test.js +1 -0
- package/specs/editor/plugins/iframed-masonry-block.test.js +3 -2
- package/specs/editor/plugins/inner-blocks-allowed-blocks.test.js +3 -1
- package/specs/editor/various/__snapshots__/inserting-blocks.test.js.snap +1 -1
- package/specs/editor/various/datepicker.test.js +30 -18
- package/specs/editor/various/embedding.test.js +2 -4
- package/specs/editor/various/links.test.js +2 -3
- package/specs/editor/various/navigable-toolbar.test.js +2 -3
- package/specs/editor/various/post-visibility.test.js +1 -1
- package/specs/editor/various/publishing.test.js +4 -2
- package/specs/editor/various/scheduling.test.js +2 -2
- package/specs/editor/various/sidebar.test.js +4 -6
- package/specs/editor/various/switch-to-draft.test.js +1 -1
- package/specs/editor/various/taxonomies.test.js +8 -7
- package/specs/editor/various/writing-flow.test.js +19 -0
- package/specs/experiments/navigation-editor.test.js +4 -6
- package/specs/performance/post-editor.test.js +10 -14
- package/specs/performance/site-editor.test.js +2 -5
- package/specs/widgets/editing-widgets.test.js +12 -8
- package/specs/editor/blocks/__snapshots__/buttons.test.js.snap +0 -33
- package/specs/editor/blocks/__snapshots__/code.test.js.snap +0 -14
- package/specs/editor/blocks/__snapshots__/html.test.js.snap +0 -8
- package/specs/editor/blocks/__snapshots__/preformatted.test.js.snap +0 -24
- package/specs/editor/blocks/__snapshots__/separator.test.js.snap +0 -7
- package/specs/editor/blocks/__snapshots__/spacer.test.js.snap +0 -13
- package/specs/editor/blocks/__snapshots__/table.test.js.snap +0 -61
- package/specs/editor/blocks/buttons.test.js +0 -95
- package/specs/editor/blocks/code.test.js +0 -48
- package/specs/editor/blocks/html.test.js +0 -31
- package/specs/editor/blocks/preformatted.test.js +0 -62
- package/specs/editor/blocks/separator.test.js +0 -22
- package/specs/editor/blocks/spacer.test.js +0 -48
- package/specs/editor/blocks/table.test.js +0 -296
- package/specs/editor/various/__snapshots__/rtl.test.js.snap +0 -63
- package/specs/editor/various/preview.test.js +0 -425
- package/specs/editor/various/rtl.test.js +0 -129
- package/specs/site-editor/style-variations.test.js +0 -213
- package/specs/site-editor/template-part.test.js +0 -346
- package/specs/site-editor/template-revert.test.js +0 -209
- package/themes/style-variations/block-templates/index.html +0 -11
- package/themes/style-variations/index.php +0 -0
- package/themes/style-variations/style.css +0 -15
- package/themes/style-variations/styles/pink.json +0 -33
- package/themes/style-variations/styles/yellow.json +0 -12
- package/themes/style-variations/theme.json +0 -8
@@ -1,213 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* WordPress dependencies
|
3
|
-
*/
|
4
|
-
import {
|
5
|
-
trashAllPosts,
|
6
|
-
activateTheme,
|
7
|
-
visitSiteEditor,
|
8
|
-
toggleGlobalStyles,
|
9
|
-
openGlobalStylesPanel,
|
10
|
-
openPreviousGlobalStylesPanel,
|
11
|
-
} from '@wordpress/e2e-test-utils';
|
12
|
-
|
13
|
-
async function openOtherStyles() {
|
14
|
-
const OTHER_STYLES_SELECTOR = '//div[contains(text(),"Browse styles")]';
|
15
|
-
await ( await page.waitForXPath( OTHER_STYLES_SELECTOR ) ).click();
|
16
|
-
}
|
17
|
-
|
18
|
-
async function getAvailableStyleVariations() {
|
19
|
-
const VARIATION_ITEMS_STYLES_SELECTOR =
|
20
|
-
'.edit-site-global-styles-variations_item';
|
21
|
-
await page.waitForSelector( VARIATION_ITEMS_STYLES_SELECTOR );
|
22
|
-
return page.$$( VARIATION_ITEMS_STYLES_SELECTOR );
|
23
|
-
}
|
24
|
-
|
25
|
-
async function applyVariation( label ) {
|
26
|
-
await toggleGlobalStyles();
|
27
|
-
await openOtherStyles();
|
28
|
-
const variation = await page.waitForXPath(
|
29
|
-
`//*[@role="button"][@aria-label="${ label }"]`
|
30
|
-
);
|
31
|
-
await variation.click();
|
32
|
-
}
|
33
|
-
|
34
|
-
async function applyPinkVariation() {
|
35
|
-
await applyVariation( 'pink' );
|
36
|
-
}
|
37
|
-
|
38
|
-
async function applyYellowVariation() {
|
39
|
-
await applyVariation( 'yellow' );
|
40
|
-
}
|
41
|
-
|
42
|
-
async function openColorsPanel() {
|
43
|
-
await openGlobalStylesPanel( 'Colors' );
|
44
|
-
}
|
45
|
-
|
46
|
-
async function openTypographyPanel() {
|
47
|
-
await openGlobalStylesPanel( 'Typography' );
|
48
|
-
}
|
49
|
-
|
50
|
-
async function openTextPanel() {
|
51
|
-
await openGlobalStylesPanel( 'Text' );
|
52
|
-
}
|
53
|
-
|
54
|
-
async function openPalettePanel() {
|
55
|
-
const selector = `//div[./h2[text()="Palette"]]//button`;
|
56
|
-
await ( await page.waitForXPath( selector ) ).click();
|
57
|
-
}
|
58
|
-
|
59
|
-
async function getFontSizeHint() {
|
60
|
-
const element = await page.$(
|
61
|
-
'.components-font-size-picker__header__hint'
|
62
|
-
);
|
63
|
-
return element.evaluate( ( el ) => el.textContent );
|
64
|
-
}
|
65
|
-
|
66
|
-
async function getCustomFontSizeValue() {
|
67
|
-
const element = await page.$(
|
68
|
-
'.components-font-size-picker input[aria-label="Custom"]'
|
69
|
-
);
|
70
|
-
return element.evaluate( ( el ) => el.value );
|
71
|
-
}
|
72
|
-
|
73
|
-
async function getColorValue( colorType ) {
|
74
|
-
return page.evaluate( ( _colorType ) => {
|
75
|
-
return document.evaluate(
|
76
|
-
`substring-before(substring-after(//div[contains(@class, "edit-site-global-styles-sidebar__panel")]//button[.//*[text()="${ _colorType }"]]//*[contains(@class,"component-color-indicator")]/@style, "background: "), ";")`,
|
77
|
-
document,
|
78
|
-
null,
|
79
|
-
XPathResult.ANY_TYPE,
|
80
|
-
null
|
81
|
-
).stringValue;
|
82
|
-
}, colorType );
|
83
|
-
}
|
84
|
-
|
85
|
-
async function getBackgroundColorValue() {
|
86
|
-
return getColorValue( 'Background' );
|
87
|
-
}
|
88
|
-
|
89
|
-
async function getTextColorValue() {
|
90
|
-
return getColorValue( 'Text' );
|
91
|
-
}
|
92
|
-
|
93
|
-
async function getColorPalette( paletteSource ) {
|
94
|
-
const paletteOptions = await page.$x(
|
95
|
-
`//div[./*/h2[text()="${ paletteSource }"]]//button[contains(@class,"components-circular-option-picker__option")]`
|
96
|
-
);
|
97
|
-
return Promise.all(
|
98
|
-
paletteOptions.map( ( element ) => {
|
99
|
-
return element.evaluate( ( el ) => {
|
100
|
-
const color = el.style.backgroundColor;
|
101
|
-
const name = el
|
102
|
-
.getAttribute( 'aria-label' )
|
103
|
-
.substring( 'Color: '.length );
|
104
|
-
return { color, name };
|
105
|
-
} );
|
106
|
-
} )
|
107
|
-
);
|
108
|
-
}
|
109
|
-
|
110
|
-
async function getThemePalette() {
|
111
|
-
return getColorPalette( 'Theme' );
|
112
|
-
}
|
113
|
-
|
114
|
-
describe( 'Global styles variations', () => {
|
115
|
-
beforeAll( async () => {
|
116
|
-
await activateTheme( 'gutenberg-test-themes/style-variations' );
|
117
|
-
await trashAllPosts( 'wp_template' );
|
118
|
-
await trashAllPosts( 'wp_template_part' );
|
119
|
-
} );
|
120
|
-
afterAll( async () => {
|
121
|
-
await activateTheme( 'twentytwentyone' );
|
122
|
-
} );
|
123
|
-
beforeEach( async () => {
|
124
|
-
await visitSiteEditor();
|
125
|
-
} );
|
126
|
-
|
127
|
-
it( 'Should have three variations available with the first one being active', async () => {
|
128
|
-
await toggleGlobalStyles();
|
129
|
-
await openOtherStyles();
|
130
|
-
const variations = await getAvailableStyleVariations();
|
131
|
-
expect( variations ).toHaveLength( 3 );
|
132
|
-
expect(
|
133
|
-
await (
|
134
|
-
await variations[ 0 ].getProperty( 'className' )
|
135
|
-
).jsonValue()
|
136
|
-
).toContain( 'is-active' );
|
137
|
-
expect(
|
138
|
-
await (
|
139
|
-
await variations[ 1 ].getProperty( 'className' )
|
140
|
-
).jsonValue()
|
141
|
-
).not.toContain( 'is-active' );
|
142
|
-
expect(
|
143
|
-
await (
|
144
|
-
await variations[ 2 ].getProperty( 'className' )
|
145
|
-
).jsonValue()
|
146
|
-
).not.toContain( 'is-active' );
|
147
|
-
} );
|
148
|
-
|
149
|
-
it( 'Should apply preset colors and font sizes in a variation', async () => {
|
150
|
-
await applyPinkVariation();
|
151
|
-
await openPreviousGlobalStylesPanel();
|
152
|
-
await openColorsPanel();
|
153
|
-
expect( await getBackgroundColorValue() ).toBe( 'rgb(202, 105, 211)' );
|
154
|
-
expect( await getTextColorValue() ).toBe( 'rgb(74, 7, 74)' );
|
155
|
-
await openPreviousGlobalStylesPanel();
|
156
|
-
await openTypographyPanel();
|
157
|
-
await openTextPanel();
|
158
|
-
expect( await getFontSizeHint() ).toBe( 'Medium(px)' );
|
159
|
-
} );
|
160
|
-
|
161
|
-
it( 'Should apply custom colors and font sizes in a variation', async () => {
|
162
|
-
await applyYellowVariation();
|
163
|
-
await openPreviousGlobalStylesPanel();
|
164
|
-
await openColorsPanel();
|
165
|
-
expect( await getBackgroundColorValue() ).toBe( 'rgb(255, 239, 11)' );
|
166
|
-
expect( await getTextColorValue() ).toBe( 'rgb(25, 25, 17)' );
|
167
|
-
await openPreviousGlobalStylesPanel();
|
168
|
-
await openTypographyPanel();
|
169
|
-
await openTextPanel();
|
170
|
-
expect( await getFontSizeHint() ).toBe( '(Custom)' );
|
171
|
-
expect( await getCustomFontSizeValue() ).toBe( '15' );
|
172
|
-
} );
|
173
|
-
|
174
|
-
it( 'Should apply a color palette in a variation', async () => {
|
175
|
-
await applyPinkVariation();
|
176
|
-
await openPreviousGlobalStylesPanel();
|
177
|
-
await openColorsPanel();
|
178
|
-
await openPalettePanel();
|
179
|
-
expect( await getThemePalette() ).toMatchObject( [
|
180
|
-
{
|
181
|
-
color: 'rgb(74, 7, 74)',
|
182
|
-
name: 'Foreground',
|
183
|
-
},
|
184
|
-
{
|
185
|
-
color: 'rgb(202, 105, 211)',
|
186
|
-
name: 'Background',
|
187
|
-
},
|
188
|
-
{
|
189
|
-
color: 'rgba(204, 0, 255, 0.77)',
|
190
|
-
name: 'Awesome pink',
|
191
|
-
},
|
192
|
-
] );
|
193
|
-
} );
|
194
|
-
|
195
|
-
it( 'Should reflect style variations in the styles applied to the editor', async () => {
|
196
|
-
await applyYellowVariation();
|
197
|
-
const frame = await (
|
198
|
-
await page.waitForSelector( '.edit-site-visual-editor iframe' )
|
199
|
-
).contentFrame();
|
200
|
-
const paragraph = await frame.waitForXPath(
|
201
|
-
`//p[text()="My awesome paragraph"]`
|
202
|
-
);
|
203
|
-
const paragraphColor = await paragraph.evaluate( ( el ) => {
|
204
|
-
return window.getComputedStyle( el ).color;
|
205
|
-
} );
|
206
|
-
expect( paragraphColor ).toBe( 'rgb(25, 25, 17)' );
|
207
|
-
const body = await frame.$( 'body' );
|
208
|
-
const backgroundColor = await body.evaluate( ( el ) => {
|
209
|
-
return window.getComputedStyle( el ).backgroundColor;
|
210
|
-
} );
|
211
|
-
expect( backgroundColor ).toBe( 'rgb(255, 239, 11)' );
|
212
|
-
} );
|
213
|
-
} );
|
@@ -1,346 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* WordPress dependencies
|
3
|
-
*/
|
4
|
-
import {
|
5
|
-
insertBlock,
|
6
|
-
deleteAllTemplates,
|
7
|
-
activateTheme,
|
8
|
-
getAllBlocks,
|
9
|
-
selectBlockByClientId,
|
10
|
-
clickBlockToolbarButton,
|
11
|
-
canvas,
|
12
|
-
visitSiteEditor,
|
13
|
-
} from '@wordpress/e2e-test-utils';
|
14
|
-
|
15
|
-
const templatePartNameInput =
|
16
|
-
'.edit-site-create-template-part-modal .components-text-control__input';
|
17
|
-
|
18
|
-
describe( 'Template Part', () => {
|
19
|
-
beforeAll( async () => {
|
20
|
-
await activateTheme( 'emptytheme' );
|
21
|
-
await deleteAllTemplates( 'wp_template' );
|
22
|
-
await deleteAllTemplates( 'wp_template_part' );
|
23
|
-
} );
|
24
|
-
afterEach( async () => {
|
25
|
-
await deleteAllTemplates( 'wp_template' );
|
26
|
-
await deleteAllTemplates( 'wp_template_part' );
|
27
|
-
} );
|
28
|
-
afterAll( async () => {
|
29
|
-
await activateTheme( 'twentytwentyone' );
|
30
|
-
} );
|
31
|
-
|
32
|
-
describe( 'Template part block', () => {
|
33
|
-
beforeEach( async () => {
|
34
|
-
await visitSiteEditor();
|
35
|
-
} );
|
36
|
-
|
37
|
-
async function navigateToHeader() {
|
38
|
-
// Switch to editing the header template part.
|
39
|
-
await visitSiteEditor( {
|
40
|
-
postId: 'emptytheme//header',
|
41
|
-
postType: 'wp_template_part',
|
42
|
-
} );
|
43
|
-
}
|
44
|
-
|
45
|
-
async function updateHeader( content ) {
|
46
|
-
await navigateToHeader();
|
47
|
-
|
48
|
-
// Edit it.
|
49
|
-
await insertBlock( 'Paragraph' );
|
50
|
-
await page.keyboard.type( content );
|
51
|
-
|
52
|
-
// Save it.
|
53
|
-
await page.click( '.edit-site-save-button__button' );
|
54
|
-
await page.click( '.editor-entities-saved-states__save-button' );
|
55
|
-
await page.waitForSelector(
|
56
|
-
'.edit-site-save-button__button:not(.is-busy)'
|
57
|
-
);
|
58
|
-
|
59
|
-
// Switch back to the Index template.
|
60
|
-
await visitSiteEditor( {
|
61
|
-
postId: 'emptytheme//index',
|
62
|
-
postType: 'wp_template',
|
63
|
-
} );
|
64
|
-
}
|
65
|
-
|
66
|
-
async function triggerEllipsisMenuItem( textPrompt ) {
|
67
|
-
await clickBlockToolbarButton( 'Options' );
|
68
|
-
const button = await page.waitForXPath(
|
69
|
-
`//span[contains(text(), "${ textPrompt }")]`
|
70
|
-
);
|
71
|
-
await button.click();
|
72
|
-
}
|
73
|
-
|
74
|
-
async function createParagraphAndGetClientId( content ) {
|
75
|
-
await insertBlock( 'Paragraph' );
|
76
|
-
await page.keyboard.type( content );
|
77
|
-
const allBlocks = await getAllBlocks();
|
78
|
-
const paragraphBlock = allBlocks.find(
|
79
|
-
( block ) =>
|
80
|
-
block.name === 'core/paragraph' &&
|
81
|
-
block.attributes.content === content
|
82
|
-
);
|
83
|
-
return paragraphBlock.clientId;
|
84
|
-
}
|
85
|
-
|
86
|
-
async function assertParagraphInTemplatePart( content ) {
|
87
|
-
const paragraphInTemplatePart = await canvas().waitForXPath(
|
88
|
-
`//*[@data-type="core/template-part"][//p[text()="${ content }"]]`
|
89
|
-
);
|
90
|
-
expect( paragraphInTemplatePart ).not.toBeNull();
|
91
|
-
}
|
92
|
-
|
93
|
-
async function awaitHeaderLoad() {
|
94
|
-
await canvas().waitForSelector(
|
95
|
-
'header.wp-block-template-part.block-editor-block-list__layout'
|
96
|
-
);
|
97
|
-
}
|
98
|
-
|
99
|
-
it( 'Should load customizations when in a template even if only the slug and theme attributes are set.', async () => {
|
100
|
-
await updateHeader( 'Header Template Part 123' );
|
101
|
-
|
102
|
-
// Verify that the header template part is updated.
|
103
|
-
await assertParagraphInTemplatePart( 'Header Template Part 123' );
|
104
|
-
} );
|
105
|
-
|
106
|
-
it( 'Should detach blocks from template part', async () => {
|
107
|
-
await updateHeader( 'Header Template Part 456' );
|
108
|
-
|
109
|
-
const initialTemplateParts = await canvas().$$(
|
110
|
-
'.wp-block-template-part'
|
111
|
-
);
|
112
|
-
|
113
|
-
// Select the header template part block.
|
114
|
-
const allBlocks = await getAllBlocks();
|
115
|
-
const headerBlock = allBlocks.find(
|
116
|
-
( block ) => block.name === 'core/template-part'
|
117
|
-
);
|
118
|
-
await selectBlockByClientId( headerBlock.clientId );
|
119
|
-
|
120
|
-
// Detach blocks from template part using ellipsis menu.
|
121
|
-
await triggerEllipsisMenuItem( 'Detach blocks from template part' );
|
122
|
-
|
123
|
-
// Verify there is one less template part on the page.
|
124
|
-
const finalTemplateParts = await canvas().$$(
|
125
|
-
'.wp-block-template-part'
|
126
|
-
);
|
127
|
-
expect(
|
128
|
-
initialTemplateParts.length - finalTemplateParts.length
|
129
|
-
).toBe( 1 );
|
130
|
-
|
131
|
-
// Verify content of the template part is still present.
|
132
|
-
const [ expectedContent ] = await canvas().$x(
|
133
|
-
'//p[contains(text(), "Header Template Part 456")]'
|
134
|
-
);
|
135
|
-
expect( expectedContent ).not.toBeUndefined();
|
136
|
-
} );
|
137
|
-
|
138
|
-
it( 'Should load navigate-to-links properly', async () => {
|
139
|
-
await navigateToHeader();
|
140
|
-
await insertBlock( 'Paragraph' );
|
141
|
-
await page.keyboard.type( 'Header Template Part 789' );
|
142
|
-
|
143
|
-
// Select the paragraph block.
|
144
|
-
const text = await canvas().waitForXPath(
|
145
|
-
'//p[contains(text(), "Header Template Part 789")]'
|
146
|
-
);
|
147
|
-
|
148
|
-
// Highlight all the text in the paragraph block.
|
149
|
-
await text.click( { clickCount: 3 } );
|
150
|
-
|
151
|
-
// Click the convert to link toolbar button.
|
152
|
-
await page.waitForSelector( 'button[aria-label="Link"]' );
|
153
|
-
await page.click( 'button[aria-label="Link"]' );
|
154
|
-
|
155
|
-
// Enter url for link.
|
156
|
-
await page.keyboard.type( 'https://google.com' );
|
157
|
-
await page.keyboard.press( 'Enter' );
|
158
|
-
|
159
|
-
// Verify that there is no error.
|
160
|
-
await canvas().click( 'p[data-type="core/paragraph"] a' );
|
161
|
-
const expectedContent = await canvas().$x(
|
162
|
-
'//p[contains(text(), "Header Template Part 789")]'
|
163
|
-
);
|
164
|
-
|
165
|
-
expect( expectedContent ).not.toBeUndefined();
|
166
|
-
} );
|
167
|
-
|
168
|
-
it( 'Should convert selected block to template part', async () => {
|
169
|
-
await awaitHeaderLoad();
|
170
|
-
const initialTemplateParts = await canvas().$$(
|
171
|
-
'.wp-block-template-part'
|
172
|
-
);
|
173
|
-
|
174
|
-
// Add some block and select it.
|
175
|
-
const clientId = await createParagraphAndGetClientId(
|
176
|
-
'Some block...'
|
177
|
-
);
|
178
|
-
await selectBlockByClientId( clientId );
|
179
|
-
|
180
|
-
// Convert block to a template part.
|
181
|
-
await triggerEllipsisMenuItem( 'Make template part' );
|
182
|
-
const nameInput = await page.waitForSelector(
|
183
|
-
templatePartNameInput
|
184
|
-
);
|
185
|
-
await nameInput.click();
|
186
|
-
await page.keyboard.type( 'My template part' );
|
187
|
-
await page.keyboard.press( 'Enter' );
|
188
|
-
|
189
|
-
// Wait for creation to finish.
|
190
|
-
await page.waitForXPath(
|
191
|
-
'//*[contains(@class, "components-snackbar")]/*[text()="Template part created."]'
|
192
|
-
);
|
193
|
-
|
194
|
-
// Verify new template part is created with expected content.
|
195
|
-
await assertParagraphInTemplatePart( 'Some block...' );
|
196
|
-
|
197
|
-
// Verify there is 1 more template part on the page than previously.
|
198
|
-
const finalTemplateParts = await canvas().$$(
|
199
|
-
'.wp-block-template-part'
|
200
|
-
);
|
201
|
-
expect(
|
202
|
-
finalTemplateParts.length - initialTemplateParts.length
|
203
|
-
).toBe( 1 );
|
204
|
-
} );
|
205
|
-
|
206
|
-
it( 'Should convert multiple selected blocks to template part', async () => {
|
207
|
-
await awaitHeaderLoad();
|
208
|
-
const initialTemplateParts = await canvas().$$(
|
209
|
-
'.wp-block-template-part'
|
210
|
-
);
|
211
|
-
|
212
|
-
// Add two blocks and select them.
|
213
|
-
const block1Id = await createParagraphAndGetClientId(
|
214
|
-
'Some block #1'
|
215
|
-
);
|
216
|
-
const block2Id = await createParagraphAndGetClientId(
|
217
|
-
'Some block #2'
|
218
|
-
);
|
219
|
-
await page.evaluate(
|
220
|
-
( id1, id2 ) => {
|
221
|
-
wp.data
|
222
|
-
.dispatch( 'core/block-editor' )
|
223
|
-
.multiSelect( id1, id2 );
|
224
|
-
},
|
225
|
-
block1Id,
|
226
|
-
block2Id
|
227
|
-
);
|
228
|
-
|
229
|
-
// Convert block to a template part.
|
230
|
-
await triggerEllipsisMenuItem( 'Make template part' );
|
231
|
-
const nameInput = await page.waitForSelector(
|
232
|
-
templatePartNameInput
|
233
|
-
);
|
234
|
-
await nameInput.click();
|
235
|
-
await page.keyboard.type( 'My multi template part' );
|
236
|
-
await page.keyboard.press( 'Enter' );
|
237
|
-
|
238
|
-
// Wait for creation to finish.
|
239
|
-
await page.waitForXPath(
|
240
|
-
'//*[contains(@class, "components-snackbar")]/*[text()="Template part created."]'
|
241
|
-
);
|
242
|
-
|
243
|
-
// Verify new template part is created with expected content.
|
244
|
-
await assertParagraphInTemplatePart( 'Some block #1' );
|
245
|
-
await assertParagraphInTemplatePart( 'Some block #2' );
|
246
|
-
|
247
|
-
// Verify there is 1 more template part on the page than previously.
|
248
|
-
const finalTemplateParts = await canvas().$$(
|
249
|
-
'.wp-block-template-part'
|
250
|
-
);
|
251
|
-
expect(
|
252
|
-
finalTemplateParts.length - initialTemplateParts.length
|
253
|
-
).toBe( 1 );
|
254
|
-
} );
|
255
|
-
|
256
|
-
describe( 'Template part placeholder', () => {
|
257
|
-
// Test constants for template part.
|
258
|
-
const testContent = 'some words...';
|
259
|
-
|
260
|
-
// Selectors.
|
261
|
-
const entitiesSaveSelector =
|
262
|
-
'.editor-entities-saved-states__save-button';
|
263
|
-
const savePostSelector = '.edit-site-save-button__button';
|
264
|
-
const templatePartSelector = '*[data-type="core/template-part"]';
|
265
|
-
const activatedTemplatePartSelector = `${ templatePartSelector }.block-editor-block-list__layout`;
|
266
|
-
const startBlockButtonSelector =
|
267
|
-
'//button[contains(text(), "Start blank")]';
|
268
|
-
const chooseExistingButtonSelector =
|
269
|
-
'//button[contains(text(), "Choose")]';
|
270
|
-
const confirmTitleButtonSelector =
|
271
|
-
'.wp-block-template-part__placeholder-create-new__title-form .components-button.is-primary';
|
272
|
-
|
273
|
-
it( 'Should insert new template part on creation', async () => {
|
274
|
-
let siteEditorCanvas = canvas();
|
275
|
-
await awaitHeaderLoad();
|
276
|
-
|
277
|
-
// Create new template part.
|
278
|
-
await insertBlock( 'Template Part' );
|
279
|
-
const startBlankButton = await siteEditorCanvas.waitForXPath(
|
280
|
-
startBlockButtonSelector
|
281
|
-
);
|
282
|
-
await startBlankButton.click();
|
283
|
-
const confirmTitleButton = await page.waitForSelector(
|
284
|
-
confirmTitleButtonSelector
|
285
|
-
);
|
286
|
-
await page.keyboard.press( 'Tab' );
|
287
|
-
await page.keyboard.press( 'Tab' );
|
288
|
-
await page.keyboard.type( 'Create New' );
|
289
|
-
await confirmTitleButton.click();
|
290
|
-
|
291
|
-
const newTemplatePart = await siteEditorCanvas.waitForSelector(
|
292
|
-
activatedTemplatePartSelector
|
293
|
-
);
|
294
|
-
expect( newTemplatePart ).toBeTruthy();
|
295
|
-
|
296
|
-
// Finish creating template part, insert some text, and save.
|
297
|
-
await siteEditorCanvas.waitForSelector(
|
298
|
-
'.block-editor-button-block-appender'
|
299
|
-
);
|
300
|
-
await siteEditorCanvas.click(
|
301
|
-
'.block-editor-button-block-appender'
|
302
|
-
);
|
303
|
-
await page.waitForSelector(
|
304
|
-
'.editor-block-list-item-paragraph'
|
305
|
-
);
|
306
|
-
await page.click( '.editor-block-list-item-paragraph' );
|
307
|
-
await page.keyboard.type( testContent );
|
308
|
-
await page.click( savePostSelector );
|
309
|
-
await page.click( entitiesSaveSelector );
|
310
|
-
|
311
|
-
// Reload the page so as the new template part is available in the existing template parts.
|
312
|
-
await visitSiteEditor();
|
313
|
-
siteEditorCanvas = canvas();
|
314
|
-
await awaitHeaderLoad();
|
315
|
-
// Try to insert the template part we created.
|
316
|
-
await insertBlock( 'Template Part' );
|
317
|
-
const chooseExistingButton = await siteEditorCanvas.waitForXPath(
|
318
|
-
chooseExistingButtonSelector
|
319
|
-
);
|
320
|
-
await chooseExistingButton.click();
|
321
|
-
const preview = await page.waitForSelector(
|
322
|
-
'.block-editor-block-patterns-list__item'
|
323
|
-
);
|
324
|
-
await preview.click();
|
325
|
-
|
326
|
-
// Wait for the template parts to load properly.
|
327
|
-
await siteEditorCanvas.waitForSelector(
|
328
|
-
'[data-type="core/template-part"] > p:first-child'
|
329
|
-
);
|
330
|
-
|
331
|
-
// We now have the same template part two times in the page, so check accordingly.
|
332
|
-
const paragraphs = await siteEditorCanvas.$$eval(
|
333
|
-
'[data-type="core/template-part"] > p:first-child',
|
334
|
-
( options ) =>
|
335
|
-
options.map( ( option ) => option.textContent )
|
336
|
-
);
|
337
|
-
expect( paragraphs ).toHaveLength( 2 );
|
338
|
-
expect(
|
339
|
-
paragraphs.every(
|
340
|
-
( paragraph ) => paragraph === testContent
|
341
|
-
)
|
342
|
-
).toBeTruthy();
|
343
|
-
} );
|
344
|
-
} );
|
345
|
-
} );
|
346
|
-
} );
|