2020-02-11 17:23:23 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
switchUserToAdmin,
|
2020-06-15 14:59:18 +00:00
|
|
|
getEditedPostContent,
|
|
|
|
openDocumentSettingsSidebar,
|
2020-02-11 17:23:23 +00:00
|
|
|
} from '@wordpress/e2e-test-utils';
|
2021-04-26 15:31:30 +00:00
|
|
|
import { clearAndFillInput } from '@woocommerce/e2e-utils';
|
2020-07-29 13:39:15 +00:00
|
|
|
import {
|
2020-09-14 07:46:58 +00:00
|
|
|
findLabelWithText,
|
2020-07-29 13:39:15 +00:00
|
|
|
visitBlockPage,
|
|
|
|
} from '@woocommerce/blocks-test-utils';
|
2020-02-11 17:23:23 +00:00
|
|
|
|
2020-06-15 14:59:18 +00:00
|
|
|
const block = {
|
|
|
|
name: 'Product Search',
|
|
|
|
slug: 'woocommerce/product-search',
|
|
|
|
class: '.wc-block-product-search',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe( `${ block.name } Block`, () => {
|
|
|
|
beforeAll( async () => {
|
2020-02-11 17:23:23 +00:00
|
|
|
await switchUserToAdmin();
|
2020-06-15 14:59:18 +00:00
|
|
|
await visitBlockPage( `${ block.name } Block` );
|
2020-02-11 17:23:23 +00:00
|
|
|
} );
|
|
|
|
|
2020-06-15 14:59:18 +00:00
|
|
|
it( 'renders without crashing', async () => {
|
2020-06-25 13:00:27 +00:00
|
|
|
await expect( page ).toRenderBlock( block );
|
2020-02-11 17:23:23 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'can toggle field label', async () => {
|
2020-06-15 14:59:18 +00:00
|
|
|
await openDocumentSettingsSidebar();
|
|
|
|
await page.click( block.class );
|
2020-09-14 07:46:58 +00:00
|
|
|
const selector = `${ block.class } .wc-block-product-search__label`;
|
|
|
|
const toggleLabel = await findLabelWithText(
|
|
|
|
'Show search field label'
|
2020-02-11 17:23:23 +00:00
|
|
|
);
|
2020-09-14 07:46:58 +00:00
|
|
|
await expect( toggleLabel ).toToggleElement( selector );
|
2020-02-11 17:23:23 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'can change field labels in editor', async () => {
|
|
|
|
await expect( page ).toFill(
|
|
|
|
'textarea.wc-block-product-search__label',
|
|
|
|
'I am a new label'
|
|
|
|
);
|
|
|
|
|
|
|
|
await expect( page ).toFill(
|
2020-08-18 11:25:48 +00:00
|
|
|
'.wc-block-product-search__field input',
|
2020-02-11 17:23:23 +00:00
|
|
|
'I am a new placeholder'
|
|
|
|
);
|
|
|
|
|
|
|
|
await clearAndFillInput(
|
|
|
|
'textarea.wc-block-product-search__label',
|
|
|
|
'The Label'
|
|
|
|
);
|
|
|
|
await clearAndFillInput(
|
2020-08-18 11:25:48 +00:00
|
|
|
'.wc-block-product-search__field input',
|
2020-02-11 17:23:23 +00:00
|
|
|
'The Placeholder'
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( await getEditedPostContent() ).toMatchSnapshot();
|
|
|
|
} );
|
|
|
|
} );
|