diff --git a/tests/e2e/utils/pages/setup-mc/step-2-product-listings.js b/tests/e2e/utils/pages/setup-mc/step-2-product-listings.js new file mode 100644 index 0000000000..0895a3fad2 --- /dev/null +++ b/tests/e2e/utils/pages/setup-mc/step-2-product-listings.js @@ -0,0 +1,514 @@ +/** + * Internal dependencies + */ +import { LOAD_STATE } from '../../constants'; +import MockRequests from '../../mock-requests'; + +/** + * Configure product listings page object class. + */ +export default class ProductListingsPage extends MockRequests { + /** + * @param {import('@playwright/test').Page} page + */ + constructor( page ) { + super( page ); + this.page = page; + } + + /** + * Close the current page. + * + * @return {Promise} + */ + async closePage() { + await this.page.close(); + } + + /** + * Go to the set up mc page. + * + * @return {Promise} + */ + async goto() { + await this.page.goto( + '/wp-admin/admin.php?page=wc-admin&path=%2Fgoogle%2Fsetup-mc&google-mc=connected', + { waitUntil: LOAD_STATE.NETWORK_IDLE } + ); + } + + /** + * Get language radio row. + * + * @return {import('@playwright/test').Locator} Get language radio row. + */ + getLanguageRadioRow() { + return this.page.getByRole( 'radio', { + name: 'English', + exact: true, + } ); + } + + /** + * Get selected countries only radio row. + * + * @return {import('@playwright/test').Locator} Get selected countries only radio row. + */ + getSelectedCountriesOnlyRadioRow() { + return this.page.getByRole( 'radio', { + name: 'Selected countries only', + exact: true, + } ); + } + + /** + * Get all countries radio row. + * + * @return {import('@playwright/test').Locator} Get all countries radio row. + */ + getAllCountriesRadioRow() { + return this.page.getByRole( 'radio', { + name: 'All countries', + exact: true, + } ); + } + + /** + * Get recommended shipping rate radio row. + * + * @return {import('@playwright/test').Locator} Get recommended shipping rate radio row. + */ + getRecommendedShippingRateRadioRow() { + return this.page.getByRole( 'radio', { + name: 'Recommended: Automatically sync my store’s shipping settings to Google.', + exact: true, + } ); + } + + /** + * Get simple shipping rate radio row. + * + * @return {import('@playwright/test').Locator} Get simple shipping rate radio row. + */ + getSimpleShippingRateRadioRow() { + return this.page.getByRole( 'radio', { + name: 'My shipping settings are simple. I can manually estimate flat shipping rates.', + exact: true, + } ); + } + + /** + * Get complex shipping rate radio row. + * + * @return {import('@playwright/test').Locator} Get complex shipping rate radio row. + */ + getComplexShippingRateRadioRow() { + return this.page.getByRole( 'radio', { + name: 'My shipping settings are complex. I will enter my shipping rates and times manually in Google Merchant Center.', + exact: true, + } ); + } + + /** + * Get offer free shipping for order "Yes" button. + * + * @return {import('@playwright/test').Locator} Get offer free shipping for order "Yes" button. + */ + getOfferFreeShippingForOrdersYesRadioRow() { + return this.page.getByRole( 'radio', { + name: 'Yes', + exact: true, + } ); + } + + /** + * Get offer free shipping for order "No" button. + * + * @return {import('@playwright/test').Locator} Get offer free shipping for order "No" button. + */ + getOfferFreeShippingForOrdersNoRadioRow() { + return this.page.getByRole( 'radio', { + name: 'No', + exact: true, + } ); + } + + /** + * Get country input search box container. + * + * @return {import('@playwright/test').Locator} Get country input search box container. + */ + getCountryInputSearchBoxContainer() { + return this.page.locator( + '.woocommerce-tree-select-control > .components-base-control' + ); + } + + /** + * Get country input search box. + * + * @return {import('@playwright/test').Locator} Get country input search box. + */ + getCountryInputSearchBox() { + return this.getCountryInputSearchBoxContainer().locator( + 'input[id*="woocommerce-tree-select-control"]' + ); + } + + /** + * Get tree item by country name. + * + * @param {string} name + * + * @return {import('@playwright/test').Locator} Get tree item by country name. + */ + getTreeItemByCountryName( name = 'United States (US)' ) { + return this.page.getByRole( 'treeitem', { name } ); + } + + /** + * Get remove country button by country name. + * + * @param {string} name + * + * @return {import('@playwright/test').Locator} Get tree item by country name. + */ + getRemoveCountryButtonByName( name = 'United States (US)' ) { + return this.page.getByRole( 'button', { name: `Remove ${ name }` } ); + } + + /** + * Get shipping rates section. + * + * @return {import('@playwright/test').Locator} Get shipping rates section. + */ + getShippingRatesSection() { + return this.page + .locator( 'section' ) + .filter( { hasText: 'Shipping rates' } ); + } + + /** + * Get shipping times section. + * + * @return {import('@playwright/test').Locator} Get shipping times section. + */ + getShippingTimesSection() { + return this.page + .locator( 'section' ) + .filter( { hasText: 'Shipping times' } ); + } + + /** + * Get tax rate section. + * + * @return {import('@playwright/test').Locator} Get tax rate section. + */ + getTaxRateSection() { + return this.page + .locator( 'section' ) + .filter( { hasText: 'Tax rate (required for U.S. only)' } ); + } + + /** + * Get audience card. + * + * @return {import('@playwright/test').Locator} Get audience card. + */ + getAudienceCard() { + return this.page + .locator( '.components-card' ) + .filter( { hasText: 'Selected countries only' } ); + } + + /** + * Get estimated shipping rates card. + * + * @return {import('@playwright/test').Locator} Get estimated shipping rates card. + */ + getEstimatedShippingRatesCard() { + return this.page + .locator( '.components-card' ) + .filter( { hasText: 'Estimated shipping rates' } ); + } + + /** + * Get estimated shipping times card. + * + * @return {import('@playwright/test').Locator} Get estimated shipping times card. + */ + getEstimatedShippingTimesCard() { + return this.page + .locator( '.components-card' ) + .filter( { hasText: 'Estimated shipping times' } ); + } + + /** + * Get estimated shipping rates input box. + * + * @return {import('@playwright/test').Locator} Get estimated shipping rates input box. + */ + getEstimatedShippingRatesInputBox() { + return this.getEstimatedShippingRatesCard().locator( + 'input[id*="inspector-input-control"]' + ); + } + + /** + * Get estimated shipping times input box. + * + * @return {import('@playwright/test').Locator} Get estimated shipping times input box. + */ + getEstimatedShippingTimesInputBox() { + return this.getEstimatedShippingTimesCard().locator( + 'input[id*="inspector-input-control"]' + ); + } + + /** + * Get estimated shipping times error. + * + * @return {import('@playwright/test').Locator} Get estimated shipping times error. + */ + getEstimatedShippingTimesError() { + return this.getEstimatedShippingTimesCard().getByText( + 'Please specify estimated shipping times for all the countries, and the time cannot be less than 0' + ); + } + + /** + * Get "Free shipping for all orders" tag. + * + * @return {import('@playwright/test').Locator} Get "Free shipping for all orders" tag. + */ + getFreeShippingForAllOrdersTag() { + return this.getEstimatedShippingRatesCard().getByText( + 'Free shipping for all orders' + ); + } + + /** + * Get "I offer free shipping for orders over a certain price" text. + * + * @return {import('@playwright/test').Locator} Get "I offer free shipping for orders over a certain price" text. + */ + getOfferFreeShippingForOrdersText() { + return this.page.getByText( + 'I offer free shipping for orders over a certain price' + ); + } + + /** + * Get "Minimum order to qualify for free shipping" text. + * + * @return {import('@playwright/test').Locator} Get "Minimum order to qualify for free shipping" text. + */ + getMinimumOrderForFreeShippingText() { + return this.page.getByText( + 'Minimum order to qualify for free shipping' + ); + } + + /** + * Get "Continue" button. + * + * @return {import('@playwright/test').Locator} Get "Continue" button. + */ + getContinueButton() { + return this.page.getByRole( 'button', { + name: 'Continue', + exact: true, + } ); + } + + /** + * Get "Read more" for Language link. + * + * @return {import('@playwright/test').Locator} Get "Read more" for Language link. + */ + getReadMoreLanguageLink() { + return this.getAudienceCard().getByRole( 'link', { + name: 'Read more', + exact: true, + } ); + } + + /** + * Get "Read more" for Shipping rates link. + * + * @return {import('@playwright/test').Locator} Get "Read more" for Shipping rates link. + */ + getReadMoreShippingRatesLink() { + return this.getShippingRatesSection().getByRole( 'link', { + name: 'Read more', + exact: true, + } ); + } + + /** + * Get "Read more" for Shipping times link. + * + * @return {import('@playwright/test').Locator} Get "Read more" for Shipping times link. + */ + getReadMoreShippingTimesLink() { + return this.getShippingTimesSection().getByRole( 'link', { + name: 'Read more', + exact: true, + } ); + } + + /** + * Get "Read more" for Tax rate link. + * + * @return {import('@playwright/test').Locator} Get "Read more" for Tax rate link. + */ + getReadMoreTaxRateLink() { + return this.getTaxRateSection().getByRole( 'link', { + name: 'Read more', + exact: true, + } ); + } + + /** + * Click "Continue" button. + * + * @return {Promise} + */ + async clickContinueButton() { + const continueButton = this.getContinueButton(); + await continueButton.click(); + await this.page.waitForLoadState( LOAD_STATE.DOM_CONTENT_LOADED ); + } + + /** + * Select a country from the search box. + * + * @param {string} name + * + * @return {Promise} + */ + async selectCountryFromSearchBox( name = 'United States (US)' ) { + const countrySearchBox = this.getCountryInputSearchBox(); + await countrySearchBox.fill( name ); + await this.getTreeItemByCountryName( name ).click(); + await countrySearchBox.press( 'Escape' ); + await this.page.waitForLoadState( LOAD_STATE.DOM_CONTENT_LOADED ); + } + + /** + * Remove a country from the search box. + * + * @param {string} name + * + * @return {Promise} + */ + async removeCountryFromSearchBox( name = 'United States (US)' ) { + const removeButton = this.getRemoveCountryButtonByName( name ); + await removeButton.click(); + await this.page.waitForLoadState( LOAD_STATE.DOM_CONTENT_LOADED ); + } + + /** + * Check all countries radio button. + * + * @return {Promise} + */ + async checkAllCountriesRadioButton() { + const allCountriesRadioRow = this.getAllCountriesRadioRow(); + await allCountriesRadioRow.check(); + await this.page.waitForLoadState( LOAD_STATE.DOM_CONTENT_LOADED ); + } + + /** + * Check selected countries only radio button. + * + * @return {Promise} + */ + async checkSelectedCountriesOnlyRadioButton() { + const selectedCountriesOnlyRadioButton = + this.getSelectedCountriesOnlyRadioRow(); + await selectedCountriesOnlyRadioButton.check(); + await this.page.waitForLoadState( LOAD_STATE.DOM_CONTENT_LOADED ); + } + + /** + * Check recommended shipping rate radio button. + * + * @return {Promise} + */ + async checkRecommendedShippingRateRadioButton() { + const recommendedShippingRateRadioButton = + this.getRecommendedShippingRateRadioRow(); + await recommendedShippingRateRadioButton.check(); + await this.page.waitForLoadState( LOAD_STATE.DOM_CONTENT_LOADED ); + } + + /** + * Check simple shipping rate radio button. + * + * @return {Promise} + */ + async checkSimpleShippingRateRadioButton() { + const simpleShippingRateRadioButton = + this.getSimpleShippingRateRadioRow(); + await simpleShippingRateRadioButton.check(); + await this.page.waitForLoadState( LOAD_STATE.DOM_CONTENT_LOADED ); + } + + /** + * Check simple shipping rate radio button. + * + * @return {Promise} + */ + async checkComplexShippingRateRadioButton() { + const complexShippingRateRadioButton = + this.getComplexShippingRateRadioRow(); + await complexShippingRateRadioButton.check(); + await this.page.waitForLoadState( LOAD_STATE.DOM_CONTENT_LOADED ); + } + + /** + * Check offer free shipping for order "Yes" radio button. + * + * @return {Promise} + */ + async checkOfferFreeShippingForOrdersYesRadioButton() { + const yesRadio = this.getOfferFreeShippingForOrdersYesRadioRow(); + await yesRadio.check(); + await this.page.waitForLoadState( LOAD_STATE.DOM_CONTENT_LOADED ); + } + + /** + * Fill estimated shipping rates. + * + * @param {string} rate + * + * @return {Promise} + */ + async fillEstimatedShippingRates( rate = '0' ) { + const estimatedRatesInputBox = this.getEstimatedShippingRatesInputBox(); + await estimatedRatesInputBox.fill( rate ); + + // A hack to finish typing in the input box, similar to pressing anywhere in the page. + await estimatedRatesInputBox.press( 'Tab' ); + + await this.page.waitForLoadState( LOAD_STATE.DOM_CONTENT_LOADED ); + } + + /** + * Fill estimated shipping times. + * + * @param {string} days + * + * @return {Promise} + */ + async fillEstimatedShippingTimes( days = '0' ) { + const estimatedTimesInputBox = this.getEstimatedShippingTimesInputBox(); + await estimatedTimesInputBox.fill( days ); + + // A hack to finish typing in the input box, similar to pressing anywhere in the page. + await estimatedTimesInputBox.press( 'Tab' ); + + await this.page.waitForLoadState( LOAD_STATE.DOM_CONTENT_LOADED ); + } +}