-
Notifications
You must be signed in to change notification settings - Fork 21
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
Changes from 10 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
68d76b3
Add filter to override DB options
jorgemd24 edbd0cd
Add action to simulate GLA onboarded
jorgemd24 251de35
Add Mock Requests Utility class
jorgemd24 acd00aa
Create Dashboard Page
jorgemd24 280b8f8
Add edit free-listings page
jorgemd24 f76fb1d
Add edit free listings test
jorgemd24 551b385
Rename onboarded function and move the method to mock requests class
jorgemd24 d722ba4
Remove unnecessary spaces
jorgemd24 0a84f51
Fix phpcs
jorgemd24 9c5010d
Fix js linting
jorgemd24 82fdb76
Merge branch 'develop' into dev/dashboard-e2e-tests
jorgemd24 d3b3448
Add endpoints to simulate onboarded merchant
jorgemd24 0664818
Remove filter to simulate options values
jorgemd24 d520d8b
Use the test API to simulate onboarded merchant
jorgemd24 c5942d6
Add onBoarded functions
jorgemd24 a19a8a8
Remove old mockOnboarded method as we will use the test API to simula…
jorgemd24 d68f4d7
Set the number of workers to 1
jorgemd24 4b4f063
Adding missing awaits
jorgemd24 62f6270
Fix js lint
jorgemd24 097f2fb
Fix misspelling targetAudienceRequest
jorgemd24 e68a11e
Mock saving settings sync request
jorgemd24 819250b
Move EditFreeListings page in beforeAll
jorgemd24 5a9c0e2
Test the snackbar message after the settings have been saved
jorgemd24 3e7fbdb
Reorder imports
jorgemd24 d0c9172
Add missing return JSDOC
jorgemd24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { test, expect } from '@playwright/test'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import DashboardPage from '../../utils/pages/dashboard.js'; | ||
import EditFreeListingsPage from '../../utils/pages/edit-free-listings.js'; | ||
|
||
test.use( { storageState: process.env.ADMINSTATE } ); | ||
|
||
test.describe.configure( { mode: 'serial' } ); | ||
|
||
/** | ||
* @type {import('../../utils/pages/dashboard.js').default} dashboardPage | ||
*/ | ||
let dashboardPage = null; | ||
|
||
/** | ||
* @type {import('../../utils/pages/edit-free-listings.js').default} editFreeListingsPage | ||
*/ | ||
let editFreeListingsPage = null; | ||
|
||
/** | ||
* @type {import('@playwright/test').Page} page | ||
*/ | ||
let page = null; | ||
|
||
test.describe( 'Edit Free Listings', () => { | ||
test.beforeAll( async ( { browser } ) => { | ||
page = await browser.newPage(); | ||
dashboardPage = new DashboardPage( page ); | ||
await dashboardPage.mockOnboarded(); | ||
await dashboardPage.mockRequests(); | ||
await dashboardPage.goto(); | ||
} ); | ||
|
||
test.afterAll( async () => { | ||
await page.close(); | ||
} ); | ||
|
||
test( 'Dashboard page contains Free Listings', async () => { | ||
await expect( dashboardPage.freeListingRow ).toContainText( | ||
'Free listings' | ||
); | ||
|
||
await expect( dashboardPage.editFreeListingButton ).toBeEnabled(); | ||
} ); | ||
|
||
test( 'Edit Free Listings should show modal', async () => { | ||
await dashboardPage.clickEditFreeListings(); | ||
|
||
await page.waitForLoadState( 'domcontentloaded' ); | ||
|
||
const continueToEditButton = await dashboardPage.getContinueToEditButton(); | ||
const dontEditButton = await dashboardPage.getDontEditButton(); | ||
await expect( continueToEditButton ).toBeEnabled(); | ||
await expect( dontEditButton ).toBeEnabled(); | ||
} ); | ||
|
||
test( 'Continue to edit Free listings', async () => { | ||
await dashboardPage.clickContinueToEditButton(); | ||
await page.waitForLoadState( 'domcontentloaded' ); | ||
} ); | ||
|
||
test( 'Check recommended shipping settings', async () => { | ||
editFreeListingsPage = new EditFreeListingsPage( page ); | ||
await editFreeListingsPage.checkRecommendShippingSettings(); | ||
await editFreeListingsPage.fillCountriesShippingTimeInput( '5' ); | ||
await editFreeListingsPage.checkDestinationBasedTaxRates(); | ||
const saveChangesButton = await editFreeListingsPage.getSaveChangesButton(); | ||
await expect( saveChangesButton ).toBeEnabled(); | ||
} ); | ||
|
||
test( 'Save changes', async () => { | ||
const awaitForRequests = editFreeListingsPage.registerSavingRequests(); | ||
await editFreeListingsPage.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' ); | ||
expect( settingsResponse.data.tax_rate ).toBe( 'destination' ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* Mock Requests | ||
* | ||
* This class is used to mock requests to the server. | ||
*/ | ||
export default class MockRequests { | ||
/** | ||
* @param {import('@playwright/test').Page} page | ||
*/ | ||
constructor( page ) { | ||
this.page = page; | ||
} | ||
|
||
/** | ||
* Add the parameter gla-e2e-onboarded to the request to simulate the onboarded state; otherwise, it will redirect to the onboarding page. | ||
* | ||
* @return {Promise<void>} | ||
*/ | ||
async mockOnboarded() { | ||
await this.page.route( /\/admin.php\b/, ( route ) => { | ||
const url = `${ route.request().url() }&gla-e2e-onboarded=true`; | ||
route.continue( { url } ); | ||
} ); | ||
} | ||
|
||
/** | ||
* Fulfill a request with a payload. | ||
* | ||
* @param {RegExp|string} url The url to fulfill. | ||
* @param {Object} payload The payload to send. | ||
* @return {Promise<void>} | ||
*/ | ||
async fulfillRequest( url, payload ) { | ||
await this.page.route( url, ( route ) => | ||
route.fulfill( { | ||
content: 'application/json', | ||
headers: { 'Access-Control-Allow-Origin': '*' }, | ||
body: JSON.stringify( payload ), | ||
} ) | ||
); | ||
} | ||
|
||
/** | ||
* Fulfill the MC Report Program request. | ||
* | ||
* @param {Object} payload | ||
* @return {Promise<void>} | ||
*/ | ||
async fulfillMCReportProgram( payload ) { | ||
await this.fulfillRequest( | ||
/\/wc\/gla\/mc\/reports\/programs\b/, | ||
payload | ||
); | ||
} | ||
|
||
/** | ||
* Fulfill the Target Audience request. | ||
* | ||
* @param {Object} payload | ||
* @return {Promise<void>} | ||
*/ | ||
async fulfillTargetAudience( payload ) { | ||
await this.fulfillRequest( | ||
/\/wc\/gla\/mc\/target_audience\b/, | ||
payload | ||
); | ||
} | ||
|
||
/** | ||
* Fulfill the JetPack Connection request. | ||
* | ||
* @param {Object} payload | ||
* @return {Promise<void>} | ||
*/ | ||
async fulfillJetPackConnection( payload ) { | ||
await this.fulfillRequest( /\/wc\/gla\/jetpack\/connected\b/, payload ); | ||
} | ||
|
||
/** | ||
* Fulfill the Google Connection request. | ||
* | ||
* @param {Object} payload | ||
* @return {Promise<void>} | ||
*/ | ||
async fulfillGoogleConnection( payload ) { | ||
await this.fulfillRequest( /\/wc\/gla\/google\/connected\b/, payload ); | ||
} | ||
|
||
/** | ||
* Fulfill the Ads Connection request. | ||
* | ||
* @param {Object} payload | ||
* @return {Promise<void>} | ||
*/ | ||
async fulfillAdsConnection( payload ) { | ||
await this.fulfillRequest( /\/wc\/gla\/ads\/connection\b/, payload ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import MockRequests from '../mock-requests'; | ||
|
||
/** | ||
* Dashboard page object class. | ||
*/ | ||
export default class DashboardPage extends MockRequests { | ||
/** | ||
* @param {import('@playwright/test').Page} page | ||
*/ | ||
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', | ||
} ); | ||
} | ||
|
||
/** | ||
* Close the current page. | ||
* | ||
* @return {Promise<void>} | ||
*/ | ||
async closePage() { | ||
await this.page.close(); | ||
} | ||
|
||
/** | ||
* Mock all requests related to external accounts such as Merchant Center, Google, etc. | ||
*/ | ||
async mockRequests() { | ||
// Mock Reports Programs | ||
this.fulfillMCReportProgram( { | ||
jorgemd24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
free_listings: null, | ||
products: null, | ||
intervals: null, | ||
totals: { | ||
clicks: 0, | ||
impressions: 0, | ||
}, | ||
next_page: null, | ||
} ); | ||
|
||
this.fulfillTargetAudience( { | ||
location: 'selected', | ||
countries: [ 'US' ], | ||
locale: 'en_US', | ||
language: 'English', | ||
} ); | ||
|
||
this.fulfillJetPackConnection( { | ||
active: 'yes', | ||
owner: 'yes', | ||
displayName: 'John', | ||
email: '[email protected]', | ||
} ); | ||
|
||
this.fulfillGoogleConnection( { | ||
active: 'yes', | ||
email: '[email protected]', | ||
scope: [], | ||
} ); | ||
|
||
this.fulfillAdsConnection( { | ||
id: 0, | ||
currency: null, | ||
symbol: '$', | ||
status: 'disconnected', | ||
} ); | ||
} | ||
|
||
/** | ||
* Go to the dashboard page. | ||
* | ||
* @return {Promise<void>} | ||
*/ | ||
async goto() { | ||
await this.page.goto( | ||
'/wp-admin/admin.php?page=wc-admin&path=%2Fgoogle%2Fdashboard', | ||
{ waitUntil: 'domcontentloaded' } | ||
); | ||
} | ||
|
||
/** | ||
* 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(); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the test is configured to run serial, I think it'd still be better to move this line to
beforeAll()
likedashboardPage
.