-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from Progi1984/boMyProfilePage
Migrate `@pages/BO/advancedParameters/team/myProfile` from Core
- Loading branch information
Showing
7 changed files
with
254 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {BOBasePagePageInterface} from '@interfaces/BO'; | ||
|
||
export interface BOTeamBasePageInterface extends BOBasePagePageInterface { | ||
readonly pageTitleEdit: (firstName: string, lastName: string) => string; | ||
readonly pageTitleEditFr: (firstName: string, lastName: string) => string; | ||
} |
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,15 @@ | ||
import type FakerEmployee from '@data/faker/employee'; | ||
import {type BOTeamBasePageInterface} from '@interfaces/BO/advancedParameters/team/base'; | ||
import type {Page} from '@playwright/test'; | ||
|
||
export interface BOMyProfilePageInterface extends BOTeamBasePageInterface { | ||
readonly errorInvalidFirstNameMessage: string; | ||
readonly errorInvalidFormatImageMessage: string; | ||
readonly errorInvalidLastNameMessage: string; | ||
readonly successfulUpdateMessageFR: string; | ||
|
||
getAlertError(page: Page): Promise<string>; | ||
getAlertSuccess(page: Page): Promise<string>; | ||
isGravatarEnabled(page: Page): Promise<boolean>; | ||
updateEditEmployee(page: Page, currentPassword: string, newEmployeeData: FakerEmployee): Promise<void>; | ||
} |
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,89 @@ | ||
import {type BOTeamBasePageInterface} from '@interfaces/BO/advancedParameters/team/base'; | ||
import BOBasePage from '@pages/BO/BOBasePage'; | ||
import {type Page} from '@playwright/test'; | ||
|
||
/** | ||
* Employee base page, contains functions that can be used on the page | ||
* @class | ||
* @extends BOBasePage | ||
*/ | ||
export default class EmployeeBasePage extends BOBasePage implements BOTeamBasePageInterface { | ||
public readonly pageTitleEdit: (firstName: string, lastName: string) => string; | ||
|
||
public readonly pageTitleEditFr: (firstName: string, lastName: string) => string; | ||
|
||
protected readonly firstNameInput: string; | ||
|
||
protected readonly lastNameInput: string; | ||
|
||
protected readonly emailInput: string; | ||
|
||
private readonly defaultPageSpan: string; | ||
|
||
private readonly searchDefaultPageInput: string; | ||
|
||
protected readonly languageSelect: string; | ||
|
||
protected readonly statusToggleInput: (toggle: number) => string; | ||
|
||
protected readonly permissionProfileSelect: string; | ||
|
||
protected readonly saveButton: string; | ||
|
||
private readonly cancelButton: string; | ||
|
||
/** | ||
* @constructs | ||
* Setting up texts and selectors to use on Employee page | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.pageTitleEdit = (firstName: string, lastName: string) => `Editing ${firstName} ${lastName}'s profile` | ||
+ ` • ${global.INSTALL.SHOP_NAME}`; | ||
this.pageTitleEditFr = (firstName: string, lastName: string) => `Modification du profil de ${firstName} ${lastName}` | ||
+ ` • ${global.INSTALL.SHOP_NAME}`; | ||
|
||
// Selectors | ||
this.firstNameInput = '#employee_firstname'; | ||
this.lastNameInput = '#employee_lastname'; | ||
this.emailInput = '#employee_email'; | ||
this.defaultPageSpan = '.select2-selection[aria-labelledby=\'select2-employee_default_page-container\']'; | ||
this.searchDefaultPageInput = '.select2-search__field'; | ||
this.languageSelect = '#employee_language'; | ||
this.statusToggleInput = (toggle: number) => `#employee_active_${toggle}`; | ||
this.permissionProfileSelect = '#employee_profile'; | ||
this.saveButton = '#save-button'; | ||
this.cancelButton = '#cancel-link'; | ||
} | ||
|
||
/* | ||
Methods | ||
*/ | ||
|
||
/** | ||
* Select default Page | ||
* @param page {Page} Browser tab | ||
* @param defaultPage {string} Page name to set on input | ||
* @returns {Promise<void>} | ||
*/ | ||
async selectDefaultPage(page: Page, defaultPage: string): Promise<void> { | ||
await Promise.all([ | ||
page.locator(this.defaultPageSpan).click(), | ||
this.waitForVisibleSelector(page, `${this.defaultPageSpan}[aria-expanded='true']`), | ||
]); | ||
await this.setValue(page, this.searchDefaultPageInput, defaultPage); | ||
await page.keyboard.press('Enter'); | ||
} | ||
|
||
/** | ||
* Cancel the creation or the update and return to the listing page | ||
* @param page {Page} Browser tab | ||
* @returns {Promise<void>} | ||
*/ | ||
async cancel(page: Page): Promise<void> { | ||
await this.clickAndWaitForURL(page, this.cancelButton); | ||
} | ||
} | ||
|
||
module.exports = EmployeeBasePage; |
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,9 @@ | ||
import type {BOMyProfilePageInterface} from '@interfaces/BO/advancedParameters/team/myProfile'; | ||
|
||
/* eslint-disable global-require, @typescript-eslint/no-var-requires */ | ||
function requirePage(): BOMyProfilePageInterface { | ||
return require('@versions/develop/pages/BO/advancedParameters/team/myProfile'); | ||
} | ||
/* eslint-enable global-require, @typescript-eslint/no-var-requires */ | ||
|
||
export default requirePage(); |
133 changes: 133 additions & 0 deletions
133
src/versions/develop/pages/BO/advancedParameters/team/myProfile.ts
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,133 @@ | ||
import type FakerEmployee from '@data/faker/employee'; | ||
import {type BOMyProfilePageInterface} from '@interfaces/BO/advancedParameters/team/myProfile'; | ||
import EmployeeBasePage from '@pages/BO/advancedParameters/team/base'; | ||
import {type Page} from '@playwright/test'; | ||
|
||
/** | ||
* Add employee page, contains functions that can be used on the page | ||
* @class | ||
* @extends EmployeeBasePage | ||
*/ | ||
class BOMyProfilePage extends EmployeeBasePage implements BOMyProfilePageInterface { | ||
public readonly successfulUpdateMessageFR: string; | ||
|
||
public readonly errorInvalidFirstNameMessage: string; | ||
|
||
public readonly errorInvalidLastNameMessage: string; | ||
|
||
public readonly errorInvalidFormatImageMessage: string; | ||
|
||
private readonly passwordButton: string; | ||
|
||
private readonly currentPasswordInput: string; | ||
|
||
private readonly newPasswordInput: string; | ||
|
||
private readonly confirmPasswordInput: string; | ||
|
||
private readonly avatarFileInput: string; | ||
|
||
private readonly enableGravatarInput: (toggle: number) => string; | ||
|
||
/** | ||
* @constructs | ||
* Setting up texts and selectors to use on add employee page | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.successfulUpdateMessageFR = 'Mise à jour réussie'; | ||
this.errorInvalidFirstNameMessage = 'The "First name" field is invalid.'; | ||
this.errorInvalidLastNameMessage = 'The "Last name" field is invalid.'; | ||
this.errorInvalidFormatImageMessage = 'Image format not recognized, allowed formats are: image/gif, image/jpg, ' | ||
+ 'image/jpeg, image/pjpeg, image/png, image/x-png, image/webp, image/svg+xml, image/svg'; | ||
|
||
// Selectors | ||
this.passwordButton = '#employee_change_password_change_password_button'; | ||
this.currentPasswordInput = '#employee_change_password_old_password'; | ||
this.newPasswordInput = '#employee_change_password_new_password_first'; | ||
this.confirmPasswordInput = '#employee_change_password_new_password_second'; | ||
this.avatarFileInput = '#employee_avatarUrl'; | ||
this.enableGravatarInput = (toggle: number) => `#employee_has_enabled_gravatar_${toggle}`; | ||
} | ||
|
||
/* | ||
Methods | ||
*/ | ||
|
||
/** | ||
* Fill form for update My Profile page | ||
* @param page {Page} Browser tab | ||
* @param currentPassword {string} Data to set on add/edit employee form | ||
* @param newEmployeeData {FakerEmployee} Data to set on add/edit employee form | ||
* @returns {Promise<void>} | ||
*/ | ||
async updateEditEmployee(page: Page, currentPassword: string, newEmployeeData: FakerEmployee): Promise<void> { | ||
await this.setValue(page, this.firstNameInput, newEmployeeData.firstName); | ||
await this.setValue(page, this.lastNameInput, newEmployeeData.lastName); | ||
if (newEmployeeData.avatarFile) { | ||
await this.uploadOnFileChooser(page, this.avatarFileInput, [newEmployeeData.avatarFile]); | ||
} | ||
await this.setChecked(page, this.enableGravatarInput(newEmployeeData.enableGravatar ? 1 : 0)); | ||
await this.setValue(page, this.emailInput, newEmployeeData.email); | ||
await page.locator(this.passwordButton).click(); | ||
await this.setValue(page, this.currentPasswordInput, currentPassword); | ||
await this.setValue(page, this.newPasswordInput, newEmployeeData.password); | ||
await this.setValue(page, this.confirmPasswordInput, newEmployeeData.password); | ||
await this.selectByVisibleText(page, this.languageSelect, newEmployeeData.language); | ||
await this.selectDefaultPage(page, newEmployeeData.defaultPage); | ||
await this.clickAndWaitForLoadState(page, this.saveButton); | ||
} | ||
|
||
/** | ||
* Get the value of an input | ||
* @override | ||
* @param page {Page} Browser tab | ||
* @param input {string} ID of the input | ||
* @returns {Promise<string>} | ||
*/ | ||
async getInputValue(page: Page, input: string): Promise<string> { | ||
let inputSelector: string; | ||
|
||
switch (input) { | ||
case 'firstname': | ||
inputSelector = this.firstNameInput; | ||
break; | ||
case 'lastname': | ||
inputSelector = this.lastNameInput; | ||
break; | ||
default: | ||
throw new Error(`Field ${input} was not found`); | ||
} | ||
|
||
return super.getInputValue(page, inputSelector); | ||
} | ||
|
||
/** | ||
* Get login error | ||
* @param page {Page} Browser tab | ||
* @return {Promise<string>} | ||
*/ | ||
async getAlertSuccess(page: Page): Promise<string> { | ||
return this.getAlertSuccessBlockParagraphContent(page); | ||
} | ||
|
||
/** | ||
* Get login error | ||
* @param page {Page} Browser tab | ||
* @return {Promise<string>} | ||
*/ | ||
async getAlertError(page: Page): Promise<string> { | ||
return this.getAlertDangerBlockParagraphContent(page); | ||
} | ||
|
||
/** | ||
* @param page {Page} Browser tab | ||
* @return {Promise<boolean>} | ||
*/ | ||
async isGravatarEnabled(page: Page): Promise<boolean> { | ||
return this.isChecked(page, this.enableGravatarInput(1)); | ||
} | ||
} | ||
|
||
module.exports = new BOMyProfilePage(); |