Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E tests: Dashboard - Edit Free Listings #2080

Merged
merged 25 commits into from
Aug 31, 2023
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
68d76b3
Add filter to override DB options
jorgemd24 Aug 29, 2023
edbd0cd
Add action to simulate GLA onboarded
jorgemd24 Aug 29, 2023
251de35
Add Mock Requests Utility class
jorgemd24 Aug 29, 2023
acd00aa
Create Dashboard Page
jorgemd24 Aug 29, 2023
280b8f8
Add edit free-listings page
jorgemd24 Aug 29, 2023
f76fb1d
Add edit free listings test
jorgemd24 Aug 29, 2023
551b385
Rename onboarded function and move the method to mock requests class
jorgemd24 Aug 29, 2023
d722ba4
Remove unnecessary spaces
jorgemd24 Aug 29, 2023
0a84f51
Fix phpcs
jorgemd24 Aug 29, 2023
9c5010d
Fix js linting
jorgemd24 Aug 29, 2023
82fdb76
Merge branch 'develop' into dev/dashboard-e2e-tests
jorgemd24 Aug 30, 2023
d3b3448
Add endpoints to simulate onboarded merchant
jorgemd24 Aug 30, 2023
0664818
Remove filter to simulate options values
jorgemd24 Aug 30, 2023
d520d8b
Use the test API to simulate onboarded merchant
jorgemd24 Aug 30, 2023
c5942d6
Add onBoarded functions
jorgemd24 Aug 30, 2023
a19a8a8
Remove old mockOnboarded method as we will use the test API to simula…
jorgemd24 Aug 30, 2023
d68f4d7
Set the number of workers to 1
jorgemd24 Aug 30, 2023
4b4f063
Adding missing awaits
jorgemd24 Aug 30, 2023
62f6270
Fix js lint
jorgemd24 Aug 30, 2023
097f2fb
Fix misspelling targetAudienceRequest
jorgemd24 Aug 31, 2023
e68a11e
Mock saving settings sync request
jorgemd24 Aug 31, 2023
819250b
Move EditFreeListings page in beforeAll
jorgemd24 Aug 31, 2023
5a9c0e2
Test the snackbar message after the settings have been saved
jorgemd24 Aug 31, 2023
3e7fbdb
Reorder imports
jorgemd24 Aug 31, 2023
d0c9172
Add missing return JSDOC
jorgemd24 Aug 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions tests/e2e/utils/pages/edit-free-listings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
export default class EditFreeListingsPage {
/**
* @param {import('@playwright/test').Page} page
*/
constructor( page ) {
this.page = page;
}

/**
* Get Save Changes button. *
* @returns {Promise<import('@playwright/test').Locator>}
*/
async getSaveChangesButton() {
return this.page.getByRole( 'button', {
name: 'Save changes',
exact: true,
} );
}

/**
* Click the Save Changes button.
* @returns {Promise<void>}
*/
async clickSaveChanges() {
const saveChangesButton = await this.getSaveChangesButton();
saveChangesButton.click();
jorgemd24 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Check the recommended shipping settings.
* @returns {Promise<void>}
*/
async checkRecommendShippingSettings() {
return this.page
.locator(
'text=Recommended: Automatically sync my store’s shipping settings to Google.'
)
.check();
}
/**
* Fill the countries shipping time input.
* @param {String} input The shipping time
* @returns {Promise<void>}
*/
async fillCountriesShippingTimeInput( input ) {
await this.page.locator( '.countries-time input' ).fill( input );
}

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

/**
* Register the requests when the save button is clicked.
* @returns {Promise<import('@playwright/test').Request[]>}
*/
registerSavingRequests() {
const targetAudienteRequest = this.page.waitForRequest(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: should be "Audience".

( request ) =>
request.url().includes( '/gla/mc/target_audience' ) &&
request.method() === 'POST' &&
request.postDataJSON().countries[ 0 ] === 'US'
);
const settingsRequest = this.page.waitForRequest(
( request ) =>
request.url().includes( '/gla/mc/settings' ) &&
request.method() === 'POST' &&
request.postDataJSON().shipping_rate === 'automatic' &&
request.postDataJSON().shipping_time === 'flat'
);

const syncRequest = this.page.waitForRequest(
( request ) =>
request.url().includes( '/gla/mc/settings/sync' ) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❔We didn't mock this request /gla/mc/settings/sync and by running npm run test:e2e-dev tests/e2e/specs/dashboard/edit-free-listings.test.js I saw this request returned 500 server error with the message Please reconnect your Jetpack account.. Although the test still passed since we only check the response from gla/mc/settings API, do you think it'd be a good idea to mock /gla/mc/settings/sync API so it wouldn't respond the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first, I didn't mock the response because I believed there wasn't much to test. But now I realize we can actually verify the message in the snackbar. See here: 5a9c0e2

request.method() === 'POST'
);

return Promise.all( [
settingsRequest,
targetAudienteRequest,
syncRequest,
] );
}
}