Skip to content

Commit

Permalink
@pages/BO/modules/moduleManager : Add router to go to the ModuleManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Jul 4, 2024
1 parent 43dbc11 commit 9c546e9
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export {default as FakerZone} from '@data/faker/zone';
export * as CommonPage from '@pages/commonPage';
// Export Pages BO
export * as BOBasePage from '@pages/BO/BOBasePage';
export {default as boRouterPage} from '@pages/BO/BORouterPage';
export {default as boLoginPage} from '@pages/BO/login';
export {default as boDashboardPage} from '@pages/BO/dashboard';
export {default as boDesignPositionsPage} from '@pages/BO/design/positions/index';
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/BO/modules/moduleManager/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import type {Page} from '@playwright/test';

export interface ModuleManagerSelectionPageInterface extends BOBasePagePageInterface {
readonly installMessageSuccessful: (moduleTag: string) => string;
readonly pageTitle: string;

goToTabSelection(page: Page): Promise<void>;
goToTabInstalledModules(page: Page): Promise<void>;
installModule(page: Page, moduleTag: string): Promise<boolean>;
}
6 changes: 6 additions & 0 deletions src/interfaces/BO/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type {BOBasePagePageInterface} from '@interfaces/BO/index';
import type {Frame, Page} from '@playwright/test';

export interface BORouterPageInterface extends BOBasePagePageInterface {
goToModuleManagerPage(page: Page): Promise<void>;
}
31 changes: 20 additions & 11 deletions src/pages/BO/BOBasePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -731,22 +731,31 @@ export default class BOBasePage extends CommonPage implements BOBasePagePageInte
* @returns {Promise<void>}
*/
async goToSubMenu(page: Page, parentSelector: string, linkSelector: string): Promise<void> {
await this.clickSubMenu(page, parentSelector);
await this.scrollTo(page, linkSelector);
await this.clickAndWaitForURL(page, linkSelector);
const psVersion = testContext.getPSVersion();

const shopVersion = testContext.getPSVersion();
let linkActiveClass: string = '-active';

// >= 1.7.8.0
if (semver.gte(shopVersion, '7.8.0')) {
linkActiveClass = 'link-active';
}
// >= 1.7.4.0
if (semver.gte(psVersion, '7.4.0')) {
await this.clickSubMenu(page, parentSelector);
await this.scrollTo(page, linkSelector);
await this.clickAndWaitForURL(page, linkSelector);

if (await this.isSidebarCollapsed(page)) {
await this.waitForHiddenSelector(page, `${linkSelector}.${linkActiveClass}`);
// >= 1.7.8.0
if (semver.gte(psVersion, '7.8.0')) {
linkActiveClass = 'link-active';
}

if (await this.isSidebarCollapsed(page)) {
await this.waitForHiddenSelector(page, `${linkSelector}.${linkActiveClass}`);
} else {
await this.waitForVisibleSelector(page, `${linkSelector}.${linkActiveClass}`);
}
} else {
await this.waitForVisibleSelector(page, `${linkSelector}.${linkActiveClass}`);
await page.locator(parentSelector).hover();
await this.waitForVisibleSelector(page, linkSelector);
await this.clickAndWaitForURL(page, linkSelector);
await this.waitForVisibleSelector(page, `${parentSelector}.${linkActiveClass}`);
}
}

Expand Down
35 changes: 35 additions & 0 deletions src/pages/BO/BORouterPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {BORouterPageInterface} from '@interfaces/BO/router';
import BOBasePage from '@pages/BO/BOBasePage';
import boDashboardPage from '@pages/BO/dashboard/index';
import boModuleManagerPage from '@pages/BO/modules/moduleManager/index';
import boModuleManagerSelectionPage from '@pages/BO/modules/moduleManager/selection';
import testContext from '@utils/testContext';

Check failure on line 6 in src/pages/BO/BORouterPage.ts

View workflow job for this annotation

GitHub Actions / TypeScript Check

Cannot find module '@utils/testContext' or its corresponding type declarations.

Check failure on line 6 in src/pages/BO/BORouterPage.ts

View workflow job for this annotation

GitHub Actions / ESLint

Cannot find module '@utils/testContext' or its corresponding type declarations.
import type {Page} from 'playwright-core';
import semver from 'semver';

class BORouterPage extends BOBasePage implements BORouterPageInterface {
async goToModuleManagerPage(page: Page): Promise<void> {
const psVersion = testContext.getPSVersion();
const pageTitle = await this.getPageTitle(page);
const boModuleManagerLinkPageTitle = semver.lt(psVersion, '7.4.0')
? boModuleManagerSelectionPage.pageTitle
: boModuleManagerPage.pageTitle;

// Check if we are not already on the page
if (!pageTitle.includes(boModuleManagerLinkPageTitle)) {
await boDashboardPage.goToSubMenu(
page,
boDashboardPage.modulesParentLink,
boDashboardPage.moduleManagerLink,
);
await boDashboardPage.closeSfToolBar(page);
}

if (semver.lt(psVersion, '7.4.0')) {
console.log('goToTabInstalledModules');
await boModuleManagerSelectionPage.goToTabInstalledModules(page);
}
}
}

export default new BORouterPage();
5 changes: 4 additions & 1 deletion src/pages/BO/modules/moduleManager/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ function requirePage(): ModuleManagerSelectionPageInterface {
if (semver.gte(psVersion, '7.5.0')) {
return require('@versions/mock/pages/BO/modules/moduleManager/selection');
}
return require('@versions/1.7.4/pages/BO/modules/moduleManager/selection');
if (semver.gte(psVersion, '7.4.0')) {
return require('@versions/1.7.4/pages/BO/modules/moduleManager/selection').selectionPage;
}
return require('@versions/1.7.3/pages/BO/modules/moduleManager/selection');
}
/* eslint-enable global-require, @typescript-eslint/no-var-requires */

Expand Down
4 changes: 2 additions & 2 deletions src/pages/FO/FOBasePage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Import pages
import {FOBasePagePageInterface} from '@interfaces/FO';
import CommonPage from '@pages/commonPage';
import testContext from '@utils/testContext';
import utilsTest from '@utils/test';
import type {Locator, Page} from 'playwright';
import semver from 'semver';

Expand Down Expand Up @@ -792,7 +792,7 @@ export default class FOBasePage extends CommonPage implements FOBasePagePageInte
}

