Skip to content

Commit

Permalink
Update E2E tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
eason9487 committed Jan 6, 2025
1 parent 43d27ec commit 1fc72e0
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 168 deletions.
105 changes: 0 additions & 105 deletions tests/e2e/specs/dashboard/edit-free-listings.test.js

This file was deleted.

3 changes: 2 additions & 1 deletion tests/e2e/specs/settings/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ test.describe( 'Settings', () => {
// Mock the country where the store is located as outside of the US.
const once = settingsPage.fulfillTimes( 1 );
await once.fulfillRequest(
/\/wc-admin\/options\?options=woocommerce_default_country\b/,
// Having`(\w+%2C)*` is because multiple option queries may be consolidated into a single request.
/\/wc-admin\/options\?options=(\w+%2C)*woocommerce_default_country\b/,
{ woocommerce_default_country: 'JP' }
);
await settingsPage.mockTargetAudienceCountries( 'JP' );
Expand Down
73 changes: 73 additions & 0 deletions tests/e2e/specs/shipping.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* External dependencies
*/
import { expect, test } from '@playwright/test';

/**
* Internal dependencies
*/
import { clearOnboardedMerchant, setOnboardedMerchant } from '../utils/api';
import { checkSnackBarMessage } from '../utils/page';
import ShippingPage from '../utils/pages/shipping';

test.use( { storageState: process.env.ADMINSTATE } );

test.describe.configure( { mode: 'serial' } );

/**
* @type {import('../../utils/pages/shipping.js').default} shippingPage
*/
let shippingPage = null;

/**
* @type {import('@playwright/test').Page} page
*/
let page = null;

test.describe( 'Shipping', () => {
test.beforeAll( async ( { browser } ) => {
page = await browser.newPage();
shippingPage = new ShippingPage( page );

await setOnboardedMerchant();
await shippingPage.mockRequests();
await shippingPage.goto();
} );

test.afterAll( async () => {
await clearOnboardedMerchant();
await page.close();
} );

test.skip( 'Should show confirmation modal before saving', async () => {
// TODO: This test case will be completed in a subsequent PR
await shippingPage.clickSaveChanges();
} );

test( 'Check recommended shipping settings', async () => {
await shippingPage.checkRecommendShippingSettings();
await shippingPage.fillCountriesShippingTimeInput( '5', '10' );
const saveChangesButton = await shippingPage.getSaveChangesButton();
await expect( saveChangesButton ).toBeEnabled();
} );

test( 'Save changes', async () => {
const awaitForRequests = shippingPage.registerSavingRequests();
await shippingPage.clickSaveChanges();
const requests = await awaitForRequests;
const settingsResponse = await (
await requests[ 0 ].response()
).json();

expect( settingsResponse.status ).toBe( 'success' );
expect( settingsResponse.message ).toBe(
'Merchant Center Settings successfully updated.'
);
expect( settingsResponse.data.shipping_time ).toBe( 'flat' );

await checkSnackBarMessage(
page,
'Your changes have been saved and will be synced to your Google Merchant Center account.'
);
} );
} );
49 changes: 0 additions & 49 deletions tests/e2e/utils/pages/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ export default class DashboardPage extends MockRequests {
constructor( page ) {
super( page );
this.page = page;
this.freeListingRow = this.page.locator(
'.gla-all-programs-table-card table tr:nth-child(2)'
);
this.editFreeListingButton = this.freeListingRow.getByRole( 'button', {
name: 'Edit',
} );
this.googleAdsSummaryCard = this.page.locator(
'.gla-dashboard__performance .gla-summary-card:nth-child(1)'
);
Expand Down Expand Up @@ -112,47 +106,4 @@ export default class DashboardPage extends MockRequests {
{ waitUntil: LOAD_STATE.DOM_CONTENT_LOADED }
);
}

/**
* Click the edit free listings button.
*
* @return {Promise<void>}
*/
async clickEditFreeListings() {
await this.editFreeListingButton.click();
}

/**
* Get the continue to edit button from the modal.
*
* @return {Promise<import('@playwright/test').Locator>} Get the continue to edit button from the modal.
*/
async getContinueToEditButton() {
return this.page.getByRole( 'button', {
name: 'Continue to edit',
exact: true,
} );
}

/**
* Get the don't edit button from the modal.
*
* @return {Promise<import('@playwright/test').Locator>} Get the don't edit button from the modal.
*/
async getDontEditButton() {
return this.page.getByRole( 'button', {
name: "Don't edit",
exact: true,
} );
}

/**
* Click the continue to edit button from the modal.
*
* @return {Promise<void>}
*/
async clickContinueToEditButton() {
const continueToEditButton = await this.getContinueToEditButton();
await continueToEditButton.click();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* Internal dependencies
*/
import MockRequests from '../mock-requests';
import { LOAD_STATE } from '../constants';

export default class EditFreeListingsPage extends MockRequests {
export default class ShippingPage extends MockRequests {
/**
* @param {import('@playwright/test').Page} page
*/
Expand All @@ -12,6 +13,39 @@ export default class EditFreeListingsPage extends MockRequests {
this.page = page;
}

/**
* Mock all requests related to external resources.
*
* @return {Promise<void>}
*/
async mockRequests() {
await this.mockSuccessfulSettingsSyncRequest();

await this.fulfillSettings( {
shipping_rate: 'flat',
tax_rate: 'destination',
} );

await this.fulfillTargetAudience( {
location: 'selected',
countries: [ 'US' ],
locale: 'en_US',
language: 'English',
} );
}

/**
* Go to the Shipping page.
*
* @return {Promise<void>}
*/
async goto() {
await this.page.goto(
'/wp-admin/admin.php?page=wc-admin&path=%2Fgoogle%2Fshipping',
{ waitUntil: LOAD_STATE.DOM_CONTENT_LOADED }
);
}

/**
* Get Save Changes button.
*
Expand Down Expand Up @@ -59,18 +93,6 @@ export default class EditFreeListingsPage extends MockRequests {
await timesLocator.last().fill( max );
}

/**
* Mock the successful saving settings response.
*
* @return {Promise<void>}
*/
async mockSuccessfulSavingSettingsResponse() {
await this.fulfillSettingsSync( {
status: 'success',
message: 'Successfully synchronized settings with Google.',
} );
}

/**
* Register the requests when the save button is clicked.
*
Expand Down

0 comments on commit 1fc72e0

Please sign in to comment.