woocommerce/plugins/woocommerce-blocks/tests/e2e/utils/api/template-api-utils.page.ts

76 lines
1.6 KiB
TypeScript
Raw Normal View History

/**
* External dependencies
*/
import { request as req } from '@playwright/test';
import fs from 'fs/promises';
/**
* Internal dependencies
*/
import { BASE_URL, STORAGE_STATE_PATH } from '../constants';
export class TemplateApiUtils {
request: typeof req;
constructor( request: typeof req ) {
this.request = request;
}
async revertTemplate( slug: string ) {
const storageState = JSON.parse(
await fs.readFile( STORAGE_STATE_PATH, 'utf-8' )
);
const requestUtils = await this.request.newContext( {
baseURL: BASE_URL,
storageState: storageState && {
cookies: storageState.cookies,
origins: [],
},
} );
const response = await requestUtils.get(
`/wp-json/wp/v2/templates/${ slug }?context=edit&source=theme&_locale=user`,
{
headers: {
'X-WP-Nonce': storageState.nonce,
},
}
);
const { content } = await response.json();
await requestUtils.post(
`wp-json/wp/v2/templates/${ slug }?_locale=user`,
{
data: {
id: slug,
Fix E2E tests for WordPress 6.5 (#44593) * Add sharding to Blocks e2e tests * Changelog * Push a change to Blocks README to trigger tests * Fix syntax * Fixed again * Try again * Trying to get the shard number * Shard names * fix E2E test * use wordpress 6.5 as test env * update util * fix Mini Cart Block E2E test * add editor dependency * fix E2E tests * fix E2E tests * fix E2E tests * restore global setup file * fix E2E tests * fix global setup * try now * try now * fix E2E test * fix E2E test * fix mini cart E2E test * add changelog * complete all the jobs * update playwright * fix E2E tests * fix E2E test * try now * fix E2E test * not show welcome guide for the post editor * update configuration * fix guest storage state * fix E2E tests * check now * fix E2E tests * fix command * improve selector * use WordPress 6.5 beta 2 * use WordPress 6.5 beta 3 * fix canvas use * wait for button * fix E2E test * fix E2E test * fix product button * fix product collection tests * fix wp build link * use beforeEach * fix E2E tests * use WordPress RC2 * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * trigger CI * fix E2E tests * fix E2E tests * fix E2E test * fix E2E tests * add timeout * Fix flaky locator assertions ...by replacing them with dedicaed auto-waiting ones. * Apply correct use of waitForRequest/Response and remove where unnecessary * Remove obsolete waitUntils * Fix accidentally isolated test * Replace saveTemplate with core's saveSiteEditorEntities * Fix findProductRow util * Restore necessary request waiters * Use activateTheme util instead of cli call * Remove unused import * Fix request destructured call Request properties cannot be destructured (todo: create upstream issue) * Revert some waitForRequest changes These need to be investigated for heavy bleeding from side-effects * Fix failing cart checkout test * Set navigation timeout to 10s We need this so that API like page.goto or page.waitForURL doesn't take 100 seconds (global timeout) to throw. * Do not close the page in the page fixture override The page will be closed anyway, and by closing it explicitly in the teardown phase of the fixture we create a flaky race condition where the page might be closed before the action/navigation timeout is reached, resulting in "page closed!" error instead of, e.g. "locator.fill timed out". * Revert product collection tests due to conflicts * Try fixing E2E test * Remove some random change * Revert to programmatic blur :shrug: * Fix additional checkout fields test * Add a waitForRequest safety check in case it's debounced * Fix price filter test * Fix flaky visitTemplateEditor util * Remove obsolete code from global setup * Revert "Fix flaky visitTemplateEditor util" This reverts commit 227336f2653eb17b37ade45634374d69ef221c50. * update to WordPress RC3 * Add waitForCustomerDataUpdate function * Don't wait for requests and use data store instead * Try with new wait condition * Re-add wait condition * Wait for customer update in guest checkout test * Add changelog * fix lint error * fix some E2E tests * disable welcome guide * remove beforeAll * add timeout * add another timeout * increase timeout * Add call to waitForSiteEditorFinishLoading when editing the theme template * remove timeout * remove not necessary comment * clean changelog * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * remove changelog --------- Co-authored-by: Jon Lane <jon.lane@automattic.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Bart Kalisz <bartlomiej.kalisz@gmail.com> Co-authored-by: Karol Manijak <20098064+kmanijak@users.noreply.github.com> Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com> Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
2024-03-27 09:54:44 +00:00
content: content?.raw,
source: 'theme',
},
headers: {
'X-WP-Nonce': storageState.nonce,
},
}
);
}
async getTemplates() {
const storageState = JSON.parse(
await fs.readFile( STORAGE_STATE_PATH, 'utf-8' )
);
const requestUtils = await this.request.newContext( {
baseURL: BASE_URL,
storageState: storageState && {
cookies: storageState.cookies,
origins: [],
},
} );
const response = await requestUtils.get( `/wp-json/wp/v2/templates`, {
headers: {
'X-WP-Nonce': storageState.nonce,
},
} );
return await response.json();
}
}