@umbraco/playwright-testhelpers
Version:
Test helpers for making playwright tests for Umbraco solutions
253 lines • 11.5 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;
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('#card-grid');
this.apiUserBtn = page.locator('#collection-action-menu-popover').getByLabel('API User', { exact: true });
this.goToProfileBtn = page.getByLabel('Go to profile', { exact: true });
}
async clickUsersButton() {
await this.click(this.usersBtn);
}
async clickCreateUserButton() {
await this.click(this.createUserBtn);
await this.page.waitForTimeout(ConstantHelper_1.ConstantHelper.wait.short);
}
async enterNameOfTheUser(name) {
await this.enterText(this.nameOfTheUserTxt, name);
}
async enterUserEmail(email) {
await this.enterText(this.userEmailTxt, email);
}
async clickAddUserGroupsButton() {
await this.click(this.addUserGroupsBtn);
// This wait is necessary to avoid the click on the user group button to be ignored
await this.page.waitForTimeout(ConstantHelper_1.ConstantHelper.wait.minimal);
}
async clickChooseUserGroupsButton() {
await this.click(this.chooseUserGroupsBtn);
}
async clickOpenUserGroupsButton() {
await this.click(this.openUserGroupsBtn);
}
async enterUpdatedNameOfUser(name) {
await this.enterText(this.updatedNameOfTheUserTxt, name);
}
async clickUserWithName(name) {
const userNameLocator = this.page.locator('#open-part').getByText(name, { exact: true });
await this.click(userNameLocator);
}
async clickChangePasswordButton() {
await this.click(this.changePasswordBtn);
}
async updatePassword(newPassword) {
await this.newPasswordTxt.fill(newPassword);
await this.confirmPasswordTxt.fill(newPassword);
}
async isUserVisible(name, isVisible = true) {
return await this.isVisible(this.page.getByText(name, { exact: true }), isVisible);
}
async clickChangePhotoButton() {
await this.click(this.changePhotoBtn);
}
async clickRemoveButtonForUserGroupWithName(userGroupName) {
await this.click(this.page.locator('umb-user-group-ref', { hasText: userGroupName }).locator('[label="Remove"]'));
}
async clickRemovePhotoButton() {
await this.click(this.removePhotoBtn);
}
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) {
let userCount = 0;
while (true) {
await this.page.waitForTimeout(ConstantHelper_1.ConstantHelper.wait.medium);
userCount += await this.userSectionCard.count();
// Check if pagination exists and next button is enabled
const nextButton = this.nextPaginationBtn;
const nextButtonExists = await nextButton.count() > 0;
if (!nextButtonExists) {
break; // No pagination at all
}
const isNextEnabled = await nextButton.isEnabled();
if (!isNextEnabled) {
break;
}
await this.clickNextPaginationButton();
}
// If we actually navigated through the pagination, we should go back
if (amount > 50) {
const firstPage = this.firstPaginationBtn;
const isFirstPageEnabled = await firstPage.isEnabled();
if (isFirstPageEnabled) {
await this.click(firstPage);
}
await this.page.waitForTimeout(ConstantHelper_1.ConstantHelper.wait.medium);
}
return (0, test_1.expect)(userCount).toBe(amount);
}
async doesUserSectionContainUserWithText(name) {
await this.containsText(this.userGrid, name);
}
async filterByStatusName(statusName) {
await this.click(this.statusBtn);
await this.click(this.page.locator('label').filter({ hasText: statusName }));
}
async filterByGroupName(groupName) {
await this.click(this.groupBtn);
await this.click(this.page.locator('label').filter({ hasText: groupName }));
}
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.click(this.chooseContainerBtn);
}
async selectUserLanguage(language) {
await this.languageBtn.selectOption(language, { force: true });
}
async clickRemoveButtonForContentNodeWithName(name) {
const entityItemLocator = this.entityItem.filter({ has: this.page.locator(`[name="${name}"]`) });
await this.hoverAndClick(entityItemLocator, entityItemLocator.getByRole('button', { name: 'Remove' }), { force: true });
}
async clickRemoveButtonForMediaNodeWithName(name) {
await this.click(this.mediaInput.locator(`[name="${name}"]`).locator('[label="Remove"]'));
}
async clickAllowAccessToAllDocumentsToggle() {
await this.click(this.allowAccessToAllDocumentsToggle);
}
async clickAllowAccessToAllMediaToggle() {
await this.click(this.allowAccessToAllMediaToggle);
}
async isUserDisabledTextVisible() {
await this.waitForVisible(this.disabledTxt);
}
async isUserActiveTextVisible() {
await this.waitForVisible(this.activeTxt);
}
async orderByNewestUser() {
// Force click is needed
await this.click(this.orderByBtn, { force: true });
await this.click(this.orderByNewestBtn);
}
async isUserWithNameTheFirstUserInList(name) {
await (0, test_1.expect)(this.userSectionCard.first()).toContainText(name);
}
async doesUserHaveAccessToContentNode(name) {
await this.isVisible(this.documentStartNode.locator(`[name="${name}"]`));
}
async doesUserHaveAccessToMediaNode(name) {
await this.isVisible(this.mediaStartNode.locator(`[name="${name}"]`));
}
async clickUsersMenu() {
await this.click(this.usersMenu);
}
async goToUsers() {
await this.goToSection(ConstantHelper_1.ConstantHelper.sections.users);
await this.clickUsersMenu();
}
async goToUserWithName(name) {
await this.goToSection(ConstantHelper_1.ConstantHelper.sections.users);
await this.clickUsersMenu();
await this.searchInUserSection(name);
await this.clickUserWithName(name);
}
async clickUserButton() {
await this.click(this.userBtn);
}
async isGoToProfileButtonVisible(isVisible = true) {
await this.isVisible(this.goToProfileBtn, isVisible);
}
async clickAPIUserButton() {
await this.click(this.apiUserBtn);
}
async clickSaveButtonAndWaitForUserToBeCreated() {
return await this.waitForResponseAfterExecutingPromise(ConstantHelper_1.ConstantHelper.apiEndpoints.user, this.clickSaveButton(), ConstantHelper_1.ConstantHelper.statusCodes.created);
}
async clickSaveButtonAndWaitForUserToBeUpdated() {
return await this.waitForResponseAfterExecutingPromise(ConstantHelper_1.ConstantHelper.apiEndpoints.user, this.clickSaveButton(), ConstantHelper_1.ConstantHelper.statusCodes.ok);
}
async clickConfirmToDeleteButtonAndWaitForUserToBeDeleted() {
return await this.waitForResponseAfterExecutingPromise(ConstantHelper_1.ConstantHelper.apiEndpoints.user, this.clickConfirmToDeleteButton(), ConstantHelper_1.ConstantHelper.statusCodes.ok);
}
async clickCreateUserButtonAndWaitForUserToBeCreated() {
return await this.waitForResponseAfterExecutingPromise(ConstantHelper_1.ConstantHelper.apiEndpoints.user, this.clickCreateUserButton(), ConstantHelper_1.ConstantHelper.statusCodes.created);
}
}
exports.UserUiHelper = UserUiHelper;
//# sourceMappingURL=UserUiHelper.js.map