2022-02-21 11:01:56 +00:00
|
|
|
import { URL } from 'url';
|
|
|
|
|
2022-02-21 10:01:42 +00:00
|
|
|
import {
|
|
|
|
canvas,
|
2022-03-10 10:00:23 +00:00
|
|
|
deleteAllTemplates,
|
2022-02-21 10:01:42 +00:00
|
|
|
getCurrentSiteEditorContent,
|
|
|
|
insertBlock,
|
|
|
|
} from '@wordpress/e2e-test-utils';
|
|
|
|
import {
|
|
|
|
getNormalPagePermalink,
|
|
|
|
visitPostOfType,
|
|
|
|
} from '@woocommerce/blocks-test-utils';
|
|
|
|
import {
|
2022-02-21 11:01:56 +00:00
|
|
|
BASE_URL,
|
2022-02-21 10:01:42 +00:00
|
|
|
DEFAULT_TIMEOUT,
|
|
|
|
filterCurrentBlocks,
|
|
|
|
getAllTemplates,
|
2022-03-28 12:32:15 +00:00
|
|
|
goToTemplateEditor,
|
|
|
|
goToTemplatesList,
|
2022-02-21 10:01:42 +00:00
|
|
|
saveTemplate,
|
2022-03-02 14:49:00 +00:00
|
|
|
useTheme,
|
2022-02-21 10:01:42 +00:00
|
|
|
} from '../../utils';
|
|
|
|
|
2022-02-21 11:01:56 +00:00
|
|
|
async function visitTemplateAndAddCustomParagraph(
|
|
|
|
templateSlug,
|
|
|
|
customText = CUSTOMIZED_STRING
|
|
|
|
) {
|
2022-03-28 12:32:15 +00:00
|
|
|
await goToTemplateEditor( {
|
2022-02-21 11:01:56 +00:00
|
|
|
postId: `woocommerce/woocommerce//${ templateSlug }`,
|
|
|
|
} );
|
|
|
|
|
|
|
|
await insertBlock( 'Paragraph' );
|
|
|
|
await page.keyboard.type( customText );
|
|
|
|
await saveTemplate();
|
|
|
|
}
|
|
|
|
|
2022-02-21 10:01:42 +00:00
|
|
|
function blockSelector( id ) {
|
|
|
|
return `[data-type="${ id }"]`;
|
|
|
|
}
|
|
|
|
|
|
|
|
function defaultTemplateProps( templateTitle ) {
|
|
|
|
return {
|
|
|
|
templateTitle,
|
|
|
|
addedBy: WOOCOMMERCE_ID,
|
|
|
|
hasActions: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-22 22:34:43 +00:00
|
|
|
function classicBlockSelector( title ) {
|
2022-02-21 10:01:42 +00:00
|
|
|
return `${ blockSelector(
|
|
|
|
'woocommerce/legacy-template'
|
|
|
|
) }[data-title="${ title }"]`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const BLOCK_DATA = {
|
2022-02-21 11:01:56 +00:00
|
|
|
'archive-product': {
|
|
|
|
attributes: {
|
|
|
|
placeholder: 'archive-product',
|
|
|
|
template: 'archive-product',
|
|
|
|
title: 'WooCommerce Product Grid Block',
|
|
|
|
},
|
|
|
|
name: 'woocommerce/legacy-template',
|
|
|
|
},
|
2022-02-21 10:01:42 +00:00
|
|
|
'single-product': {
|
|
|
|
attributes: {
|
|
|
|
placeholder: 'single-product',
|
|
|
|
template: 'single-product',
|
|
|
|
title: 'WooCommerce Single Product Block',
|
|
|
|
},
|
|
|
|
name: 'woocommerce/legacy-template',
|
|
|
|
},
|
2022-02-21 11:38:36 +00:00
|
|
|
'taxonomy-product_cat': {
|
|
|
|
attributes: {
|
|
|
|
placeholder: 'archive-product',
|
|
|
|
template: 'taxonomy-product_cat',
|
|
|
|
title: 'WooCommerce Product Taxonomy Block',
|
|
|
|
},
|
|
|
|
name: 'woocommerce/legacy-template',
|
|
|
|
},
|
2022-02-21 12:26:22 +00:00
|
|
|
'taxonomy-product_tag': {
|
|
|
|
attributes: {
|
|
|
|
placeholder: 'archive-product',
|
|
|
|
template: 'taxonomy-product_tag',
|
|
|
|
title: 'WooCommerce Product Tag Block',
|
|
|
|
},
|
|
|
|
name: 'woocommerce/legacy-template',
|
|
|
|
},
|
2022-02-21 10:01:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const SELECTORS = {
|
|
|
|
blocks: {
|
|
|
|
paragraph: blockSelector( 'core/paragraph' ),
|
2022-03-22 22:34:43 +00:00
|
|
|
productArchive: classicBlockSelector(
|
|
|
|
'WooCommerce Product Grid Block'
|
|
|
|
),
|
|
|
|
singleProduct: classicBlockSelector(
|
2022-02-21 10:01:42 +00:00
|
|
|
'WooCommerce Single Product Block'
|
|
|
|
),
|
|
|
|
},
|
2022-03-23 13:18:00 +00:00
|
|
|
templates: {
|
|
|
|
templateActions:
|
|
|
|
'[aria-label="Templates list - Content"] [aria-label="Actions"]',
|
|
|
|
},
|
2022-02-21 10:01:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const CUSTOMIZED_STRING = 'My awesome customization';
|
|
|
|
const WOOCOMMERCE_ID = 'woocommerce/woocommerce';
|
|
|
|
const WOOCOMMERCE_PARSED_ID = 'WooCommerce';
|
|
|
|
|
|
|
|
describe( 'Store Editing Templates', () => {
|
2022-03-02 14:49:00 +00:00
|
|
|
useTheme( 'emptytheme' );
|
|
|
|
|
2022-02-21 10:01:42 +00:00
|
|
|
beforeAll( async () => {
|
2022-03-10 10:00:23 +00:00
|
|
|
await deleteAllTemplates( 'wp_template' );
|
|
|
|
await deleteAllTemplates( 'wp_template_part' );
|
2022-02-21 10:01:42 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
describe( 'Single Product block template', () => {
|
|
|
|
it( 'default template from WooCommerce Blocks is available on an FSE theme', async () => {
|
|
|
|
const EXPECTED_TEMPLATE = defaultTemplateProps( 'Single Product' );
|
|
|
|
|
2022-03-28 12:32:15 +00:00
|
|
|
await goToTemplatesList();
|
|
|
|
|
2022-02-21 10:01:42 +00:00
|
|
|
const templates = await getAllTemplates();
|
|
|
|
|
|
|
|
try {
|
|
|
|
expect( templates ).toContainEqual( EXPECTED_TEMPLATE );
|
|
|
|
} catch ( ok ) {
|
|
|
|
// Depending on the speed of the execution and whether Chrome is headless or not
|
|
|
|
// the id might be parsed or not
|
|
|
|
|
|
|
|
expect( templates ).toContainEqual( {
|
|
|
|
...EXPECTED_TEMPLATE,
|
|
|
|
addedBy: WOOCOMMERCE_PARSED_ID,
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2022-03-22 22:34:43 +00:00
|
|
|
it( 'should contain the "WooCommerce Single Product Block" classic template', async () => {
|
2022-03-28 12:32:15 +00:00
|
|
|
await goToTemplateEditor( {
|
2022-02-21 10:01:42 +00:00
|
|
|
postId: 'woocommerce/woocommerce//single-product',
|
|
|
|
} );
|
|
|
|
|
2022-03-22 22:34:43 +00:00
|
|
|
const [ classicBlock ] = await filterCurrentBlocks(
|
2022-02-21 10:01:42 +00:00
|
|
|
( block ) => block.name === BLOCK_DATA[ 'single-product' ].name
|
|
|
|
);
|
|
|
|
|
|
|
|
// Comparing only the `template` property currently
|
|
|
|
// because the other properties seem to be slightly unreliable.
|
|
|
|
// Investigation pending.
|
2022-03-22 22:34:43 +00:00
|
|
|
expect( classicBlock.attributes.template ).toBe(
|
2022-02-21 10:01:42 +00:00
|
|
|
BLOCK_DATA[ 'single-product' ].attributes.template
|
|
|
|
);
|
|
|
|
expect( await getCurrentSiteEditorContent() ).toMatchSnapshot();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should show the action menu if the template has been customized by the user', async () => {
|
|
|
|
const EXPECTED_TEMPLATE = {
|
|
|
|
...defaultTemplateProps( 'Single Product' ),
|
|
|
|
hasActions: true,
|
|
|
|
};
|
|
|
|
|
2022-02-21 11:01:56 +00:00
|
|
|
await visitTemplateAndAddCustomParagraph( 'single-product' );
|
|
|
|
|
2022-03-28 12:32:15 +00:00
|
|
|
await goToTemplatesList( { waitFor: 'actions' } );
|
|
|
|
|
2022-02-21 11:01:56 +00:00
|
|
|
const templates = await getAllTemplates();
|
|
|
|
|
|
|
|
try {
|
|
|
|
expect( templates ).toContainEqual( EXPECTED_TEMPLATE );
|
|
|
|
} catch ( ok ) {
|
|
|
|
// Depending on the speed of the execution and whether Chrome is headless or not
|
|
|
|
// the id might be parsed or not
|
|
|
|
|
|
|
|
expect( templates ).toContainEqual( {
|
|
|
|
...EXPECTED_TEMPLATE,
|
|
|
|
addedBy: WOOCOMMERCE_PARSED_ID,
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should preserve and correctly show the user customization on the back-end', async () => {
|
2022-03-28 12:32:15 +00:00
|
|
|
await goToTemplateEditor( {
|
2022-02-21 10:01:42 +00:00
|
|
|
postId: 'woocommerce/woocommerce//single-product',
|
|
|
|
} );
|
|
|
|
|
2022-02-21 11:01:56 +00:00
|
|
|
await expect( canvas() ).toMatchElement(
|
|
|
|
SELECTORS.blocks.paragraph,
|
2022-03-22 22:34:43 +00:00
|
|
|
{
|
|
|
|
text: CUSTOMIZED_STRING,
|
|
|
|
timeout: DEFAULT_TIMEOUT,
|
|
|
|
}
|
2022-02-21 11:01:56 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should show the user customization on the front-end', async () => {
|
|
|
|
const exampleProductName = 'Woo Single #1';
|
|
|
|
|
|
|
|
await visitPostOfType( exampleProductName, 'product' );
|
|
|
|
const permalink = await getNormalPagePermalink();
|
|
|
|
|
|
|
|
await page.goto( permalink );
|
|
|
|
|
|
|
|
await expect( page ).toMatchElement( 'p', {
|
|
|
|
text: CUSTOMIZED_STRING,
|
|
|
|
timeout: DEFAULT_TIMEOUT,
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2022-02-28 07:00:01 +00:00
|
|
|
describe( 'Product Catalog block template', () => {
|
2022-02-21 11:01:56 +00:00
|
|
|
it( 'default template from WooCommerce Blocks is available on an FSE theme', async () => {
|
2022-02-28 07:00:01 +00:00
|
|
|
const EXPECTED_TEMPLATE = defaultTemplateProps( 'Product Catalog' );
|
2022-02-21 10:01:42 +00:00
|
|
|
|
2022-03-28 12:32:15 +00:00
|
|
|
await goToTemplatesList();
|
|
|
|
|
2022-02-21 11:01:56 +00:00
|
|
|
const templates = await getAllTemplates();
|
|
|
|
|
|
|
|
try {
|
|
|
|
expect( templates ).toContainEqual( EXPECTED_TEMPLATE );
|
|
|
|
} catch ( ok ) {
|
|
|
|
// Depending on the speed of the execution and whether Chrome is headless or not
|
|
|
|
// the id might be parsed or not
|
|
|
|
|
|
|
|
expect( templates ).toContainEqual( {
|
|
|
|
...EXPECTED_TEMPLATE,
|
|
|
|
addedBy: WOOCOMMERCE_PARSED_ID,
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2022-03-22 22:34:43 +00:00
|
|
|
it( 'should contain the "WooCommerce Product Grid Block" classic template', async () => {
|
2022-03-28 12:32:15 +00:00
|
|
|
await goToTemplateEditor( {
|
2022-02-21 11:01:56 +00:00
|
|
|
postId: 'woocommerce/woocommerce//archive-product',
|
|
|
|
} );
|
|
|
|
|
2022-03-22 22:34:43 +00:00
|
|
|
const [ classicBlock ] = await filterCurrentBlocks(
|
2022-02-21 11:01:56 +00:00
|
|
|
( block ) => block.name === BLOCK_DATA[ 'archive-product' ].name
|
|
|
|
);
|
|
|
|
|
2022-03-22 22:34:43 +00:00
|
|
|
expect( classicBlock.attributes.template ).toBe(
|
2022-02-21 11:01:56 +00:00
|
|
|
BLOCK_DATA[ 'archive-product' ].attributes.template
|
|
|
|
);
|
|
|
|
expect( await getCurrentSiteEditorContent() ).toMatchSnapshot();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should show the action menu if the template has been customized by the user', async () => {
|
|
|
|
const EXPECTED_TEMPLATE = {
|
2022-02-28 07:00:01 +00:00
|
|
|
...defaultTemplateProps( 'Product Catalog' ),
|
2022-02-21 11:01:56 +00:00
|
|
|
hasActions: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
await visitTemplateAndAddCustomParagraph( 'archive-product' );
|
|
|
|
|
2022-03-28 12:32:15 +00:00
|
|
|
await goToTemplatesList( { waitFor: 'actions' } );
|
|
|
|
|
2022-02-21 10:01:42 +00:00
|
|
|
const templates = await getAllTemplates();
|
|
|
|
|
|
|
|
try {
|
|
|
|
expect( templates ).toContainEqual( EXPECTED_TEMPLATE );
|
|
|
|
} catch ( ok ) {
|
|
|
|
// Depending on the speed of the execution and whether Chrome is headless or not
|
|
|
|
// the id might be parsed or not
|
|
|
|
|
|
|
|
expect( templates ).toContainEqual( {
|
|
|
|
...EXPECTED_TEMPLATE,
|
|
|
|
addedBy: WOOCOMMERCE_PARSED_ID,
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should preserve and correctly show the user customization on the back-end', async () => {
|
2022-03-28 12:32:15 +00:00
|
|
|
await goToTemplateEditor( {
|
2022-02-21 11:01:56 +00:00
|
|
|
postId: 'woocommerce/woocommerce//archive-product',
|
2022-02-21 10:01:42 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
await expect( canvas() ).toMatchElement(
|
|
|
|
SELECTORS.blocks.paragraph,
|
2022-03-22 22:34:43 +00:00
|
|
|
{
|
|
|
|
text: CUSTOMIZED_STRING,
|
|
|
|
timeout: DEFAULT_TIMEOUT,
|
|
|
|
}
|
2022-02-21 10:01:42 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should show the user customization on the front-end', async () => {
|
2022-02-21 11:01:56 +00:00
|
|
|
await page.goto( new URL( '/?post_type=product', BASE_URL ) );
|
2022-02-21 10:01:42 +00:00
|
|
|
const exampleProductName = 'Woo Single #1';
|
|
|
|
|
|
|
|
await visitPostOfType( exampleProductName, 'product' );
|
|
|
|
const permalink = await getNormalPagePermalink();
|
|
|
|
|
|
|
|
await page.goto( permalink );
|
|
|
|
|
|
|
|
await expect( page ).toMatchElement( 'p', {
|
|
|
|
text: CUSTOMIZED_STRING,
|
|
|
|
timeout: DEFAULT_TIMEOUT,
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
2022-02-21 11:38:36 +00:00
|
|
|
|
2022-02-28 07:00:01 +00:00
|
|
|
describe( 'Product by Category block template', () => {
|
2022-02-21 11:38:36 +00:00
|
|
|
it( 'default template from WooCommerce Blocks is available on an FSE theme', async () => {
|
|
|
|
const EXPECTED_TEMPLATE = defaultTemplateProps(
|
2022-02-28 07:00:01 +00:00
|
|
|
'Products by Category'
|
2022-02-21 11:38:36 +00:00
|
|
|
);
|
|
|
|
|
2022-03-28 12:32:15 +00:00
|
|
|
await goToTemplatesList();
|
|
|
|
|
2022-02-21 11:38:36 +00:00
|
|
|
const templates = await getAllTemplates();
|
|
|
|
|
|
|
|
try {
|
|
|
|
expect( templates ).toContainEqual( EXPECTED_TEMPLATE );
|
|
|
|
} catch ( ok ) {
|
|
|
|
// Depending on the speed of the execution and whether Chrome is headless or not
|
|
|
|
// the id might be parsed or not
|
|
|
|
|
|
|
|
expect( templates ).toContainEqual( {
|
|
|
|
...EXPECTED_TEMPLATE,
|
|
|
|
addedBy: WOOCOMMERCE_PARSED_ID,
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2022-03-22 22:34:43 +00:00
|
|
|
it( 'should contain the "WooCommerce Product Taxonomy Block" classic template', async () => {
|
2022-03-28 12:32:15 +00:00
|
|
|
await goToTemplateEditor( {
|
2022-02-21 11:38:36 +00:00
|
|
|
postId: 'woocommerce/woocommerce//taxonomy-product_cat',
|
|
|
|
} );
|
|
|
|
|
2022-03-22 22:34:43 +00:00
|
|
|
const [ classicBlock ] = await filterCurrentBlocks(
|
2022-02-21 11:38:36 +00:00
|
|
|
( block ) =>
|
|
|
|
block.name === BLOCK_DATA[ 'taxonomy-product_cat' ].name
|
|
|
|
);
|
|
|
|
|
2022-03-22 22:34:43 +00:00
|
|
|
expect( classicBlock.attributes.template ).toBe(
|
2022-02-21 11:38:36 +00:00
|
|
|
BLOCK_DATA[ 'taxonomy-product_cat' ].attributes.template
|
|
|
|
);
|
|
|
|
expect( await getCurrentSiteEditorContent() ).toMatchSnapshot();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should show the action menu if the template has been customized by the user', async () => {
|
|
|
|
const EXPECTED_TEMPLATE = {
|
2022-02-28 07:00:01 +00:00
|
|
|
...defaultTemplateProps( 'Products by Category' ),
|
2022-02-21 11:38:36 +00:00
|
|
|
hasActions: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
await visitTemplateAndAddCustomParagraph( 'taxonomy-product_cat' );
|
|
|
|
|
2022-03-28 12:32:15 +00:00
|
|
|
await goToTemplatesList( { waitFor: 'actions' } );
|
|
|
|
|
2022-02-21 11:38:36 +00:00
|
|
|
const templates = await getAllTemplates();
|
|
|
|
|
|
|
|
try {
|
|
|
|
expect( templates ).toContainEqual( EXPECTED_TEMPLATE );
|
|
|
|
} catch ( ok ) {
|
|
|
|
// Depending on the speed of the execution and whether Chrome is headless or not
|
|
|
|
// the id might be parsed or not
|
|
|
|
|
|
|
|
expect( templates ).toContainEqual( {
|
|
|
|
...EXPECTED_TEMPLATE,
|
|
|
|
addedBy: WOOCOMMERCE_PARSED_ID,
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should preserve and correctly show the user customization on the back-end', async () => {
|
2022-03-28 12:32:15 +00:00
|
|
|
await goToTemplateEditor( {
|
2022-02-21 11:38:36 +00:00
|
|
|
postId: 'woocommerce/woocommerce//taxonomy-product_cat',
|
|
|
|
} );
|
|
|
|
|
|
|
|
await expect( canvas() ).toMatchElement(
|
|
|
|
SELECTORS.blocks.paragraph,
|
2022-03-22 22:34:43 +00:00
|
|
|
{
|
|
|
|
text: CUSTOMIZED_STRING,
|
|
|
|
timeout: DEFAULT_TIMEOUT,
|
|
|
|
}
|
2022-02-21 11:38:36 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should show the user customization on the front-end', async () => {
|
|
|
|
await page.goto(
|
|
|
|
new URL( '/product-category/uncategorized', BASE_URL )
|
|
|
|
);
|
|
|
|
|
|
|
|
await expect( page ).toMatchElement( 'p', {
|
|
|
|
text: CUSTOMIZED_STRING,
|
|
|
|
timeout: DEFAULT_TIMEOUT,
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
2022-02-21 12:26:22 +00:00
|
|
|
|
2022-02-28 07:00:01 +00:00
|
|
|
describe( 'Products by Tag block template', () => {
|
2022-02-21 12:26:22 +00:00
|
|
|
it( 'default template from WooCommerce Blocks is available on an FSE theme', async () => {
|
2022-02-28 07:00:01 +00:00
|
|
|
const EXPECTED_TEMPLATE = defaultTemplateProps( 'Products by Tag' );
|
2022-02-21 12:26:22 +00:00
|
|
|
|
2022-03-28 12:32:15 +00:00
|
|
|
await goToTemplatesList();
|
|
|
|
|
2022-02-21 12:26:22 +00:00
|
|
|
const templates = await getAllTemplates();
|
|
|
|
|
|
|
|
try {
|
|
|
|
expect( templates ).toContainEqual( EXPECTED_TEMPLATE );
|
|
|
|
} catch ( ok ) {
|
|
|
|
// Depending on the speed of the execution and whether Chrome is headless or not
|
|
|
|
// the id might be parsed or not
|
|
|
|
|
|
|
|
expect( templates ).toContainEqual( {
|
|
|
|
...EXPECTED_TEMPLATE,
|
|
|
|
addedBy: WOOCOMMERCE_PARSED_ID,
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2022-03-22 22:34:43 +00:00
|
|
|
it( 'should contain the "WooCommerce Product Taxonomy Block" classic template', async () => {
|
2022-03-28 12:32:15 +00:00
|
|
|
await goToTemplateEditor( {
|
2022-02-21 12:26:22 +00:00
|
|
|
postId: 'woocommerce/woocommerce//taxonomy-product_tag',
|
|
|
|
} );
|
|
|
|
|
2022-03-22 22:34:43 +00:00
|
|
|
const [ classicBlock ] = await filterCurrentBlocks(
|
2022-02-21 12:26:22 +00:00
|
|
|
( block ) =>
|
|
|
|
block.name === BLOCK_DATA[ 'taxonomy-product_tag' ].name
|
|
|
|
);
|
|
|
|
|
2022-03-22 22:34:43 +00:00
|
|
|
expect( classicBlock.attributes.template ).toBe(
|
2022-02-21 12:26:22 +00:00
|
|
|
BLOCK_DATA[ 'taxonomy-product_tag' ].attributes.template
|
|
|
|
);
|
|
|
|
expect( await getCurrentSiteEditorContent() ).toMatchSnapshot();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should show the action menu if the template has been customized by the user', async () => {
|
|
|
|
const EXPECTED_TEMPLATE = {
|
2022-02-28 07:00:01 +00:00
|
|
|
...defaultTemplateProps( 'Products by Tag' ),
|
2022-02-21 12:26:22 +00:00
|
|
|
hasActions: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
await visitTemplateAndAddCustomParagraph( 'taxonomy-product_tag' );
|
|
|
|
|
2022-03-28 12:32:15 +00:00
|
|
|
await goToTemplatesList( { waitFor: 'actions' } );
|
|
|
|
|
2022-02-21 12:26:22 +00:00
|
|
|
const templates = await getAllTemplates();
|
|
|
|
|
|
|
|
try {
|
|
|
|
expect( templates ).toContainEqual( EXPECTED_TEMPLATE );
|
|
|
|
} catch ( ok ) {
|
|
|
|
// Depending on the speed of the execution and whether Chrome is headless or not
|
|
|
|
// the id might be parsed or not
|
|
|
|
|
|
|
|
expect( templates ).toContainEqual( {
|
|
|
|
...EXPECTED_TEMPLATE,
|
|
|
|
addedBy: WOOCOMMERCE_PARSED_ID,
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should preserve and correctly show the user customization on the back-end', async () => {
|
2022-03-28 12:32:15 +00:00
|
|
|
await goToTemplateEditor( {
|
2022-02-21 12:26:22 +00:00
|
|
|
postId: 'woocommerce/woocommerce//taxonomy-product_tag',
|
|
|
|
} );
|
|
|
|
|
|
|
|
await expect( canvas() ).toMatchElement(
|
|
|
|
SELECTORS.blocks.paragraph,
|
2022-03-22 22:34:43 +00:00
|
|
|
{
|
|
|
|
text: CUSTOMIZED_STRING,
|
|
|
|
timeout: DEFAULT_TIMEOUT,
|
|
|
|
}
|
2022-02-21 12:26:22 +00:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should show the user customization on the front-end', async () => {
|
|
|
|
await page.goto( new URL( '/product-tag/newest', BASE_URL ) );
|
|
|
|
|
|
|
|
await expect( page ).toMatchElement( 'p', {
|
|
|
|
text: CUSTOMIZED_STRING,
|
|
|
|
timeout: DEFAULT_TIMEOUT,
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
2022-04-14 09:45:00 +00:00
|
|
|
|
|
|
|
describe( 'Product Search Results block template', () => {
|
|
|
|
it( 'default template from WooCommerce Blocks is available on an FSE theme', async () => {
|
|
|
|
const EXPECTED_TEMPLATE = defaultTemplateProps(
|
|
|
|
'Product Search Results'
|
|
|
|
);
|
|
|
|
|
|
|
|
await goToTemplatesList();
|
|
|
|
|
|
|
|
const templates = await getAllTemplates();
|
|
|
|
|
|
|
|
try {
|
|
|
|
expect( templates ).toContainEqual( EXPECTED_TEMPLATE );
|
|
|
|
} catch ( ok ) {
|
|
|
|
// Depending on the speed of the execution and whether Chrome is headless or not
|
|
|
|
// the id might be parsed or not
|
|
|
|
|
|
|
|
expect( templates ).toContainEqual( {
|
|
|
|
...EXPECTED_TEMPLATE,
|
|
|
|
addedBy: WOOCOMMERCE_PARSED_ID,
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should contain the "WooCommerce Product Grid Block" classic template', async () => {
|
|
|
|
await goToTemplateEditor( {
|
|
|
|
postId: 'woocommerce/woocommerce//product-search-results',
|
|
|
|
} );
|
|
|
|
|
|
|
|
const [ classicBlock ] = await filterCurrentBlocks(
|
|
|
|
( block ) => block.name === BLOCK_DATA[ 'archive-product' ].name
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( classicBlock.attributes.template ).toBe(
|
|
|
|
BLOCK_DATA[ 'archive-product' ].attributes.template
|
|
|
|
);
|
|
|
|
expect( await getCurrentSiteEditorContent() ).toMatchSnapshot();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should show the action menu if the template has been customized by the user', async () => {
|
|
|
|
const EXPECTED_TEMPLATE = {
|
|
|
|
...defaultTemplateProps( 'Product Search Results' ),
|
|
|
|
hasActions: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
await visitTemplateAndAddCustomParagraph(
|
|
|
|
'product-search-results'
|
|
|
|
);
|
|
|
|
|
|
|
|
await goToTemplatesList( { waitFor: 'actions' } );
|
|
|
|
|
|
|
|
const templates = await getAllTemplates();
|
|
|
|
|
|
|
|
try {
|
|
|
|
expect( templates ).toContainEqual( EXPECTED_TEMPLATE );
|
|
|
|
} catch ( ok ) {
|
|
|
|
// Depending on the speed of the execution and whether Chrome is headless or not
|
|
|
|
// the id might be parsed or not
|
|
|
|
|
|
|
|
expect( templates ).toContainEqual( {
|
|
|
|
...EXPECTED_TEMPLATE,
|
|
|
|
addedBy: WOOCOMMERCE_PARSED_ID,
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should preserve and correctly show the user customization on the back-end', async () => {
|
|
|
|
await goToTemplateEditor( {
|
|
|
|
postId: 'woocommerce/woocommerce//product-search-results',
|
|
|
|
} );
|
|
|
|
|
|
|
|
await expect( canvas() ).toMatchElement(
|
|
|
|
SELECTORS.blocks.paragraph,
|
|
|
|
{
|
|
|
|
text: CUSTOMIZED_STRING,
|
|
|
|
timeout: DEFAULT_TIMEOUT,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should show the user customization on the front-end', async () => {
|
|
|
|
await page.goto(
|
|
|
|
new URL( '?s=shirt&post_type=product', BASE_URL )
|
|
|
|
);
|
|
|
|
|
|
|
|
await expect( page ).toMatchElement( 'p', {
|
|
|
|
text: CUSTOMIZED_STRING,
|
|
|
|
timeout: DEFAULT_TIMEOUT,
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
2022-02-21 10:01:42 +00:00
|
|
|
} );
|