UNPKG

@umbraco/playwright-testhelpers

Version:

Test helpers for making playwright tests for Umbraco solutions

172 lines 8.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UserGroupUiHelper = void 0; const UiBaseLocators_1 = require("./UiBaseLocators"); 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-user-group-entity-user-permission-list'); } async clickUserGroupsButton() { await this.click(this.userGroupsBtn); await this.page.waitForTimeout(500); } 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 waitForUserGroupToBeCreated() { await this.waitForNetworkToBeIdle(); } async waitForUserGroupToBeDeleted() { await this.waitForNetworkToBeIdle(); } async waitForUserGroupToBeRenamed() { await this.waitForNetworkToBeIdle(); } async clickCreateUserGroupButton() { await this.click(this.userGroupCreateBtn); } async clickRemoveLanguageFromUserGroup(languageName) { await this.click(this.page.locator('umb-entity-item-ref').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(200); } async clickPermissionsByName(permissionName) { for (let i = 0; i < permissionName.length; i++) { await this.permissionVerbBtn.getByText(permissionName[i], { exact: true }).click(); } } async clickGranularPermissionsByName(permissionName) { for (let i = 0; i < permissionName.length; i++) { await this.granularPermissionsModal.getByText(permissionName[i], { exact: true }).click(); } } 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.isVisible(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) { const removeMediaStartNodeWithNameLocator = this.mediaStartNode.filter({ hasText: mediaStartNodeName }).getByLabel('Remove'); await this.isVisible(removeMediaStartNodeWithNameLocator); // Force click is needed await removeMediaStartNodeWithNameLocator.click({ 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 this.hasText(propertyLocator.locator('#headerColumn #label'), label); if (description !== '') await this.hasText(propertyLocator.locator('#description'), 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 this.hasText(permissionItemLocator.locator('#name'), name); if (description !== '') await this.hasText(permissionItemLocator.locator('#setting small'), description); } } async doesUserGroupContainSection(section) { return await this.containsText(this.sectionList, section); } async doesUserGroupHaveSections(sections) { return await Promise.all(sections.map(section => this.doesUserGroupContainSection(section))); } async doesUserGroupSectionsHaveCount(count) { return await this.hasCount(this.section, count); } } exports.UserGroupUiHelper = UserGroupUiHelper; //# sourceMappingURL=UserGroupUiHelper.js.map