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 3, 2025
1 parent fdd48bd commit 1eda2d7
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 12 deletions.
1 change: 0 additions & 1 deletion tests/e2e/specs/dashboard/edit-free-listings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ test.describe( 'Edit Free Listings', () => {
test( 'Check recommended shipping settings', async () => {
await editFreeListingsPage.checkRecommendShippingSettings();
await editFreeListingsPage.fillCountriesShippingTimeInput( '5', '10' );
await editFreeListingsPage.checkDestinationBasedTaxRates();
const saveChangesButton =
await editFreeListingsPage.getSaveChangesButton();
await expect( saveChangesButton ).toBeEnabled();
Expand Down
99 changes: 99 additions & 0 deletions tests/e2e/specs/settings/settings.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* External dependencies
*/
import { expect, test } from '@playwright/test';

/**
* Internal dependencies
*/
import { clearOnboardedMerchant, setOnboardedMerchant } from '../../utils/api';
import SettingsPage from '../../utils/pages/settings';

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

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

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

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

test.describe( 'Settings', () => {
test.beforeAll( async ( { browser } ) => {
page = await browser.newPage();
settingsPage = new SettingsPage( page );

await setOnboardedMerchant();
await settingsPage.mockRequests();
} );

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

test.describe( 'Tax rate setup', () => {
test( 'Should not show the setup when selling in regions unrelated to the US', async () => {
// 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/,
{ woocommerce_default_country: 'JP' }
);
await settingsPage.mockTargetAudienceCountries( 'JP' );
await settingsPage.goto();

await expect(
page.getByRole( 'heading', { name: 'Settings' } )
).toBeVisible();

await expect(
page.locator( '.woocommerce-spinner' ).first()
).not.toBeVisible();

await expect(
page.getByText( 'Tax rate (required for U.S. only)' )
).not.toBeVisible();
} );

test( 'Update the setting', async () => {
await settingsPage.mockTargetAudienceCountries();
await settingsPage.goto();

await expect(
page.getByText( 'Tax rate (required for U.S. only)' )
).toBeVisible();

const saveButton = page.getByRole( 'button', {
name: 'Save tax rate',
} );
const saveSpinner = saveButton.locator( '.woocommerce-spinner' );
const option = page.getByRole( 'radio', { checked: false } );
const optionValue = option.getAttribute( 'value' );

// Save button will become clickable after selecting another option.
await expect( saveButton ).toBeDisabled();
await option.check();
await expect( saveButton ).toBeEnabled();

// Submit the change, and then the save button will go through loading state
// and stay disabled both during and after submission.
await saveButton.click();
await expect( saveSpinner ).toBeVisible();
await expect( saveButton ).toBeDisabled();
await expect( saveSpinner ).not.toBeVisible();
await expect( saveButton ).toBeDisabled();

// Reload to assert the setting has been actually saved.
await page.reload();
await expect(
page.getByRole( 'radio', { checked: true } )
).toHaveAttribute( 'value', optionValue );
} );
} );
} );
11 changes: 0 additions & 11 deletions tests/e2e/utils/pages/edit-free-listings.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,6 @@ export default class EditFreeListingsPage extends MockRequests {
await timesLocator.last().fill( max );
}

/**
* Check the destination based tax rates.
*
* @return {Promise<void>}
*/
async checkDestinationBasedTaxRates() {
await this.page
.locator( 'text=My store uses destination-based tax rates.' )
.check();
}

/**
* Mock the successful saving settings response.
*
Expand Down
29 changes: 29 additions & 0 deletions tests/e2e/utils/pages/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,35 @@ export default class SettingsPage extends MockRequests {
);
}

/**
* Mock all requests related to external accounts such as Merchant Center, Google, etc.
*
* @return {Promise<void>}
*/
async mockRequests() {
await this.mockJetpackConnected();
await this.mockGoogleConnected();
await this.mockMCConnected();
await this.mockAdsAccountConnected();
await this.mockContactInformation();
await this.mockSuccessfulSettingsSyncRequest();
}

/**
* Mock the target audience request with the given countries.
*
* @param {Array<string>} [countries=['US']] country codes to be mocked.
* @return {Promise<void>}
*/
async mockTargetAudienceCountries( ...countries ) {
await this.fulfillTargetAudience( {
location: 'selected',
countries: countries.length ? countries : [ 'US' ],
locale: 'en_US',
language: 'English',
} );
}

/**
* Get the Grant Access Button.
*
Expand Down

0 comments on commit 1eda2d7

Please sign in to comment.