From f523d03015acbbf7318121246b21b9f4ab1418d7 Mon Sep 17 00:00:00 2001 From: "akash.rathod@hyland.com" Date: Wed, 20 Dec 2023 13:53:40 +0100 Subject: [PATCH] code fix for review --- .../src/tests/sort-list-login.spec.ts | 152 ------------------ .../list-views/src/tests/sort-list.spec.ts | 148 +++++++---------- .../src/api/file-actions.ts | 22 +-- .../dataTable/data-table.component.ts | 19 +-- .../components/pagination.component.ts | 4 +- 5 files changed, 75 insertions(+), 270 deletions(-) delete mode 100644 e2e/playwright/list-views/src/tests/sort-list-login.spec.ts diff --git a/e2e/playwright/list-views/src/tests/sort-list-login.spec.ts b/e2e/playwright/list-views/src/tests/sort-list-login.spec.ts deleted file mode 100644 index c026e7221e..0000000000 --- a/e2e/playwright/list-views/src/tests/sort-list-login.spec.ts +++ /dev/null @@ -1,152 +0,0 @@ -/*! - * Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. - * - * Alfresco Example Content Application - * - * This file is part of the Alfresco Example Content Application. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * The Alfresco Example Content Application is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * The Alfresco Example Content Application is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * from Hyland Software. If not, see . - */ - -import { expect } from '@playwright/test'; -import { - ApiClientFactory, - FileActionsApi, - LoginPage, - NodesApi, - PersonalFilesPage, - TEST_FILES, - Utils, - test, - timeouts -} from '@alfresco/playwright-shared'; - -let initialSortState: { - sortingColumn: string; - sortingOrder: string; - firstElement: string; -}; - -async function getSortState(myPersonalFiles: PersonalFilesPage): Promise { - return { - sortingColumn: await myPersonalFiles.dataTable.getSortedColumnHeaderText(), - sortingOrder: await myPersonalFiles.dataTable.getSortingOrder(), - firstElement: await myPersonalFiles.dataTable.getFirstElementDetail('Name') - }; -} - -test.describe('Remember sorting', () => { - interface NodesIds { - [index: string]: string; - } - - const user1 = `userSortLogin1-${Utils.random()}`; - const user2 = `userSortLogin2-${Utils.random()}`; - const pdfFileNames = [...new Array(14).fill(100)].map((v, i) => `file-${v + i}.pdf`); - const jpgFileNames = [...new Array(12).fill(114)].map((v, i) => `file-${v + i}.jpg`); - - const testData = { - user1: { - files: { - jpg: jpgFileNames, - pdf: pdfFileNames - } - }, - user2: { - files: [pdfFileNames[0], jpgFileNames[0]] - } - }; - - test.beforeAll(async () => { - test.setTimeout(timeouts.extendedTest); - const apiClientFactory = new ApiClientFactory(); - await apiClientFactory.setUpAcaBackend('admin'); - await apiClientFactory.createUser({ username: user1 }); - await apiClientFactory.createUser({ username: user2 }); - const fileActionUser1 = await FileActionsApi.initialize(user1, user1); - const fileActionUser2 = await FileActionsApi.initialize(user2, user2); - const filesIdsUser1: NodesIds = {}; - const filesIdsUser2: NodesIds = {}; - await Promise.all([ - testData.user1.files.pdf.map( - async (i) => (filesIdsUser1[i] = (await fileActionUser1.uploadFileWithRename(TEST_FILES.PDF.path, i, '-my-')).entry.id) - ), - testData.user1.files.jpg.map( - async (i) => (filesIdsUser1[i] = (await fileActionUser1.uploadFileWithRename(TEST_FILES.JPG_FILE.path, i, '-my-')).entry.id) - ), - testData.user2.files.map( - async (i) => (filesIdsUser2[i] = (await fileActionUser2.uploadFileWithRename(TEST_FILES.PDF.path, i, '-my-')).entry.id) - ) - ]); - }); - - test.beforeEach(async ({ page, personalFiles }) => { - const loginPage = new LoginPage(page); - await loginPage.loginUser( - { username: user1, password: user1 }, - { - withNavigation: true, - waitForLoading: true - } - ); - await personalFiles.dataTable.sortBy('Name', 'asc'); - await personalFiles.dataTable.spinnerWaitForReload(); - initialSortState = await getSortState(personalFiles); - }); - - test.afterAll(async () => { - const nodeActionUser1 = await NodesApi.initialize(user1, user1); - const nodeActionUser2 = await NodesApi.initialize(user2, user2); - await nodeActionUser1.deleteCurrentUserNodes(); - await nodeActionUser2.deleteCurrentUserNodes(); - }); - - test.describe('User Tests', () => { - test('[C261137] Size sort order is retained when user logs out and logs back in', async ({ personalFiles, loginPage }) => { - await personalFiles.dataTable.sortBy('Name', 'desc'); - await personalFiles.dataTable.spinnerWaitForReload(); - const expectedSortData = await getSortState(personalFiles); - expect(expectedSortData).not.toEqual(initialSortState); - - await loginPage.logoutUser(); - await FileActionsApi.initialize(user1, user1); - await loginPage.loginUser({ username: user1, password: user1 }, { withNavigation: true, waitForLoading: true }); - - const actualSortData = await getSortState(personalFiles); - expect(actualSortData).toEqual(expectedSortData); - }); - - test('[C261150] Sort order is not retained between different users', async ({ personalFiles, loginPage }) => { - await personalFiles.dataTable.sortBy('Size', 'asc'); - await personalFiles.dataTable.spinnerWaitForReload(); - const expectedSortData = await getSortState(personalFiles); - - await loginPage.logoutUser(); - await FileActionsApi.initialize(user2, user2); - await loginPage.loginUser( - { username: user2, password: user2 }, - { - withNavigation: true, - waitForLoading: true - } - ); - - const actualSortData = await getSortState(personalFiles); - expect(actualSortData).not.toEqual(expectedSortData); - }); - }); -}); diff --git a/e2e/playwright/list-views/src/tests/sort-list.spec.ts b/e2e/playwright/list-views/src/tests/sort-list.spec.ts index 0de0f0fca0..ac61d43280 100644 --- a/e2e/playwright/list-views/src/tests/sort-list.spec.ts +++ b/e2e/playwright/list-views/src/tests/sort-list.spec.ts @@ -27,19 +27,23 @@ import { ApiClientFactory, FavoritesPageApi, FileActionsApi, - LoginPage, NodesApi, + PersonalFilesPage, TEST_FILES, Utils, test, timeouts } from '@alfresco/playwright-shared'; -test.describe('Remember sorting', () => { - interface NodesIds { - [index: string]: string; - } +async function getSortState(myPersonalFiles: PersonalFilesPage): Promise<{ [key: string]: string }> { + return { + sortingColumn: await myPersonalFiles.dataTable.getSortedColumnHeaderText(), + sortingOrder: await myPersonalFiles.dataTable.getSortingOrder(), + firstElement: await myPersonalFiles.dataTable.getFirstElementDetail('Name') + }; +} +test.describe('Remember sorting', () => { const user1 = `userSort1-${Utils.random()}`; const user2 = `userSort2-${Utils.random()}`; const pdfFileNames = [...new Array(14).fill(100)].map((v, i) => `file-${v + i}.pdf`); @@ -60,11 +64,7 @@ test.describe('Remember sorting', () => { } }; - let initialSortState: { - sortingColumn: string; - sortingOrder: string; - firstElement: string; - }; + let initialSortState: { [key: string]: string }; let nodeActionUser1: NodesApi; test.beforeAll(async () => { @@ -77,8 +77,8 @@ test.describe('Remember sorting', () => { const fileActionUser2 = await FileActionsApi.initialize(user2, user2); const favoritesActions = await FavoritesPageApi.initialize(user1, user1); nodeActionUser1 = await NodesApi.initialize(user1, user1); - const filesIdsUser1: NodesIds = {}; - const filesIdsUser2: NodesIds = {}; + const filesIdsUser1: { [key: string]: string } = {}; + const filesIdsUser2: { [key: string]: string } = {}; await Promise.all( testData.user1.files.pdf.map( async (i) => (filesIdsUser1[i] = (await fileActionUser1.uploadFileWithRename(TEST_FILES.PDF.path, i, '-my-')).entry.id) @@ -97,8 +97,8 @@ test.describe('Remember sorting', () => { await favoritesActions.addFavoritesByIds('file', [filesIdsUser1[pdfFileNames[0]], filesIdsUser1[pdfFileNames[1]]]); }); - test.beforeEach(async ({ page, personalFiles }) => { - const loginPage = new LoginPage(page); + test.beforeEach(async ({ loginPage, personalFiles }) => { + await NodesApi.initialize(user1, user1); await loginPage.loginUser( { username: user1, password: user1 }, { @@ -108,11 +108,7 @@ test.describe('Remember sorting', () => { ); await personalFiles.dataTable.sortBy('Name', 'asc'); await personalFiles.dataTable.spinnerWaitForReload(); - initialSortState = { - sortingColumn: await personalFiles.dataTable.getSortedColumnHeaderText(), - sortingOrder: await personalFiles.dataTable.getSortingOrder(), - firstElement: await personalFiles.dataTable.getFirstElementDetail('Name') - }; + initialSortState = await getSortState(personalFiles); }); test.afterAll(async () => { @@ -126,79 +122,43 @@ test.describe('Remember sorting', () => { await personalFiles.dataTable.sortBy('Name', 'desc'); await personalFiles.dataTable.spinnerWaitForReload(); - const expectedSortData = { - sortingColumn: await personalFiles.dataTable.getSortedColumnHeaderText(), - sortingOrder: await personalFiles.dataTable.getSortingOrder(), - firstElement: await personalFiles.dataTable.getFirstElementDetail('Name') - }; - + const expectedSortData = await getSortState(personalFiles); expect(expectedSortData).not.toEqual(initialSortState); await favoritePage.navigate(); await personalFiles.navigate(); - const actualSortData = { - sortingColumn: await personalFiles.dataTable.getSortedColumnHeaderText(), - sortingOrder: await personalFiles.dataTable.getSortingOrder(), - firstElement: await personalFiles.dataTable.getFirstElementDetail('Name') - }; - + const actualSortData = await getSortState(personalFiles); expect(actualSortData).toEqual(expectedSortData); }); test('[C589205] Size sort order is retained after viewing a file and closing the viewer', async ({ personalFiles }) => { await personalFiles.dataTable.sortBy('Size', 'desc'); await personalFiles.dataTable.spinnerWaitForReload(); - - const expectedSortData = { - sortingColumn: await personalFiles.dataTable.getSortedColumnHeaderText(), - sortingOrder: await personalFiles.dataTable.getSortingOrder(), - firstElement: await personalFiles.dataTable.getFirstElementDetail('Name') - }; + const expectedSortData = await getSortState(personalFiles); await personalFiles.dataTable.performClickFolderOrFileToOpen(expectedSortData.firstElement); await personalFiles.viewer.closeButtonLocator.click(); await personalFiles.waitForPageLoad(); - const actualSortData = { - sortingColumn: await personalFiles.dataTable.getSortedColumnHeaderText(), - sortingOrder: await personalFiles.dataTable.getSortingOrder(), - firstElement: await personalFiles.dataTable.getFirstElementDetail('Name') - }; - + const actualSortData = await getSortState(personalFiles); expect(actualSortData).toEqual(expectedSortData); }); test('[C261153] Sort order should be remembered separately on each list view', async ({ personalFiles, favoritePage }) => { await personalFiles.dataTable.sortBy('Size', 'desc'); await personalFiles.dataTable.spinnerWaitForReload(); - - const personalFilesSortData = { - sortingColumn: await personalFiles.dataTable.getSortedColumnHeaderText(), - sortingOrder: await personalFiles.dataTable.getSortingOrder(), - firstElement: await personalFiles.dataTable.getFirstElementDetail('Name') - }; + const personalFilesSortData = await getSortState(personalFiles); await favoritePage.navigate(); await favoritePage.dataTable.sortBy('Name', 'asc'); await favoritePage.dataTable.spinnerWaitForReload(); - const favouritesSortData = { - sortingColumn: await favoritePage.dataTable.getSortedColumnHeaderText(), - sortingOrder: await favoritePage.dataTable.getSortingOrder(), - firstElement: await favoritePage.dataTable.getFirstElementDetail('Name') - }; - + const favouritesSortData = await getSortState(personalFiles); expect(favouritesSortData).not.toEqual(personalFilesSortData); await personalFiles.navigate(); - - const personalFilesSortDataAfterFavSort = { - sortingColumn: await personalFiles.dataTable.getSortedColumnHeaderText(), - sortingOrder: await personalFiles.dataTable.getSortingOrder(), - firstElement: await personalFiles.dataTable.getFirstElementDetail('Name') - }; - + const personalFilesSortDataAfterFavSort = await getSortState(personalFiles); expect(personalFilesSortDataAfterFavSort).toEqual(personalFilesSortData); }); @@ -215,35 +175,24 @@ test.describe('Remember sorting', () => { firstElement: lastFileInArray }; - let currentPersonalFilesSortDataPage2 = { - sortingColumn: await personalFiles.dataTable.getSortedColumnHeaderText(), - sortingOrder: await personalFiles.dataTable.getSortingOrder(), - firstElement: await personalFiles.dataTable.getFirstElementDetail('Name') - }; - + let currentPersonalFilesSortDataPage2 = await getSortState(personalFiles); expect(currentPersonalFilesSortDataPage2).toEqual(expectedPersonalFilesSortDataPage2); await personalFiles.dataTable.sortBy('Name', 'desc'); await personalFiles.dataTable.spinnerWaitForReload(); - expectedPersonalFilesSortDataPage2 = { sortingColumn: 'Name', sortingOrder: 'desc', firstElement: firstFileInArray }; - currentPersonalFilesSortDataPage2 = { - sortingColumn: await personalFiles.dataTable.getSortedColumnHeaderText(), - sortingOrder: await personalFiles.dataTable.getSortingOrder(), - firstElement: await personalFiles.dataTable.getFirstElementDetail('Name') - }; - + currentPersonalFilesSortDataPage2 = await getSortState(personalFiles); expect(expectedPersonalFilesSortDataPage2).toEqual(currentPersonalFilesSortDataPage2); }); test.describe('Folder actions', () => { test.beforeAll(async () => { - const folderIds: NodesIds = {}; + const folderIds: { [key: string]: string } = {}; folderIds[folderToContain] = (await nodeActionUser1.createFolder(folderToContain)).entry.id; folderIds[folderToMove] = (await nodeActionUser1.createFolder(folderToMove)).entry.id; }); @@ -262,12 +211,7 @@ test.describe('Remember sorting', () => { await personalFiles.folderDialog.createNewFolderDialog(uiCreatedFolder); await personalFiles.dataTable.isItemPresent(uiCreatedFolder); - const actualSortData = { - sortingColumn: await personalFiles.dataTable.getSortedColumnHeaderText(), - sortingOrder: await personalFiles.dataTable.getSortingOrder(), - firstElement: await personalFiles.dataTable.getFirstElementDetail('Name') - }; - + const actualSortData = await getSortState(personalFiles); expect(actualSortData).toEqual(expectedSortData); }); @@ -279,13 +223,43 @@ test.describe('Remember sorting', () => { }; await personalFiles.copyOrMoveContentInDatatable([folderToMove], folderToContain, 'Move'); await personalFiles.dataTable.spinnerWaitForReload(); - const actualSortData = { - sortingColumn: await personalFiles.dataTable.getSortedColumnHeaderText(), - sortingOrder: await personalFiles.dataTable.getSortingOrder(), - firstElement: await personalFiles.dataTable.getFirstElementDetail('Name') - }; + const actualSortData = await getSortState(personalFiles); + expect(actualSortData).toEqual(expectedSortData); + }); + }); + + test.describe('User Tests', () => { + test('[C261137] Size sort order is retained when user logs out and logs back in', async ({ personalFiles, loginPage }) => { + await personalFiles.dataTable.sortBy('Name', 'desc'); + await personalFiles.dataTable.spinnerWaitForReload(); + const expectedSortData = await getSortState(personalFiles); + expect(expectedSortData).not.toEqual(initialSortState); + + await loginPage.logoutUser(); + await FileActionsApi.initialize(user1, user1); + await loginPage.loginUser({ username: user1, password: user1 }, { withNavigation: true, waitForLoading: true }); + const actualSortData = await getSortState(personalFiles); expect(actualSortData).toEqual(expectedSortData); }); + + test('[C261150] Sort order is not retained between different users', async ({ personalFiles, loginPage }) => { + await personalFiles.dataTable.sortBy('Size', 'asc'); + await personalFiles.dataTable.spinnerWaitForReload(); + const expectedSortData = await getSortState(personalFiles); + + await loginPage.logoutUser(); + await FileActionsApi.initialize(user2, user2); + await loginPage.loginUser( + { username: user2, password: user2 }, + { + withNavigation: true, + waitForLoading: true + } + ); + + const actualSortData = await getSortState(personalFiles); + expect(actualSortData).not.toEqual(expectedSortData); + }); }); }); diff --git a/projects/aca-playwright-shared/src/api/file-actions.ts b/projects/aca-playwright-shared/src/api/file-actions.ts index 4285d1a82c..6b41de50e4 100644 --- a/projects/aca-playwright-shared/src/api/file-actions.ts +++ b/projects/aca-playwright-shared/src/api/file-actions.ts @@ -41,7 +41,7 @@ export class FileActionsApi { return classObj; } - async uploadFile(fileLocation: string, fileName: string, parentFolderId: string): Promise { + async uploadFile(fileLocation: string, fileName: string, parentFolderId: string): Promise { const file = fs.createReadStream(fileLocation); return this.apiService.upload.uploadFile(file, '', parentFolderId, null, { name: fileName, @@ -56,7 +56,7 @@ export class FileActionsApi { parentId: string = '-my-', title: string = '', description: string = '' - ): Promise { + ): Promise { const file = fs.createReadStream(fileLocation); const nodeProps = { properties: { @@ -74,11 +74,11 @@ export class FileActionsApi { return await this.apiService.upload.uploadFile(file, '', parentId, nodeProps, opts); } catch (error) { Logger.error(`${this.constructor.name} ${this.uploadFileWithRename.name}`, error); - return null; + return Promise.reject(error); } } - async lockNodes(nodeIds: string[], lockType: string = 'ALLOW_OWNER_CHANGES') { + async lockNodes(nodeIds: string[], lockType: string = 'ALLOW_OWNER_CHANGES'): Promise { try { for (const nodeId of nodeIds) { await this.apiService.nodes.lockNode(nodeId, { type: lockType }); @@ -175,23 +175,17 @@ export class FileActionsApi { } } - async updateNodeContent( - nodeId: string, - content: string, - majorVersion: boolean = true, - comment?: string, - newName?: string - ): Promise { + async updateNodeContent(nodeId: string, content: string, majorVersion: boolean = true, comment?: string, newName?: string): Promise { try { const opts = { - majorVersion, - comment, + majorVersion: majorVersion, + comment: comment, name: newName }; return await this.apiService.nodes.updateNodeContent(nodeId, content, opts); } catch (error) { console.error(`${this.constructor.name} ${this.updateNodeContent.name}`, error); - return null; + return Promise.reject(error); } } } diff --git a/projects/aca-playwright-shared/src/page-objects/components/dataTable/data-table.component.ts b/projects/aca-playwright-shared/src/page-objects/components/dataTable/data-table.component.ts index 1a618fe2ac..95df52d4be 100644 --- a/projects/aca-playwright-shared/src/page-objects/components/dataTable/data-table.component.ts +++ b/projects/aca-playwright-shared/src/page-objects/components/dataTable/data-table.component.ts @@ -48,6 +48,7 @@ export class DataTableComponent extends BaseComponent { emptyListTitle = this.getChild('.adf-empty-content__title'); emptyListSubtitle = this.getChild('.adf-empty-content__subtitle'); emptySearchText = this.getChild('.empty-search__text'); + emptyListTest = this.getChild('adf-custom-empty-content-template'); /** Locator for row (or rows) */ getRowLocator = this.getChild(`adf-datatable-row`); @@ -300,27 +301,15 @@ export class DataTableComponent extends BaseComponent { } async getEmptyStateTitle(): Promise { - const isEmpty = await this.isEmpty(); - if (isEmpty) { - return this.emptyListTitle.innerText(); - } - return ''; + return (await this.isEmpty()) ? this.emptyListTitle.innerText() : ''; } async getEmptyStateSubtitle(): Promise { - const isEmpty = await this.isEmpty(); - if (isEmpty) { - return this.emptyListSubtitle.innerText(); - } - return ''; + return (await this.isEmpty()) ? this.emptyListSubtitle.innerText() : ''; } async getEmptyListText(): Promise { - const isEmpty = await this.isEmpty(); - if (isEmpty) { - return this.getChild('adf-custom-empty-content-template').innerText(); - } - return ''; + return (await this.isEmpty()) ? this.emptyListTest.innerText() : ''; } async getRowsCount(): Promise { diff --git a/projects/aca-playwright-shared/src/page-objects/components/pagination.component.ts b/projects/aca-playwright-shared/src/page-objects/components/pagination.component.ts index dd73f11e64..ff58672902 100644 --- a/projects/aca-playwright-shared/src/page-objects/components/pagination.component.ts +++ b/projects/aca-playwright-shared/src/page-objects/components/pagination.component.ts @@ -167,11 +167,11 @@ export class PaginationComponent extends BaseComponent { await this.page.keyboard.press('Escape'); } - async isRangePresent() { + async isRangePresent(): Promise { return this.range.isVisible(); } - async isMaxItemsPresent() { + async isMaxItemsPresent(): Promise { return this.maxItems.isVisible(); } }