@umbraco/playwright-testhelpers
Version:
Test helpers for making playwright tests for Umbraco solutions
224 lines • 9.7 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserUiHelper = void 0;
const test_1 = require("@playwright/test");
const UiBaseLocators_1 = require("./UiBaseLocators");
const umbraco_config_1 = require("../../umbraco.config");
const ConstantHelper_1 = require("./ConstantHelper");
class UserUiHelper extends UiBaseLocators_1.UiBaseLocators {
usersBtn;
createUserBtn;
nameOfTheUserTxt;
userEmailTxt;
addUserGroupsBtn;
openUserGroupsBtn;
updatedNameOfTheUserTxt;
changePasswordBtn;
changePhotoBtn;
removePhotoBtn;
searchInUserSectionTxt;
userSectionCard;
statusBtn;
groupBtn;
chooseUserGroupsBtn;
allowAccessToAllDocumentsToggle;
allowAccessToAllMediaToggle;
mediaInput;
chooseContainerBtn;
languageBtn;
disabledTxt;
activeTxt;
orderByBtn;
orderByNewestBtn;
documentStartNode;
mediaStartNode;
usersMenu;
userBtn;
userGrid;
apiUserBtn;
entityItem;
goToProfileBtn;
constructor(page) {
super(page);
this.usersBtn = page.getByLabel('Users');
this.createUserBtn = page.getByLabel('Create user');
this.nameOfTheUserTxt = page.getByLabel('name', { exact: true });
this.userEmailTxt = page.getByLabel('email');
this.addUserGroupsBtn = page.locator('#userGroups').getByLabel('open', { exact: true });
this.openUserGroupsBtn = page.locator('[label="Groups"]').getByLabel('open', { exact: true });
this.chooseUserGroupsBtn = page.locator('umb-user-group-input').getByLabel('Choose');
this.updatedNameOfTheUserTxt = page.locator('umb-workspace-header-name-editable').locator('input');
this.changePasswordBtn = page.getByLabel('Change your password');
this.changePhotoBtn = page.getByLabel('Change photo');
this.removePhotoBtn = page.getByLabel('Remove photo');
this.searchInUserSectionTxt = page.locator('umb-collection-filter-field #input');
this.userSectionCard = page.locator('uui-card-user');
this.statusBtn = page.locator('uui-button', { hasText: 'Status' });
this.groupBtn = page.locator('uui-button', { hasText: 'Groups' });
this.allowAccessToAllDocumentsToggle = page.locator('umb-property-layout').filter({ hasText: 'Allow access to all documents' }).locator('#toggle');
this.allowAccessToAllMediaToggle = page.locator('umb-property-layout').filter({ hasText: 'Allow access to all media' }).locator('#toggle');
this.mediaInput = page.locator('umb-input-media');
this.chooseContainerBtn = page.locator('#container').getByLabel('Choose');
this.languageBtn = page.locator('[label="UI Culture"] select');
this.disabledTxt = page.getByText('Disabled', { exact: true });
this.activeTxt = page.getByText('Active', { exact: true });
this.orderByBtn = page.getByLabel('order by');
this.orderByNewestBtn = page.getByLabel('Newest');
this.documentStartNode = page.locator('umb-user-document-start-node');
this.mediaStartNode = page.locator('umb-user-media-start-node');
this.usersMenu = page.locator('umb-menu').getByLabel('Users', { exact: true });
this.userBtn = page.locator('#collection-action-menu-popover').getByLabel('User', { exact: true });
this.userGrid = page.locator('#user-grid');
this.apiUserBtn = page.locator('#collection-action-menu-popover').getByLabel('API User', { exact: true });
this.entityItem = page.locator('umb-entity-item-ref');
this.goToProfileBtn = page.getByLabel('Go to profile', { exact: true });
}
async clickUsersButton() {
await (0, test_1.expect)(this.usersBtn).toBeVisible();
await this.usersBtn.click();
}
async clickCreateUserButton() {
await this.createUserBtn.click();
await this.page.waitForTimeout(500);
}
async enterNameOfTheUser(name) {
await this.nameOfTheUserTxt.fill(name);
}
async enterUserEmail(email) {
await this.userEmailTxt.fill(email);
}
async waitForUserToBeCreated() {
await this.waitForNetworkToBeIdle();
}
async waitForUserToBeDeleted() {
await this.waitForNetworkToBeIdle();
}
async waitForUserToBeRenamed() {
await this.waitForNetworkToBeIdle();
}
async clickAddUserGroupsButton() {
await this.addUserGroupsBtn.click();
// This wait is necessary to avoid the click on the user group button to be ignored
await this.page.waitForTimeout(200);
}
async clickChooseUserGroupsButton() {
await this.chooseUserGroupsBtn.click();
}
async clickOpenUserGroupsButton() {
await this.openUserGroupsBtn.click();
}
async enterUpdatedNameOfUser(name) {
await this.updatedNameOfTheUserTxt.fill(name);
}
async clickUserWithName(name) {
const userNameLocator = this.page.locator('#open-part').getByText(name, { exact: true });
await (0, test_1.expect)(userNameLocator).toBeVisible();
await userNameLocator.click();
}
async clickChangePasswordButton() {
await this.changePasswordBtn.click();
}
async updatePassword(newPassword) {
await this.newPasswordTxt.fill(newPassword);
await this.confirmPasswordTxt.fill(newPassword);
}
async isUserVisible(name, isVisible = true) {
return await (0, test_1.expect)(this.page.getByText(name, { exact: true })).toBeVisible({ visible: isVisible });
}
async clickChangePhotoButton() {
await this.changePhotoBtn.click();
}
async clickRemoveButtonForUserGroupWithName(userGroupName) {
await this.page.locator('umb-user-group-ref', { hasText: userGroupName }).locator('[label="Remove"]').click();
}
async clickRemovePhotoButton() {
await this.removePhotoBtn.click();
}
async changePhotoWithFileChooser(filePath) {
const fileChooserPromise = this.page.waitForEvent('filechooser');
await this.clickChangePhotoButton();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles(filePath);
}
async searchInUserSection(name) {
await this.searchInUserSectionTxt.fill(name);
}
async doesUserSectionContainUserAmount(amount) {
return await (0, test_1.expect)(this.userSectionCard).toHaveCount(amount);
}
async doesUserSectionContainUserWithText(name) {
return await (0, test_1.expect)(this.userGrid).toContainText(name);
}
async filterByStatusName(statusName) {
await this.statusBtn.click();
await this.page.locator('label').filter({ hasText: statusName }).click();
}
async filterByGroupName(groupName) {
await this.groupBtn.click();
await this.page.locator('label').filter({ hasText: groupName }).click();
}
async isPasswordUpdatedForUserWithId(userId) {
await Promise.all([
this.page.waitForResponse(resp => resp.url().includes(umbraco_config_1.umbracoConfig.environment.baseUrl + '/umbraco/management/api/v1/user/' + userId + '/change-password') && resp.status() === 200),
await this.clickConfirmButton()
]);
}
async clickChooseContainerButton() {
await this.chooseContainerBtn.click();
}
async selectUserLanguage(language) {
await this.languageBtn.selectOption(language, { force: true });
}
async clickRemoveButtonForContentNodeWithName(name) {
await this.entityItem.filter({ has: this.page.locator('[name="' + name + '"]') }).hover();
await this.entityItem.filter({ has: this.page.locator('[name="' + name + '"]') }).getByRole('button', { name: 'Remove' }).click({ force: true });
}
async clickRemoveButtonForMediaNodeWithName(name) {
await this.mediaInput.locator('[name="' + name + '"]').locator('[label="Remove"]').click();
}
async clickAllowAccessToAllDocumentsToggle() {
await this.allowAccessToAllDocumentsToggle.click();
}
async clickAllowAccessToAllMediaToggle() {
await this.allowAccessToAllMediaToggle.click();
}
async isUserDisabledTextVisible() {
return await (0, test_1.expect)(this.disabledTxt).toBeVisible();
}
async isUserActiveTextVisible() {
return await (0, test_1.expect)(this.activeTxt).toBeVisible();
}
async orderByNewestUser() {
await (0, test_1.expect)(this.orderByBtn).toBeVisible();
// Force click is needed
await this.orderByBtn.click({ force: true });
await this.orderByNewestBtn.click();
}
async isUserWithNameTheFirstUserInList(name) {
await (0, test_1.expect)(this.userSectionCard.first()).toContainText(name);
}
async doesUserHaveAccessToContentNode(name) {
return await (0, test_1.expect)(this.documentStartNode.locator('[name="' + name + '"]')).toBeVisible();
}
async doesUserHaveAccessToMediaNode(name) {
return await (0, test_1.expect)(this.mediaStartNode.locator('[name="' + name + '"]')).toBeVisible();
}
async clickUsersMenu() {
await this.usersMenu.click();
}
async goToUsers() {
await this.goToSection(ConstantHelper_1.ConstantHelper.sections.users);
await this.clickUsersMenu();
}
async clickUserButton() {
await this.userBtn.click();
}
async isGoToProfileButtonVisible(isVisible = true) {
await (0, test_1.expect)(this.goToProfileBtn).toBeVisible({ visible: isVisible });
}
async clickAPIUserButton() {
await this.apiUserBtn.click();
}
}
exports.UserUiHelper = UserUiHelper;
//# sourceMappingURL=UserUiHelper.js.map