-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
template-customization.block_theme.spec.ts
191 lines (166 loc) · 5.65 KB
/
template-customization.block_theme.spec.ts
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/**
* External dependencies
*/
import {
test,
expect,
BLOCK_THEME_SLUG,
BLOCK_THEME_WITH_TEMPLATES_SLUG,
} from '@woocommerce/e2e-utils';
/**
* Internal dependencies
*/
import { CUSTOMIZABLE_WC_TEMPLATES } from './constants';
test.describe( 'Template customization', () => {
CUSTOMIZABLE_WC_TEMPLATES.forEach( ( testData ) => {
const userText = `Hello World in the ${ testData.templateName } template`;
const fallbackTemplateUserText = `Hello World in the fallback ${ testData.templateName } template`;
const templateTypeName =
testData.templateType === 'wp_template'
? 'template'
: 'template part';
test.describe( `${ testData.templateName } template`, () => {
test( 'can be modified and reverted', async ( {
admin,
frontendUtils,
editor,
page,
} ) => {
await admin.visitSiteEditor( {
postId: `woocommerce/woocommerce//${ testData.templatePath }`,
postType: testData.templateType,
} );
await editor.enterEditMode();
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: userText },
} );
await editor.saveSiteEditorEntities();
// Verify template name didn't change.
// See: https://github.com/woocommerce/woocommerce/issues/42221
await expect(
page.getByRole( 'heading', {
name: `Editing ${ templateTypeName }: ${ testData.templateName }`,
} )
).toBeVisible();
await testData.visitPage( { frontendUtils, page } );
await expect(
page.getByText( userText ).first()
).toBeVisible();
} );
if ( testData.fallbackTemplate ) {
test( `defaults to the ${ testData.fallbackTemplate.templateName } template`, async ( {
admin,
frontendUtils,
editor,
page,
} ) => {
// Edit fallback template and verify changes are visible.
await admin.visitSiteEditor( {
postId: `woocommerce/woocommerce//${ testData.fallbackTemplate?.templatePath }`,
postType: testData.templateType,
} );
await editor.enterEditMode();
await editor.insertBlock( {
name: 'core/paragraph',
attributes: {
content: fallbackTemplateUserText,
},
} );
await editor.saveSiteEditorEntities();
await testData.visitPage( { frontendUtils, page } );
await expect(
page.getByText( fallbackTemplateUserText ).first()
).toBeVisible();
} );
}
} );
} );
const testToRun = CUSTOMIZABLE_WC_TEMPLATES.filter(
( data ) => data.canBeOverriddenByThemes
);
for ( const testData of testToRun ) {
const userText = `Hello World in the ${ testData.templateName } template`;
const woocommerceTemplateUserText = `Hello World in the WooCommerce ${ testData.templateName } template`;
test.describe( `${ testData.templateName } template`, () => {
test( `user-modified ${ testData.templateName } template based on the theme template has priority over the user-modified template based on the default WooCommerce template`, async ( {
page,
admin,
editor,
requestUtils,
frontendUtils,
} ) => {
// Edit the WooCommerce default template
await admin.visitSiteEditor( {
postId: `woocommerce/woocommerce//${ testData.templatePath }`,
postType: testData.templateType,
} );
await editor.enterEditMode();
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: woocommerceTemplateUserText },
} );
await editor.saveSiteEditorEntities();
await requestUtils.activateTheme(
BLOCK_THEME_WITH_TEMPLATES_SLUG
);
// Edit the theme template. The theme template is not
// directly available from the UI, because the customized
// one takes priority, so we go directly to its URL.
await admin.visitSiteEditor( {
postId: `${ BLOCK_THEME_WITH_TEMPLATES_SLUG }//${ testData.templatePath }`,
postType: testData.templateType,
} );
await editor.enterEditMode();
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: userText },
} );
await editor.saveSiteEditorEntities();
// Verify the template is the one modified by the user based on the theme.
await testData.visitPage( { frontendUtils, page } );
await expect(
page.getByText( userText ).first()
).toBeVisible();
await expect(
page.getByText( woocommerceTemplateUserText )
).toHaveCount( 0 );
// Revert edition and verify the user-modified WC template is used.
// Note: we need to revert it from the admin (instead of calling
// `deleteAllTemplates()`). This way, we verify there are no
// duplicate templates with the same name.
// See: https://github.com/woocommerce/woocommerce/issues/42220
await admin.visitSiteEditor( {
path: `/${ testData.templateType }/all`,
} );
await page
.getByPlaceholder( 'Search' )
.fill( testData.templateName );
const templateRow = page.getByRole( 'row' ).filter( {
has: page.getByRole( 'link', {
name: testData.templateName,
exact: true,
} ),
} );
const resetButton = templateRow.getByLabel( 'Reset', {
exact: true,
} );
const revertedNotice = page
.getByLabel( 'Dismiss this notice' )
.getByText( `"${ testData.templateName }" reverted.` );
const savedButton = page.getByRole( 'button', {
name: 'Saved',
} );
await resetButton.click();
await expect( revertedNotice ).toBeVisible();
await expect( savedButton ).toBeVisible();
await testData.visitPage( { frontendUtils, page } );
await expect(
page.getByText( woocommerceTemplateUserText ).first()
).toBeVisible();
await expect( page.getByText( userText ) ).toHaveCount( 0 );
await requestUtils.activateTheme( BLOCK_THEME_SLUG );
} );
} );
}
} );