@umbraco/playwright-testhelpers
Version:
Test helpers for making playwright tests for Umbraco solutions
172 lines • 9.13 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserGroupUiHelper = void 0;
const test_1 = require("@playwright/test");
const UiBaseLocators_1 = require("./UiBaseLocators");
const ConstantHelper_1 = require("./ConstantHelper");
class UserGroupUiHelper extends UiBaseLocators_1.UiBaseLocators {
userGroupsBtn;
chooseSectionBtn;
languageInput;
chooseLanguageBtn;
permissionVerbBtn;
userGroupCreateBtn;
allowAccessToAllLanguagesBtn;
allowAccessToAllDocumentsBtn;
allowAccessToAllMediaBtn;
contentStartNode;
mediaStartNode;
section;
granularPermission;
addGranularPermissionBtn;
granularPermissionsModal;
iconChecked;
inputEntityUserPermissionList;
sectionList;
constructor(page) {
super(page);
this.userGroupsBtn = page.getByLabel('User groups');
this.permissionVerbBtn = page.locator('umb-input-user-permission-verb');
this.chooseSectionBtn = page.locator('umb-input-section').getByLabel('Choose');
this.languageInput = page.locator('umb-input-language');
this.chooseLanguageBtn = this.languageInput.getByLabel('Choose');
this.userGroupCreateBtn = page.getByLabel('Create');
this.allowAccessToAllLanguagesBtn = page.getByText('Allow access to all languages');
this.allowAccessToAllDocumentsBtn = page.getByText('Allow access to all documents');
this.allowAccessToAllMediaBtn = page.getByText('Allow access to all media');
this.contentStartNode = page.locator('umb-input-document');
this.mediaStartNode = page.locator('umb-input-media');
this.sectionList = page.locator('umb-input-section uui-ref-list');
this.section = this.sectionList.locator('umb-ref-section');
this.granularPermission = page.locator('umb-input-document-granular-user-permission');
this.addGranularPermissionBtn = this.granularPermission.getByLabel('Add');
this.granularPermissionsModal = page.locator('umb-entity-user-permission-settings-modal');
this.iconChecked = page.locator('uui-toggle').locator('#icon-checked').getByRole('img');
this.inputEntityUserPermissionList = page.locator('umb-input-entity-user-permission');
}
async clickUserGroupsButton() {
await this.click(this.userGroupsBtn);
await this.page.waitForTimeout(ConstantHelper_1.ConstantHelper.wait.short);
}
async enterUserGroupName(name) {
await this.enterText(this.enterAName, name);
}
async addLanguageToUserGroup(languageName) {
await this.click(this.chooseLanguageBtn);
await this.clickLabelWithName(languageName, true);
await this.clickSubmitButton();
}
async clickAllowAccessToAllLanguages() {
await this.click(this.allowAccessToAllLanguagesBtn);
}
async clickAllowAccessToAllDocuments() {
await this.click(this.allowAccessToAllDocumentsBtn);
}
async clickAllowAccessToAllMedia() {
await this.click(this.allowAccessToAllMediaBtn);
}
async clickCreateUserGroupButton() {
await this.click(this.userGroupCreateBtn);
}
async clickRemoveLanguageFromUserGroup(languageName) {
await this.click(this.entityItem.filter({ hasText: languageName }).getByLabel('Remove'));
}
async isUserGroupWithNameVisible(name, isVisible = true) {
return await this.isVisible(this.page.locator('uui-table-row', { hasText: name }), isVisible);
}
async clickUserGroupWithName(name) {
await this.click(this.page.getByRole('link', { name: name }));
await this.page.waitForTimeout(ConstantHelper_1.ConstantHelper.wait.short);
}
async clickPermissionsByName(permissionName) {
for (let i = 0; i < permissionName.length; i++) {
await this.click(this.permissionVerbBtn.getByText(permissionName[i], { exact: true }));
}
}
async clickGranularPermissionsByName(permissionName) {
for (let i = 0; i < permissionName.length; i++) {
await this.click(this.granularPermissionsModal.getByText(permissionName[i], { exact: true }));
}
}
async doesUserGroupHavePermission(permissionName, hasPermission = true) {
await this.isVisible(this.permissionVerbBtn.filter({ has: this.page.getByLabel(permissionName, { exact: true }) }).filter({ has: this.iconChecked }), hasPermission);
}
async doesUserGroupHaveGranularPermission(permissionName, hasPermission = true) {
await this.isVisible(this.granularPermissionsModal.filter({ has: this.page.getByLabel(permissionName, { exact: true }) }).filter({ has: this.iconChecked }), hasPermission);
}
async addSectionWithNameToUserGroup(sectionName) {
await this.clickChooseSectionButton();
await this.clickLabelWithName(sectionName, true);
await this.clickSubmitButton();
}
async clickChooseSectionButton() {
await this.click(this.chooseSectionBtn);
}
async doesUserGroupTableHaveSection(userGroupName, sectionName, hasSection = true) {
await this.isVisible(this.page.locator('uui-table-row', { hasText: userGroupName }).locator('umb-user-group-table-sections-column-layout', { hasText: sectionName }), hasSection);
}
async doesUserGroupContainLanguage(languageName, isVisible = true) {
await this.waitForVisible(this.languageInput);
await this.isVisible(this.languageInput.filter({ hasText: languageName }), isVisible);
}
async clickRemoveSectionFromUserGroup(sectionName) {
await this.click(this.section.filter({ hasText: sectionName }).getByLabel('Remove'));
}
async clickRemoveContentStartNodeFromUserGroup(contentStartNodeName) {
await this.click(this.contentStartNode.filter({ hasText: contentStartNodeName }).getByLabel('Remove'));
}
async clickRemoveMediaStartNodeFromUserGroup(mediaStartNodeName) {
// Force click is needed
await this.click(this.mediaStartNode.filter({ hasText: mediaStartNodeName }).getByLabel('Remove'), { force: true });
}
async doesUserGroupHavePermissionEnabled(permissionName) {
return await Promise.all(permissionName.map(permission => this.doesUserGroupHavePermission(permission)));
}
async clickGranularPermissionWithName(permissionName) {
await this.click(this.granularPermission.getByText(permissionName));
}
async clickAddGranularPermission() {
await this.click(this.addGranularPermissionBtn);
}
async clickRemoveGranularPermissionWithName(permissionName) {
await this.click(this.granularPermission.filter({ hasText: permissionName }).getByLabel('Remove'));
}
async doesSettingHaveValue(headline, settings) {
for (let index = 0; index < Object.keys(settings).length; index++) {
const [label, description] = settings[index];
const propertyLocator = this.page.locator('uui-box').filter({ hasText: headline }).locator('umb-property-layout').nth(index);
await (0, test_1.expect)(propertyLocator.locator('#headerColumn #label')).toHaveText(label);
if (description !== '')
await (0, test_1.expect)(propertyLocator.locator('#description')).toHaveText(description);
}
}
async doesPermissionsSettingsHaveValue(settings) {
for (let index = 0; index < Object.keys(settings).length; index++) {
const [name, description] = settings[index];
const permissionItemLocator = this.inputEntityUserPermissionList.locator(this.permissionVerbBtn).nth(index);
await (0, test_1.expect)(permissionItemLocator.locator('#name')).toHaveText(name);
if (description !== '')
await (0, test_1.expect)(permissionItemLocator.locator('#setting small')).toHaveText(description);
}
}
async doesUserGroupContainSection(section) {
await this.containsText(this.sectionList, section);
}
async doesUserGroupHaveSections(sections) {
return await Promise.all(sections.map(section => this.doesUserGroupContainSection(section)));
}
async doesUserGroupSectionsHaveCount(count) {
await this.hasCount(this.section, count);
}
async clickSaveButtonAndWaitForUserGroupToBeCreated() {
return await this.waitForResponseAfterExecutingPromise(ConstantHelper_1.ConstantHelper.apiEndpoints.userGroup, this.clickSaveButton(), ConstantHelper_1.ConstantHelper.statusCodes.created);
}
async clickSaveButtonAndWaitForUserGroupToBeUpdated() {
return await this.waitForResponseAfterExecutingPromise(ConstantHelper_1.ConstantHelper.apiEndpoints.userGroup, this.clickSaveButton(), ConstantHelper_1.ConstantHelper.statusCodes.ok);
}
async clickConfirmToDeleteButtonAndWaitForUserGroupToBeDeleted() {
return await this.waitForResponseAfterExecutingPromise(ConstantHelper_1.ConstantHelper.apiEndpoints.userGroup, this.clickConfirmToDeleteButton(), ConstantHelper_1.ConstantHelper.statusCodes.ok);
}
}
exports.UserGroupUiHelper = UserGroupUiHelper;
//# sourceMappingURL=UserGroupUiHelper.js.map