UNPKG

@umbraco/playwright-testhelpers

Version:

Test helpers for making playwright tests for Umbraco solutions

191 lines 9.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MediaUiHelper = void 0; const UiBaseLocators_1 = require("./UiBaseLocators"); const test_1 = require("@playwright/test"); const ConstantHelper_1 = require("./ConstantHelper"); class MediaUiHelper extends UiBaseLocators_1.UiBaseLocators { createMediaItemBtn; mediaNameTxt; actionModalCreateBtn; mediaSearchTxt; trashBtn; restoreThreeDotsBtn; confirmEmptyRecycleBinBtn; mediaCreateBtn; mediaListHeader; mediaCardItemsValues; mediaListView; mediaGridView; mediaListNameValues; bulkTrashBtn; bulkMoveToBtn; mediaHeader; mediaHeaderActionsMenu; emptyRecycleBinBtn; mediaTreeItem; mediaPopoverLayout; mediaWorkspace; constructor(page) { super(page); this.createMediaItemBtn = page.locator('umb-create-media-collection-action').getByLabel('Create'); this.mediaNameTxt = page.locator('#name-input #input'); this.actionModalCreateBtn = page.locator('#action-modal').getByLabel('Create'); this.mediaSearchTxt = page.getByLabel('Search', { exact: true }); this.trashBtn = page.getByLabel(/^Trash(…)?$/); this.restoreThreeDotsBtn = page.getByRole('button', { name: 'Restore…' }); this.confirmEmptyRecycleBinBtn = page.locator('#confirm').getByLabel('Empty Recycle Bin', { exact: true }); this.mediaCreateBtn = this.page.locator('umb-collection-toolbar').getByLabel('Create'); this.mediaListView = this.page.locator('umb-media-table-collection-view'); this.mediaGridView = this.page.locator('umb-media-grid-collection-view'); this.mediaListHeader = this.mediaListView.locator('uui-table-head-cell span'); this.mediaCardItemsValues = this.mediaCardItems.locator('span'); this.mediaListNameValues = this.mediaListView.locator('umb-media-table-column-name span'); this.bulkTrashBtn = page.locator('umb-entity-bulk-action uui-button').filter({ hasText: 'Trash' }); this.bulkMoveToBtn = page.locator('umb-entity-bulk-action uui-button').filter({ hasText: 'Move to' }); this.mediaHeader = page.getByRole('heading', { name: 'Media' }); this.mediaHeaderActionsMenu = page.locator('#header #action-modal'); this.emptyRecycleBinBtn = page.locator('[label="Empty Recycle Bin"]').locator('svg'); this.mediaTreeItem = page.locator('umb-media-tree-item'); this.mediaPopoverLayout = page.locator('umb-popover-layout'); this.mediaWorkspace = page.locator('umb-media-workspace-editor'); } async clickCreateMediaItemButton() { await this.click(this.createMediaItemBtn); } async enterMediaItemName(name) { await this.enterText(this.mediaNameTxt, name, { verify: true }); } async clickMediaTypeWithNameButton(mediaTypeName) { await this.click(this.page.getByLabel(mediaTypeName, { exact: true })); } async searchForMediaItemByName(name) { await this.enterText(this.mediaSearchTxt, name); } async doesMediaCardsContainAmount(count) { await this.hasCount(this.mediaCardItems, count); } async doesMediaCardContainText(name) { await this.containsText(this.mediaCardItems, name); } async clickTrashButton() { await this.click(this.trashBtn); } async restoreMediaItem(name) { await this.clickActionsMenuForName(name); await this.click(this.restoreThreeDotsBtn); await this.page.waitForTimeout(ConstantHelper_1.ConstantHelper.wait.medium); await this.clickRestoreButton(); } async deleteMediaItem(name) { await this.clickActionsMenuForName(name); await this.clickDeleteActionMenuOption(); await this.clickConfirmToDeleteButton(); } async deleteMediaItemAndWaitForMediaToBeDeleted(name) { await this.clickActionsMenuForName(name); await this.clickDeleteActionMenuOption(); return await this.waitForResponseAfterExecutingPromise(ConstantHelper_1.ConstantHelper.apiEndpoints.media, this.clickConfirmToDeleteButton(), ConstantHelper_1.ConstantHelper.statusCodes.ok); } async clickCreateMediaWithType(mediaTypeName) { await this.click(this.mediaCreateBtn); await this.clickMediaTypeInPopoverByName(mediaTypeName); } async clickMediaTypeName(mediaTypeName) { await this.click(this.documentTypeNode.filter({ hasText: mediaTypeName })); } async clickMediaTypeInPopoverByName(mediaTypeName) { await this.click(this.mediaPopoverLayout.getByLabel(mediaTypeName)); } async clickEmptyRecycleBinButton() { // Force click is needed await this.hoverAndClick(this.recycleBinMenuItem, this.emptyRecycleBinBtn, { force: true }); } async clickConfirmEmptyRecycleBinButton() { await this.click(this.confirmEmptyRecycleBinBtn); } async clickCreateModalButton() { await this.click(this.actionModalCreateBtn); } async clickMediaCaretButtonForName(name) { await this.click(this.page.locator(`umb-media-tree-item [label="${name}"]`).locator('#caret-button')); } async openMediaCaretButtonForName(name) { const menuItem = this.page.locator(`umb-media-tree-item [label="${name}"]`); const isCaretButtonOpen = await menuItem.getAttribute('show-children'); if (isCaretButtonOpen === null) { await this.clickMediaCaretButtonForName(name); } } async doesMediaGridValuesMatch(expectedValues) { return expectedValues.forEach((text, index) => { (0, test_1.expect)(this.mediaCardItemsValues.nth(index)).toHaveText(text); }); } async doesMediaListHeaderValuesMatch(expectedValues) { return expectedValues.forEach((text, index) => { (0, test_1.expect)(this.mediaListHeader.nth(index)).toHaveText(text); }); } async doesMediaListNameValuesMatch(expectedValues) { return expectedValues.forEach((text, index) => { (0, test_1.expect)(this.mediaListNameValues.nth(index)).toHaveText(text); }); } async isMediaGridViewVisible(isVisible = true) { await this.isVisible(this.mediaGridView, isVisible); } async isMediaListViewVisible(isVisible = true) { await this.isVisible(this.mediaListView, isVisible); } async doesMediaWorkspaceHaveText(text) { await this.containsText(this.mediaWorkspace, text); } async clickBulkTrashButton() { await this.click(this.bulkTrashBtn); } async clickBulkMoveToButton() { await this.click(this.bulkMoveToBtn); } async clickModalTextByName(name) { await this.click(this.sidebarModal.getByLabel(name, { exact: true })); } async reloadMediaTree() { await this.click(this.mediaHeader); await this.click(this.mediaHeaderActionsMenu, { force: true }); await this.clickReloadChildrenActionMenuOption(); } async isMediaTreeItemVisible(name, isVisible = true) { return await this.isVisible(this.mediaTreeItem.getByLabel(name, { exact: true }), isVisible); } async doesMediaItemInTreeHaveThumbnail(name, thumbnailIconName) { const mediaThumbnailIconLocator = this.page.locator(`umb-media-tree-item [label="${name}"]`).locator('#icon-container #icon'); await this.hasAttribute(mediaThumbnailIconLocator, 'name', thumbnailIconName); } async isChildMediaVisible(parentName, childName, isVisible = true) { return await this.isVisible(this.mediaTreeItem.filter({ hasText: parentName }).getByText(childName, { exact: true }), isVisible); } async clickCaretButtonForMediaName(name) { await this.click(this.mediaTreeItem.filter({ hasText: name }).last().locator('#caret-button').last()); } async goToMediaWithName(mediaName) { await this.click(this.mediaTreeItem.getByText(mediaName, { exact: true })); } async clickSaveButtonAndWaitForMediaToBeCreated() { return await this.waitForResponseAfterExecutingPromise(ConstantHelper_1.ConstantHelper.apiEndpoints.media, this.clickSaveButton(), ConstantHelper_1.ConstantHelper.statusCodes.created); } async clickSaveButtonAndWaitForMediaToBeUpdated() { return await this.waitForResponseAfterExecutingPromise(ConstantHelper_1.ConstantHelper.apiEndpoints.media, this.clickSaveButton(), ConstantHelper_1.ConstantHelper.statusCodes.ok); } async clickConfirmTrashButtonAndWaitForMediaToBeTrashed() { return await this.waitForResponseAfterExecutingPromise(ConstantHelper_1.ConstantHelper.apiEndpoints.media, this.clickConfirmTrashButton(), ConstantHelper_1.ConstantHelper.statusCodes.ok); } async clickConfirmEmptyRecycleBinButtonAndWaitForRecycleBinToBeEmptied() { return await this.waitForResponseAfterExecutingPromise(ConstantHelper_1.ConstantHelper.apiEndpoints.recycleBinMedia, this.clickConfirmEmptyRecycleBinButton(), ConstantHelper_1.ConstantHelper.statusCodes.ok); } async clickChooseModalButtonAndWaitForMediaItemsToBeMoved(movedMediaItems) { return await this.waitForMultipleResponsesAfterExecutingPromise('/move', this.clickChooseModalButton(), 200, movedMediaItems); } } exports.MediaUiHelper = MediaUiHelper; //# sourceMappingURL=MediaUiHelper.js.map