woocommerce/plugins/woocommerce-blocks/tests/utils/save-or-publish.js

23 lines
595 B
JavaScript
Raw Normal View History

Add E2E tests for Filter blocks (Price, Attribute, and Active Filters) (https://github.com/woocommerce/woocommerce-blocks/pull/4562) * Add clear and fill input test util * Add tests for Filter Products by Price * Add class name to filter products by price block in editor * Update wp-env * Fix formatting * Update lock * Revert "Update lock" This reverts commit f4e809e000430eea3972c94fd2aea0a19ba6961b. * Create product attributes during setup * Remove product attributes during teardown * Add attributes in fixture-data * Add two new products, for attribute testing * Load attributes into store and apply them to products * Add class to Filter by Attribute when editing This is so it can be targeted in E2E tests more easily. * Add tests for Filter Product by Attribute * Fix formatting in attribute-filter.test.js * Add tests for active filters block * Add doc block for ensuteCleanAttributes * Update wording of title test in all filter block E2E * Update test wording to read better * Update snapshots * Use pptr-testing-library selectors to click elements This makes the tests easier to reason with, and lets us take a step back from the implementation details (classnames etc.) * Add saveOrPublish test util * Use pptr-testing-library selectors to click elements in attribute filter * Use pptr-testing-library selectors to click elements in price filter * Add `puppeteer-testing-library` * Use puppeteer-testing-library API to look for H6 button * Use correct argument in jest-puppeteer.dev.config * Update package.json & package-lock.json * remove tests for 5.3 * remove snapshots * Remove ensureCleanAttributes * Remove puppeteer-testing-library, install missing expect-puppeteer package and update tests The puppeteer-testing-library, although added by gutenberg is not actively used. I have removed it and realised that the added functionality can be easily replaced by expect-puppeteer. This is a package that we specify in the jest configuration but it was not part of our package.json. The selectors from puppeteer-testing-library have been replaced with .toClick and the utility clearAndFillInput with .toFill The Filter by Attribute block has been skiped until tests are fixed. * Add back setupPageSettings to jest setup * Fix filter by attribute block test * Fix linting error Co-authored-by: Raluca Stan <ralucastn@gmail.com>
2021-12-23 16:26:10 +00:00
/**
* External dependencies
*/
import { publishPost } from '@wordpress/e2e-test-utils';
export async function saveOrPublish() {
const link = await page.evaluate( () =>
wp.data.select( 'core/editor' ).getPermalink()
);
if ( link.match( 'auto-draft' ) ) {
await publishPost();
} else {
const publishButton = await page.$(
'.editor-post-publish-button.editor-post-publish-button__button:not([aria-disabled="true"])'
);
if ( publishButton ) {
await publishButton.click();
// A success notice should show up
await page.waitForSelector( '.components-snackbar' );
}
}
}