private getLanguageSelector(page: Page, lang: string): string|Locator {
const psVersion = testContext.getPSVersion();
const psVersion = utilsTest.getPSVersion();

// >= 1.7.5.0
if (semver.gte(psVersion, '7.5.0')) {
Expand Down
43 changes: 43 additions & 0 deletions src/versions/1.7.3/pages/BO/modules/moduleManager/selection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {ModuleManagerSelectionPageInterface} from '@interfaces/BO/modules/moduleManager/selection';
import {Page} from '@playwright/test';
import {SelectionPage} from '@versions/1.7.4/pages/BO/modules/moduleManager/selection';

/**
* @class
* @extends BOBasePage
*/
class SelectionPageVersion extends SelectionPage implements ModuleManagerSelectionPageInterface {
/**
* @constructs
* Setting up titles and selectors to use on module catalog page
*/
constructor() {
super();

// Selectors
this.subTabSelection = '#head_tabs a.tab:nth-child(1)';
this.subTabInstalledModules = '#head_tabs a.tab:nth-child(2)';
}

/**
* Go to the "Selection" tab
* @param {Page} page
* @returns {Promise<void>}
*/
async goToTabSelection(page: Page): Promise<void> {
await this.waitForSelectorAndClick(page, this.subTabSelection);
await this.waitForVisibleSelector(page, `${this.subTabSelection}.current`, 2000);
}

/**
* Go to the "Installed Modules" tab
* @param {Page} page
* @returns {Promise<void>}
*/
async goToTabInstalledModules(page: Page): Promise<void> {
await this.waitForSelectorAndClick(page, this.subTabInstalledModules);
await this.waitForVisibleSelector(page, `${this.subTabInstalledModules}.current`, 2000);
}
}

module.exports = new SelectionPageVersion();
28 changes: 23 additions & 5 deletions src/versions/1.7.4/pages/BO/modules/moduleManager/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import {Page} from '@playwright/test';
* @extends BOBasePage
*/
class SelectionPage extends BOBasePage implements ModuleManagerSelectionPageInterface {
public readonly pageTitle: string;

public readonly installMessageSuccessful: (moduleTag: string) => string;

private readonly subTabUninstalledModules: string;
protected subTabSelection: string;

protected subTabInstalledModules: string;

private readonly searchInput: string;

Expand All @@ -24,10 +28,13 @@ class SelectionPage extends BOBasePage implements ModuleManagerSelectionPageInte
constructor() {
super();

this.pageTitle = 'Module selection';

this.installMessageSuccessful = (moduleTag: string) => `Install action on module ${moduleTag} succeeded.`;

// Selectors
this.subTabUninstalledModules = '#subtab-AdminModulesCatalog';
this.subTabSelection = '#subtab-AdminModulesCatalog';
this.subTabInstalledModules = '#subtab-AdminModulesManage';
this.searchInput = '#search-input-group input.pstaggerAddTagInput';
this.searchButton = '#module-search-button';
this.installModuleButton = (moduleTag: string) => `div[data-tech-name="${moduleTag}"] button.module_action_menu_install`;
Expand All @@ -42,8 +49,18 @@ class SelectionPage extends BOBasePage implements ModuleManagerSelectionPageInte
* @returns {Promise<void>}
*/
async goToTabSelection(page: Page): Promise<void> {
await this.waitForSelectorAndClick(page, this.subTabUninstalledModules);
await this.waitForVisibleSelector(page, `${this.subTabUninstalledModules}.active`, 2000);
await this.waitForSelectorAndClick(page, this.subTabSelection);
await this.waitForVisibleSelector(page, `${this.subTabSelection}.active`, 2000);
}

/**
* Go to the "Selection" tab
* @param {Page} page
* @returns {Promise<void>}
*/
async goToTabInstalledModules(page: Page): Promise<void> {
await this.waitForSelectorAndClick(page, this.subTabInstalledModules);
await this.waitForVisibleSelector(page, `${this.subTabInstalledModules}.active`, 2000);
}

/**
Expand All @@ -62,4 +79,5 @@ class SelectionPage extends BOBasePage implements ModuleManagerSelectionPageInte
}
}

module.exports = new SelectionPage();
const selectionPage = new SelectionPage();
export {selectionPage, SelectionPage};
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ class ModuleManagerPage extends BOBasePage implements ModuleManagerPageInterface

if (cancel) {
await this.waitForSelectorAndClick(page, this.modalConfirmCancel(module.tag, action));
await this.elementNotVisible(page, this.modalConfirmAction(module.tag, action), 10000);
await this.waitForHiddenSelector(page, this.modalConfirmAction(module.tag, action), 10000);
return '';
}
if (action === 'uninstall' && forceDeletion) {
Expand Down
11 changes: 11 additions & 0 deletions src/versions/mock/pages/BO/modules/moduleManager/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import BOBasePage from '@pages/BO/BOBasePage';
* @extends BOBasePage
*/
class SelectionPageMock extends BOBasePage implements ModuleManagerSelectionPageInterface {
public readonly pageTitle: string;

public readonly installMessageSuccessful: (moduleTag: string) => string;

/**
Expand All @@ -16,6 +18,7 @@ class SelectionPageMock extends BOBasePage implements ModuleManagerSelectionPage
constructor() {
super();

this.pageTitle = '';
this.installMessageSuccessful = () => '';
}

Expand All @@ -30,6 +33,14 @@ class SelectionPageMock extends BOBasePage implements ModuleManagerSelectionPage
// do nothing.
}

/**
* Go to the "Installed Modules" tab
* @returns {Promise<void>}
*/
async goToTabInstalledModules(): Promise<void> {
// do nothing.
}

/**
* Install the module and return if installed
* @returns {Promise<boolean>}
Expand Down

0 comments on commit 9c546e9

Please sign in to comment.