From 4fceade50cd9ea3ba62373736f61878575de8870 Mon Sep 17 00:00:00 2001 From: Katarzyna Kita Date: Mon, 10 Jun 2024 13:45:57 +0200 Subject: [PATCH] CR comments fixes --- .../src/tests/mark-favorite.e2e.ts | 30 ++++++++----------- .../src/api/favorites-api.ts | 10 +------ .../page-objects/pages/personal-files.page.ts | 8 +++++ 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/e2e/playwright/favorite-actions/src/tests/mark-favorite.e2e.ts b/e2e/playwright/favorite-actions/src/tests/mark-favorite.e2e.ts index af18b7a243..76232fd402 100644 --- a/e2e/playwright/favorite-actions/src/tests/mark-favorite.e2e.ts +++ b/e2e/playwright/favorite-actions/src/tests/mark-favorite.e2e.ts @@ -142,46 +142,40 @@ test.describe('Mark items as favorites', () => { }); test('favorite a file', async ({ personalFiles }) => { - await personalFiles.dataTable.selectItem(fileNotFav1); - await personalFiles.acaHeader.clickMoreActions(); - await personalFiles.matMenu.clickMenuItem('Favorite'); + await personalFiles.selectItemsAndToggleFavorite([fileNotFav1], 'Favorite'); + expect(await favoritesApi.isFavoriteWithRetry(username, fileNotFav1Id, { expect: true })).toBe(true); }); test('favorite a folder', async ({ personalFiles }) => { - await personalFiles.dataTable.selectItem(folder); - await personalFiles.acaHeader.clickMoreActions(); - await personalFiles.matMenu.clickMenuItem('Favorite'); + await personalFiles.selectItemsAndToggleFavorite([folder], 'Favorite'); + expect(await favoritesApi.isFavoriteWithRetry(username, folderId, { expect: true })).toBe(true); }); test('unfavorite an item', async ({ personalFiles }) => { - await personalFiles.dataTable.selectItem(fileFav1); - await personalFiles.acaHeader.clickMoreActions(); - await personalFiles.matMenu.clickMenuItem('Remove Favorite'); + await personalFiles.selectItemsAndToggleFavorite([fileFav1], 'Remove Favorite'); + expect(await favoritesApi.isFavoriteWithRetry(username, fileFav1Id, { expect: false })).toBe(false); }); test('favorite multiple items - all unfavorite', async ({ personalFiles }) => { - await personalFiles.dataTable.selectMultiItem(fileNotFav2, fileNotFav3); - await personalFiles.acaHeader.clickMoreActions(); - await personalFiles.matMenu.clickMenuItem('Favorite'); + await personalFiles.selectItemsAndToggleFavorite([fileNotFav2, fileNotFav3], 'Favorite'); + expect(await favoritesApi.isFavoriteWithRetry(username, fileNotFav2Id, { expect: true })).toBe(true); expect(await favoritesApi.isFavoriteWithRetry(username, fileNotFav3Id, { expect: true })).toBe(true); }); test('favorite multiple items - some favorite and some unfavorite', async ({ personalFiles }) => { - await personalFiles.dataTable.selectMultiItem(fileNotFav4, fileFav2); - await personalFiles.acaHeader.clickMoreActions(); - await personalFiles.matMenu.clickMenuItem('Favorite'); + await personalFiles.selectItemsAndToggleFavorite([fileNotFav4, fileFav2], 'Favorite'); + expect(await favoritesApi.isFavoriteWithRetry(username, fileNotFav4Id, { expect: true })).toBe(true); expect(await favoritesApi.isFavoriteWithRetry(username, fileFav2Id, { expect: true })).toBe(true); }); test('unfavorite multiple items', async ({ personalFiles }) => { - await personalFiles.dataTable.selectMultiItem(fileFav3, fileFav4); - await personalFiles.acaHeader.clickMoreActions(); - await personalFiles.matMenu.clickMenuItem('Remove Favorite'); + await personalFiles.selectItemsAndToggleFavorite([fileFav3, fileFav4], 'Remove Favorite'); + expect(await favoritesApi.isFavoriteWithRetry(username, fileFav3Id, { expect: false })).toBe(false); expect(await favoritesApi.isFavoriteWithRetry(username, fileFav4Id, { expect: false })).toBe(false); }); diff --git a/projects/aca-playwright-shared/src/api/favorites-api.ts b/projects/aca-playwright-shared/src/api/favorites-api.ts index 2190c87472..d676a81c73 100755 --- a/projects/aca-playwright-shared/src/api/favorites-api.ts +++ b/projects/aca-playwright-shared/src/api/favorites-api.ts @@ -116,19 +116,11 @@ export class FavoritesPageApi { } catch {} } - async removeFavoriteById(username: string, nodeId: string): Promise { - try { - await this.apiService.favorites.deleteFavorite(username, nodeId); - } catch (error) { - console.error('FavoritesApi: removeFavoriteById failed ', error); - } - } - async removeFavoritesByIds(username: string, ids: string[]): Promise { try { if (ids && ids.length > 0) { for (const id of ids) { - await this.removeFavoriteById(username, id); + await this.apiService.favorites.deleteFavorite(username, id); } } } catch (error) { diff --git a/projects/aca-playwright-shared/src/page-objects/pages/personal-files.page.ts b/projects/aca-playwright-shared/src/page-objects/pages/personal-files.page.ts index dcf7f17dc2..9b3eea07b3 100644 --- a/projects/aca-playwright-shared/src/page-objects/pages/personal-files.page.ts +++ b/projects/aca-playwright-shared/src/page-objects/pages/personal-files.page.ts @@ -103,4 +103,12 @@ export class PersonalFilesPage extends BasePage { await this.contentNodeSelector.selectDestination(destinationName); await this.contentNodeSelector.actionButton.click(); } + + async selectItemsAndToggleFavorite(item: string[], action: 'Favorite' | 'Remove Favorite') { + for (const itemToSelect of item) { + await this.dataTable.selectItem(itemToSelect); + } + await this.acaHeader.clickMoreActions(); + await this.matMenu.clickMenuItem(action); + } }