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

Migrate @pages/BO/international/localization/geolocation from Core #446

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
15 changes: 15 additions & 0 deletions src/interfaces/BO/international/localization/geolocation.ts
Original file line number Diff line number Diff line change
@@ -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<string>;
getWhiteListedIPAddresses(page: Page): Promise<string>;
saveFormGeolocationByIPAddress(page: Page): Promise<string>;
saveFormIPAddressesWhitelist(page: Page): Promise<string>;
setGeolocationByIPAddressStatus(page: Page, status: boolean): Promise<void>;
setWhiteListedIPAddresses(page: Page, whitelist: string): Promise<void>;
}
9 changes: 9 additions & 0 deletions src/pages/BO/international/localization/geolocation.ts
Original file line number Diff line number Diff line change
@@ -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();
Original file line number Diff line number Diff line change
@@ -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<void>}
*/
async setGeolocationByIPAddressStatus(page: Page, status: boolean): Promise<void> {
await this.setChecked(page, this.golocationByIPAddressInput(status), true);
}

/**
* Save the form Geolocation By IP Address
* @param page {Page} Browser tab
* @return {Promise<string>}
*/
async saveFormGeolocationByIPAddress(page: Page): Promise<string> {
await page.locator(this.geolocationByIPAddressSaveButton).click();

return this.getAlertBlockContent(page);
}

/**
* Get the whitelisted IP Addresses list
* @param page {Page} Browser tab
* @return {Promise<string>}
*/
async getWhiteListedIPAddresses(page: Page): Promise<string> {
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<void>}
*/
async setWhiteListedIPAddresses(page: Page, whitelist: string): Promise<void> {
await this.setValue(page, this.golocationByIPAddressTextarea, whitelist);
}

/**
* Save the form IP Address Whitelist
* @param page {Page} Browser tab
* @return {Promise<string>}
*/
async saveFormIPAddressesWhitelist(page: Page): Promise<string> {
await page.locator(this.ipAddressWhiteSaveButton).click();

return this.getAlertBlockContent(page);
}

/**
* Get the warning message
* @param page {Page} browser tab
* @returns {Promise<string>}
*/
async getWarningMessage(page: Page): Promise<string> {
return this.getTextContent(page, this.warningMessage);
}
}

module.exports = new BOGeolocationPage();