UNPKG

@umbraco/playwright-testhelpers

Version:

Test helpers for making playwright tests for Umbraco solutions

221 lines 9.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UserUiHelper = void 0; 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 this.click(this.usersBtn); } async clickCreateUserButton() { await this.createUserBtn.click(); await this.page.waitForTimeout(500); } async enterNameOfTheUser(name) { await this.enterText(this.nameOfTheUserTxt, name); } async enterUserEmail(email) { await this.enterText(this.userEmailTxt, 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.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.changePasswordBtn.click(); } async updatePassword(newPassword) { await this.enterText(this.newPasswordTxt, newPassword); await this.enterText(this.confirmPasswordTxt, newPassword); } async isUserVisible(name, isVisible = true) { return await this.isVisible(this.page.getByText(name, { exact: true }), 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.enterText(this.searchInUserSectionTxt, name); } async doesUserSectionContainUserAmount(amount) { return await this.hasCount(this.userSectionCard, amount); } async doesUserSectionContainUserWithText(name) { return await this.containsText(this.userGrid, 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 this.isVisible(this.disabledTxt); } async isUserActiveTextVisible() { return await this.isVisible(this.activeTxt); } async orderByNewestUser() { await this.isVisible(this.orderByBtn); // Force click is needed await this.orderByBtn.click({ force: true }); await this.orderByNewestBtn.click(); } async isUserWithNameTheFirstUserInList(name) { await this.containsText(this.userSectionCard.first(), name); } async doesUserHaveAccessToContentNode(name) { return await this.isVisible(this.documentStartNode.locator('[name="' + name + '"]')); } async doesUserHaveAccessToMediaNode(name) { return await this.isVisible(this.mediaStartNode.locator('[name="' + name + '"]')); } 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 this.isVisible(this.goToProfileBtn, isVisible); } async clickAPIUserButton() { await this.apiUserBtn.click(); } } exports.UserUiHelper = UserUiHelper; //# sourceMappingURL=UserUiHelper.js.map