UNPKG

@umbraco/playwright-testhelpers

Version:

Test helpers for making playwright tests for Umbraco solutions

189 lines 10.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UserGroupUiHelper = void 0; const test_1 = require("@playwright/test"); 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 (0, test_1.expect)(this.userGroupsBtn).toBeVisible(); await this.userGroupsBtn.click(); await this.page.waitForTimeout(500); } async enterUserGroupName(name) { await (0, test_1.expect)(this.enterAName).toBeVisible(); await this.enterAName.clear(); await this.enterAName.fill(name); } async addLanguageToUserGroup(languageName) { await (0, test_1.expect)(this.chooseLanguageBtn).toBeVisible(); await this.chooseLanguageBtn.click(); await this.clickLabelWithName(languageName, true); await this.clickSubmitButton(); } async clickAllowAccessToAllLanguages() { await (0, test_1.expect)(this.allowAccessToAllLanguagesBtn).toBeVisible(); await this.allowAccessToAllLanguagesBtn.click(); } async clickAllowAccessToAllDocuments() { await (0, test_1.expect)(this.allowAccessToAllDocumentsBtn).toBeVisible(); await this.allowAccessToAllDocumentsBtn.click(); } async clickAllowAccessToAllMedia() { await (0, test_1.expect)(this.allowAccessToAllMediaBtn).toBeVisible(); await this.allowAccessToAllMediaBtn.click(); } async waitForUserGroupToBeCreated() { await this.waitForNetworkToBeIdle(); } async waitForUserGroupToBeDeleted() { await this.waitForNetworkToBeIdle(); } async waitForUserGroupToBeRenamed() { await this.waitForNetworkToBeIdle(); } async clickCreateUserGroupButton() { await (0, test_1.expect)(this.userGroupCreateBtn).toBeVisible(); await this.userGroupCreateBtn.click(); } async clickRemoveLanguageFromUserGroup(languageName) { await (0, test_1.expect)(this.page.locator('umb-entity-item-ref').filter({ hasText: languageName }).getByLabel('Remove')).toBeVisible(); await this.page.locator('umb-entity-item-ref').filter({ hasText: languageName }).getByLabel('Remove').click(); } async isUserGroupWithNameVisible(name, isVisible = true) { return await (0, test_1.expect)(this.page.locator('uui-table-row', { hasText: name })).toBeVisible({ visible: isVisible }); } async clickUserGroupWithName(name) { await (0, test_1.expect)(this.page.getByRole('link', { name: name })).toBeVisible(); await this.page.getByRole('link', { name: name }).click(); 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 (0, test_1.expect)(this.permissionVerbBtn.filter({ has: this.page.getByLabel(permissionName, { exact: true }) }).filter({ has: this.iconChecked })).toBeVisible({ visible: hasPermission }); } async doesUserGroupHaveGranularPermission(permissionName, hasPermission = true) { await (0, test_1.expect)(this.granularPermissionsModal.filter({ has: this.page.getByLabel(permissionName, { exact: true }) }).filter({ has: this.iconChecked })).toBeVisible({ visible: hasPermission }); } async addSectionWithNameToUserGroup(sectionName) { await this.clickChooseSectionButton(); await this.clickLabelWithName(sectionName, true); await this.clickSubmitButton(); } async clickChooseSectionButton() { await (0, test_1.expect)(this.chooseSectionBtn).toBeVisible(); await this.chooseSectionBtn.click(); } async doesUserGroupTableHaveSection(userGroupName, sectionName, hasSection = true) { await (0, test_1.expect)(this.page.locator('uui-table-row', { hasText: userGroupName }).locator('umb-user-group-table-sections-column-layout', { hasText: sectionName })).toBeVisible({ visible: hasSection }); } async doesUserGroupContainLanguage(languageName, isVisible = true) { await (0, test_1.expect)(this.languageInput).toBeVisible(); await (0, test_1.expect)(this.languageInput.filter({ hasText: languageName })).toBeVisible({ visible: isVisible }); } async clickRemoveSectionFromUserGroup(sectionName) { await (0, test_1.expect)(this.section.filter({ hasText: sectionName }).getByLabel('Remove')).toBeVisible(); await this.section.filter({ hasText: sectionName }).getByLabel('Remove').click(); } async clickRemoveContentStartNodeFromUserGroup(contentStartNodeName) { await (0, test_1.expect)(this.contentStartNode.filter({ hasText: contentStartNodeName }).getByLabel('Remove')).toBeVisible(); await this.contentStartNode.filter({ hasText: contentStartNodeName }).getByLabel('Remove').click(); } async clickRemoveMediaStartNodeFromUserGroup(mediaStartNodeName) { const removeMediaStartNodeWithNameLocator = this.mediaStartNode.filter({ hasText: mediaStartNodeName }).getByLabel('Remove'); await (0, test_1.expect)(removeMediaStartNodeWithNameLocator).toBeVisible(); // 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 (0, test_1.expect)(this.granularPermission.getByText(permissionName)).toBeVisible(); await this.granularPermission.getByText(permissionName).click(); } async clickAddGranularPermission() { await (0, test_1.expect)(this.addGranularPermissionBtn).toBeVisible(); await this.addGranularPermissionBtn.click(); } async clickRemoveGranularPermissionWithName(permissionName) { await (0, test_1.expect)(this.granularPermission.filter({ hasText: permissionName }).getByLabel('Remove')).toBeVisible(); await this.granularPermission.filter({ hasText: permissionName }).getByLabel('Remove').click(); } 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) { return await (0, test_1.expect)(this.sectionList).toContainText(section); } async doesUserGroupHaveSections(sections) { return await Promise.all(sections.map(section => this.doesUserGroupContainSection(section))); } async doesUserGroupSectionsHaveCount(count) { return await (0, test_1.expect)(this.section).toHaveCount(count); } } exports.UserGroupUiHelper = UserGroupUiHelper; //# sourceMappingURL=UserGroupUiHelper.js.map