From cbef884076c375c8fc38b926b2faaad31bbb2d6e Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Fri, 28 Feb 2025 09:46:04 +0100 Subject: [PATCH] Migrate `@pages/BO/international/localization/geolocation` from Core --- src/index.ts | 1 + .../international/localization/geolocation.ts | 15 +++ .../international/localization/geolocation.ts | 9 ++ .../international/localization/geolocation.ts | 121 ++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 src/interfaces/BO/international/localization/geolocation.ts create mode 100644 src/pages/BO/international/localization/geolocation.ts create mode 100644 src/versions/develop/pages/BO/international/localization/geolocation.ts diff --git a/src/index.ts b/src/index.ts index 74b1eaaa..b963ec07 100644 --- a/src/index.ts +++ b/src/index.ts @@ -248,6 +248,7 @@ export {default as boFeaturesValueCreatePage} from '@pages/BO/catalog/features/c export {default as boFeaturesViewPage} from '@pages/BO/catalog/features/view'; export {default as boFilesPage} from '@pages/BO/catalog/files'; export {default as boFilesCreatePage} from '@pages/BO/catalog/files/create'; +export {default as boGeolocationPage} from '@pages/BO/international/localization/geolocation'; export {default as boInformationPage} from '@pages/BO/advancedParameters/information'; export {default as boImageSettingsPage} from '@pages/BO/design/imageSettings'; export {default as boImageSettingsCreatePage} from '@pages/BO/design/imageSettings/create'; diff --git a/src/interfaces/BO/international/localization/geolocation.ts b/src/interfaces/BO/international/localization/geolocation.ts new file mode 100644 index 00000000..5860607d --- /dev/null +++ b/src/interfaces/BO/international/localization/geolocation.ts @@ -0,0 +1,15 @@ +import {type BOLocalizationBasePageInterface} from '@interfaces/BO/international/localization/base'; +import type {Page} from '@playwright/test'; + +export interface BOGeolocationPageInterface extends BOLocalizationBasePageInterface { + readonly messageGeolocationDBUnavailable: string; + readonly messageWarningNeedDB: string; + readonly pageTitle: string; + + getWarningMessage(page: Page): Promise; + getWhiteListedIPAddresses(page: Page): Promise; + saveFormGeolocationByIPAddress(page: Page): Promise; + saveFormIPAddressesWhitelist(page: Page): Promise; + setGeolocationByIPAddressStatus(page: Page, status: boolean): Promise; + setWhiteListedIPAddresses(page: Page, whitelist: string): Promise; +} diff --git a/src/pages/BO/international/localization/geolocation.ts b/src/pages/BO/international/localization/geolocation.ts new file mode 100644 index 00000000..d51ef820 --- /dev/null +++ b/src/pages/BO/international/localization/geolocation.ts @@ -0,0 +1,9 @@ +import {type BOGeolocationPageInterface} from '@interfaces/BO/international/localization/geolocation'; + +/* eslint-disable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */ +function requirePage(): BOGeolocationPageInterface { + return require('@versions/develop/pages/BO/international/localization/geolocation'); +} +/* eslint-enable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */ + +export default requirePage(); diff --git a/src/versions/develop/pages/BO/international/localization/geolocation.ts b/src/versions/develop/pages/BO/international/localization/geolocation.ts new file mode 100644 index 00000000..8a9a4cb9 --- /dev/null +++ b/src/versions/develop/pages/BO/international/localization/geolocation.ts @@ -0,0 +1,121 @@ +import {type BOGeolocationPageInterface} from '@interfaces/BO/international/localization/geolocation'; +import BOLocalizationBasePage from '@pages/BO/international/localization/base'; +import {type Page} from '@playwright/test'; + +/** + * Geolocation page, contains functions that can be used on the page + * @class + * @extends LocalizationBasePage + */ +class BOGeolocationPage extends BOLocalizationBasePage implements BOGeolocationPageInterface { + public readonly pageTitle: string; + + public readonly messageWarningNeedDB: string; + + public readonly messageGeolocationDBUnavailable: string; + + private readonly warningMessage: string; + + private readonly geolocationByIPAddressForm: string; + + private readonly golocationByIPAddressInput: (status: boolean) => string; + + private readonly geolocationByIPAddressSaveButton: string; + + private readonly ipAddressWhiteForm: string; + + private readonly golocationByIPAddressTextarea: string; + + private readonly ipAddressWhiteSaveButton: string; + + /** + * @constructs + * Setting up texts and selectors to use on localization page + */ + constructor() { + super(); + + this.successfulUpdateMessage = 'Update successful'; + + this.pageTitle = `Geolocation • ${global.INSTALL.SHOP_NAME}`; + this.messageWarningNeedDB = 'Since December 30, 2019, you need to register for a MaxMind account to get a license key to be' + + ' able to download the geolocation data. Once downloaded, extract the data using Winrar or Gzip into the ' + + '/app/Resources/geoip/ directory.'; + this.messageGeolocationDBUnavailable = 'The geolocation database is unavailable.'; + this.warningMessage = 'div#main-div div.alert-warning span.alert-text'; + + // Geolocation By IP Address + this.geolocationByIPAddressForm = 'form[name="geolocation_by_ip_address"]'; + this.golocationByIPAddressInput = (status: boolean) => `${this.geolocationByIPAddressForm} ` + + `#geolocation_by_ip_address_geolocation_enabled_${status ? 1 : 0}`; + this.geolocationByIPAddressSaveButton = `${this.geolocationByIPAddressForm} .card-footer button`; + + // IP address whitelist + this.ipAddressWhiteForm = 'form[name="geolocation_whitelist"]'; + this.golocationByIPAddressTextarea = `${this.ipAddressWhiteForm} #geolocation_whitelist_geolocation_whitelist`; + this.ipAddressWhiteSaveButton = `${this.ipAddressWhiteForm} .card-footer button`; + } + + /* Methods */ + /** + * Enable/Disable the Geolocation By IP Address + * @param page {Page} Browser tab + * @param status {boolean} Enable/Disable + * @return {Promise} + */ + async setGeolocationByIPAddressStatus(page: Page, status: boolean): Promise { + await this.setChecked(page, this.golocationByIPAddressInput(status), true); + } + + /** + * Save the form Geolocation By IP Address + * @param page {Page} Browser tab + * @return {Promise} + */ + async saveFormGeolocationByIPAddress(page: Page): Promise { + await page.locator(this.geolocationByIPAddressSaveButton).click(); + + return this.getAlertBlockContent(page); + } + + /** + * Get the whitelisted IP Addresses list + * @param page {Page} Browser tab + * @return {Promise} + */ + async getWhiteListedIPAddresses(page: Page): Promise { + return this.getTextContent(page, this.golocationByIPAddressTextarea, true, false); + } + + /** + * Set the whitelisted IP Addresses list + * @param page {Page} Browser tab + * @param whitelist {string} The whitelist + * @return {Promise} + */ + async setWhiteListedIPAddresses(page: Page, whitelist: string): Promise { + await this.setValue(page, this.golocationByIPAddressTextarea, whitelist); + } + + /** + * Save the form IP Address Whitelist + * @param page {Page} Browser tab + * @return {Promise} + */ + async saveFormIPAddressesWhitelist(page: Page): Promise { + await page.locator(this.ipAddressWhiteSaveButton).click(); + + return this.getAlertBlockContent(page); + } + + /** + * Get the warning message + * @param page {Page} browser tab + * @returns {Promise} + */ + async getWarningMessage(page: Page): Promise { + return this.getTextContent(page, this.warningMessage); + } +} + +module.exports = new BOGeolocationPage();