Skip to content

Commit

Permalink
[ACS-8951] [E2E] tags and categories e2es added in ACA (#4210)
Browse files Browse the repository at this point in the history
* [ACS-8951] [E2E] tags and categories e2es added in ACA

* [ACS-8951] sonar fix 1

* [ACS-8951] added tag deletion in afterAll

* [ACS-8951] added tag deletion

* [ACS-8951] sonar fix 2

* [ACS-8951] review fix 1

* [ACS-8951] Small code cleanup

* [ACS-8951] review fix 2

* [ACS-8951] review fix 3
  • Loading branch information
datguychen authored Nov 6, 2024
1 parent b68db2e commit 62f38ee
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 21 deletions.
219 changes: 199 additions & 20 deletions e2e/playwright/info-drawer/src/tests/file-folder-properties.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,64 @@
*/

import { expect } from '@playwright/test';
import { ApiClientFactory, Utils, test, TrashcanApi, NodesApi, FileActionsApi } from '@alfresco/aca-playwright-shared';
import {
ApiClientFactory,
Utils,
test,
TrashcanApi,
NodesApi,
FileActionsApi,
TagsApi,
CategoriesApi,
PersonalFilesPage
} from '@alfresco/aca-playwright-shared';

test.describe('Info Drawer - File Folder Properties', () => {
let nodesApi: NodesApi;
let trashcanApi: TrashcanApi;
let fileActionsApi: FileActionsApi;
let tagsApi: TagsApi;
let categoriesApi: CategoriesApi;
let responseCategoryId: string;
let responseTagsId: string;
let Folder17239Id: string;
let Folder17240Id: string;
let Folder17242Id: string;
const username = `user-e2e-${Utils.random()}`;
const manualTagName = `e2e-tag-${Utils.random()}`;
const FolderC299162 = `C299162-e2e-${Utils.random()}`;
const FolderC599174 = `C599174-e2e-${Utils.random()}`;
const Folder17238 = `xat-17238-e2e-${Utils.random()}`;
const Folder17239 = `xat-17239-e2e-${Utils.random()}`;
const Folder17240 = `xat-17240-e2e-${Utils.random()}`;
const Folder17241 = `xat-17241-e2e-${Utils.random()}`;
const Folder17242 = `xat-17242-e2e-${Utils.random()}`;
const Folder17243 = `xat-17243-e2e-${Utils.random()}`;
const Folder17244 = `xat-17244-e2e-${Utils.random()}`;
const tagBody = { tag: `tag-${Utils.random()}` };
const categoryName = Utils.random();
const noCategoriesText = 'There are currently no categories added';
const noTagsText = 'There are currently no tags added';

async function createCategoryGetId(): Promise<string> {
const createdCategory = await categoriesApi.createCategory(`-root-`, [{ name: categoryName }]);
if ('entry' in createdCategory) {
return createdCategory.entry.id;
} else {
console.error('Unexpected response format:', createdCategory);
return null;
}
}

async function createTagGetId(): Promise<string> {
const createdTag = await tagsApi.createTags([tagBody]);
if ('entry' in createdTag) {
return (createdTag as { entry: { id: string } }).entry.id;
} else {
console.error('Unexpected response format:', createdTag);
return null;
}
}

test.beforeAll(async () => {
try {
Expand All @@ -39,6 +90,24 @@ test.describe('Info Drawer - File Folder Properties', () => {
nodesApi = await NodesApi.initialize(username, username);
trashcanApi = await TrashcanApi.initialize(username, username);
fileActionsApi = await FileActionsApi.initialize(username, username);
tagsApi = await TagsApi.initialize('admin');
categoriesApi = await CategoriesApi.initialize('admin');
responseCategoryId = await createCategoryGetId();
responseTagsId = await createTagGetId();

if (responseCategoryId === null || responseTagsId === null) {
throw new Error('Failed to create category or tag - check API manually');
}

await nodesApi.createFolder(FolderC299162);
await nodesApi.createFolder(FolderC599174);
await nodesApi.createFolder(Folder17238);
Folder17239Id = (await nodesApi.createFolder(Folder17239)).entry.id;
Folder17240Id = (await nodesApi.createFolder(Folder17240)).entry.id;
await nodesApi.createFolder(Folder17241);
Folder17242Id = (await nodesApi.createFolder(Folder17242)).entry.id;
await nodesApi.createFolder(Folder17243);
await nodesApi.createFolder(Folder17244);
} catch (error) {
console.error(`beforeAll failed : ${error}`);
}
Expand All @@ -50,41 +119,151 @@ test.describe('Info Drawer - File Folder Properties', () => {

test.afterAll(async () => {
await Utils.deleteNodesSitesEmptyTrashcan(nodesApi, trashcanApi, 'afterAll failed');
await categoriesApi.deleteCategory(responseCategoryId);
await tagsApi.deleteTag(responseTagsId);
});

test('[C299162] View properties - Default tabs', async ({ personalFiles }) => {
const defaultTabsFolderName = `defaultTabsFolder-e2e-${Utils.random()}`;
await nodesApi.createFolder(defaultTabsFolderName);
await fileActionsApi.waitForNodes(defaultTabsFolderName, { expect: 1 });
async function navigateAndOpenInfoDrawer(personalFiles: PersonalFilesPage, folderName: string) {
await fileActionsApi.waitForNodes(folderName, { expect: 1 });
await personalFiles.navigate();
await Utils.reloadPageIfRowNotVisible(personalFiles, defaultTabsFolderName);
await expect(personalFiles.dataTable.getRowByName(defaultTabsFolderName)).toBeVisible();
await personalFiles.dataTable.getRowByName(defaultTabsFolderName).click();
await Utils.reloadPageIfRowNotVisible(personalFiles, folderName);
await expect(personalFiles.dataTable.getRowByName(folderName)).toBeVisible();
await personalFiles.dataTable.getRowByName(folderName).click();
await personalFiles.acaHeader.viewDetails.click();
}

async function waitForTagToBeAdded(folderId: string, personalFiles: PersonalFilesPage, maxRetries: number) {
let retries = 0;

while ((await tagsApi.listTagsForNode(folderId)).list.entries.length === 0) {
if (retries >= maxRetries) {
throw new Error('Tag was not added within the expected time frame.');
}
await personalFiles.page.waitForTimeout(1000);
retries++;
}
}

expect(await personalFiles.infoDrawer.getHeaderTitle()).toEqual(defaultTabsFolderName);
test('[C299162] View properties - Default tabs', async ({ personalFiles }) => {
await navigateAndOpenInfoDrawer(personalFiles, FolderC299162);
expect(await personalFiles.infoDrawer.getHeaderTitle()).toEqual(FolderC299162);
await expect(personalFiles.infoDrawer.propertiesTab).toBeVisible();
await expect(personalFiles.infoDrawer.commentsTab).toBeVisible();
expect(await personalFiles.infoDrawer.getTabsCount()).toEqual(2);
});

test('[C599174] View properties - Should be able to make the files/folders info drawer expandable as for Sites', async ({ personalFiles }) => {
const expandDetailsFolderName = `expandDetailsFolder-e2e-${Utils.random()}`;
await nodesApi.createFolder(expandDetailsFolderName);
await fileActionsApi.waitForNodes(expandDetailsFolderName, { expect: 1 });
await personalFiles.navigate();
await Utils.reloadPageIfRowNotVisible(personalFiles, expandDetailsFolderName);
await expect(personalFiles.dataTable.getRowByName(expandDetailsFolderName)).toBeVisible();
await personalFiles.dataTable.getRowByName(expandDetailsFolderName).click();
await personalFiles.acaHeader.viewDetails.click();

await navigateAndOpenInfoDrawer(personalFiles, FolderC599174);
await personalFiles.infoDrawer.expandDetailsButton.click();
await expect(personalFiles.infoDrawer.expandedDetailsPermissionsTab).toBeVisible();

await personalFiles.navigate();
await expect(personalFiles.dataTable.getRowByName(expandDetailsFolderName)).toBeVisible();
await personalFiles.dataTable.getRowByName(expandDetailsFolderName).click({ button: 'right' });
await expect(personalFiles.dataTable.getRowByName(FolderC599174)).toBeVisible();
await personalFiles.dataTable.getRowByName(FolderC599174).click({ button: 'right' });
await personalFiles.pagination.clickMenuItem('Permissions');
await expect(personalFiles.infoDrawer.expandedDetailsPermissionsTab).toBeVisible();
});

test('[XAT-17238] State for no tags and categories - accordion expanded', async ({ personalFiles }) => {
await navigateAndOpenInfoDrawer(personalFiles, Folder17238);
await personalFiles.infoDrawer.tagsAccordion.click();
await expect(personalFiles.infoDrawer.tagsAccordion).toContainText(noTagsText);

await personalFiles.infoDrawer.categoriesAccordion.click();
await expect(personalFiles.infoDrawer.categoriesAccordion).toContainText(noCategoriesText);
});

test('[XAT-17239] Add a new tag to a node', async ({ personalFiles }) => {
await navigateAndOpenInfoDrawer(personalFiles, Folder17239);
await personalFiles.infoDrawer.tagsAccordionPenButton.click();
await expect(personalFiles.infoDrawer.tagsAccordionPenButton).toBeHidden();
await expect(personalFiles.infoDrawer.tagsAccordionCancelButton).toBeEnabled();
await expect(personalFiles.infoDrawer.tagsAccordionConfirmButton).toBeDisabled();
await personalFiles.infoDrawer.tagsInput.fill(manualTagName);
await personalFiles.infoDrawer.createTagButton.click();
await expect(personalFiles.infoDrawer.tagsChips.first()).toContainText(manualTagName);
await expect(personalFiles.infoDrawer.tagsChipsXButton.first()).toBeVisible();
await personalFiles.infoDrawer.tagsAccordionConfirmButton.click();
await expect(personalFiles.infoDrawer.tagsChipsXButton.first()).toBeHidden();
await expect(personalFiles.infoDrawer.tagsAccordionPenButton).toBeVisible();

await waitForTagToBeAdded(Folder17239Id, personalFiles, 10);
const tagId = (await tagsApi.listTagsForNode(Folder17239Id)).list.entries[0].entry.id;
await tagsApi.deleteTag(tagId);
});

test('[XAT-17240] Remove a tag from a node', async ({ personalFiles }) => {
await fileActionsApi.waitForNodes(Folder17240, { expect: 1 });
await tagsApi.assignTagToNode(Folder17240Id, tagBody);
await personalFiles.navigate();
await Utils.reloadPageIfRowNotVisible(personalFiles, Folder17240);
await expect(personalFiles.dataTable.getRowByName(Folder17240)).toBeVisible();
await personalFiles.dataTable.getRowByName(Folder17240).click();
await personalFiles.acaHeader.viewDetails.click();

await personalFiles.infoDrawer.tagsAccordion.click();
await expect(personalFiles.infoDrawer.tagsChipsXButton.first()).toBeHidden();
await personalFiles.infoDrawer.tagsAccordionPenButton.click();
await personalFiles.infoDrawer.tagsChipsXButton.first().click();
await personalFiles.infoDrawer.tagsAccordionConfirmButton.click();
await expect(personalFiles.infoDrawer.tagsChips.first()).toBeHidden();
await expect(personalFiles.infoDrawer.tagsAccordion).toContainText(noTagsText);
});

test('[XAT-17243] Cancel adding a tag to a node', async ({ personalFiles }) => {
await fileActionsApi.waitForNodes(Folder17243, { expect: 1 });
await personalFiles.navigate();
await Utils.reloadPageIfRowNotVisible(personalFiles, Folder17243);
await expect(personalFiles.dataTable.getRowByName(Folder17243)).toBeVisible();
await personalFiles.dataTable.getRowByName(Folder17243).click();
await personalFiles.acaHeader.viewDetails.click();

await personalFiles.infoDrawer.tagsAccordionPenButton.click();
await personalFiles.infoDrawer.tagsInput.fill(manualTagName);
await personalFiles.infoDrawer.tagsAccordionCancelButton.click();
await expect(personalFiles.infoDrawer.tagsAccordionPenButton).toBeVisible();
await expect(personalFiles.infoDrawer.tagsAccordion).toContainText(noTagsText);
});

test('[XAT-17241] Add a new category to a node', async ({ personalFiles }) => {
await navigateAndOpenInfoDrawer(personalFiles, Folder17241);
await personalFiles.infoDrawer.categoriesAccordionPenButton.click();
await expect(personalFiles.infoDrawer.categoriesAccordionPenButton).toBeHidden();
await expect(personalFiles.infoDrawer.categoriesAccordionCancelButton).toBeEnabled();
await expect(personalFiles.infoDrawer.categoriesAccordionConfirmButton).toBeDisabled();
await personalFiles.infoDrawer.categoriesInput.fill('*');
await personalFiles.infoDrawer.categoriesListItems.first().click();
await expect(personalFiles.infoDrawer.categoriesItemRemoveButton.first()).toBeVisible();
await personalFiles.infoDrawer.categoriesAccordionConfirmButton.click();
await expect(personalFiles.infoDrawer.tagsChipsXButton.first()).toBeHidden();
await expect(personalFiles.infoDrawer.tagsAccordionPenButton).toBeVisible();
await expect(personalFiles.infoDrawer.categoriesAccordion).not.toContainText(noCategoriesText);
await expect(personalFiles.infoDrawer.categoriesCreatedList.first()).toBeVisible();
});

test('[XAT-17242] Remove a category from a node', async ({ personalFiles }) => {
await fileActionsApi.waitForNodes(Folder17242, { expect: 1 });
await categoriesApi.linkNodeToCategory(Folder17242Id, [{ categoryId: responseCategoryId }]);
await personalFiles.navigate();
await Utils.reloadPageIfRowNotVisible(personalFiles, Folder17242);
await expect(personalFiles.dataTable.getRowByName(Folder17242)).toBeVisible();
await personalFiles.dataTable.getRowByName(Folder17242).click();
await personalFiles.acaHeader.viewDetails.click();

await personalFiles.infoDrawer.categoriesAccordion.click();
await expect(personalFiles.infoDrawer.categoriesAccordion).not.toContainText(noCategoriesText);
await personalFiles.infoDrawer.categoriesAccordionPenButton.click();
await personalFiles.infoDrawer.categoriesItemRemoveButton.first().click();
await personalFiles.infoDrawer.categoriesAccordionConfirmButton.click();
await expect(personalFiles.infoDrawer.categoriesAccordion).toContainText(noCategoriesText);
});

test('[XAT-17244] Cancel adding a category to a node', async ({ personalFiles }) => {
await navigateAndOpenInfoDrawer(personalFiles, Folder17244);
await personalFiles.infoDrawer.categoriesAccordionPenButton.click();
await personalFiles.infoDrawer.categoriesInput.fill('*');
await personalFiles.infoDrawer.categoriesListItems.first().click();
await personalFiles.infoDrawer.categoriesAccordionCancelButton.click();
await expect(personalFiles.infoDrawer.categoriesAccordion).toContainText(noCategoriesText);
});
});
11 changes: 10 additions & 1 deletion projects/aca-playwright-shared/src/api/tags-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { TagBody, TagEntry } from '@alfresco/js-api';
import { TagBody, TagEntry, TagPaging } from '@alfresco/js-api';
import { ApiClientFactory } from './api-client-factory';

export class TagsApi {
Expand Down Expand Up @@ -63,4 +63,13 @@ export class TagsApi {
console.error(error);
}
}

async listTagsForNode(nodeId: string): Promise<TagPaging> {
try {
return this.apiService.tagsApi.listTagsForNode(nodeId);
} catch (error) {
console.error(error);
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export class AdfInfoDrawerComponent extends BaseComponent {
super(page, AdfInfoDrawerComponent.rootElement);
}

private readonly categoriesManagement = this.getChild('adf-categories-management');
private readonly tagsCreator = this.getChild('adf-tags-creator');

public getNameField = (labelText: string) =>
this.getChild(`[data-automation-id="library-name-properties-wrapper"] input[placeholder='${labelText}']`);
public getIdField = (labelText: string) => this.getChild(`[data-automation-id="library-id-properties-wrapper"] input[placeholder='${labelText}']`);
Expand Down Expand Up @@ -63,6 +66,22 @@ export class AdfInfoDrawerComponent extends BaseComponent {
public descriptionField = this.page.locator('textarea[placeholder=Description]');
public visibilityField = this.infoDrawerPanel.getByRole('combobox');
public selectVisibility = (visibilityOption: string) => this.page.getByRole('listbox').getByRole('option', { name: visibilityOption }).click();
public tagsAccordion = this.getChild('[data-automation-id="adf-content-metadata-tags-panel"]');
public categoriesAccordion = this.getChild('[data-automation-id="adf-content-metadata-categories-panel"]');
public tagsAccordionPenButton = this.tagsAccordion.locator('[data-automation-id="showing-tag-input-button"]');
public categoriesAccordionPenButton = this.categoriesAccordion.locator('[data-automation-id="meta-data-categories-edit"]');
public tagsInput = this.tagsCreator.locator('input');
public createTagButton = this.tagsCreator.locator('[role="button"]');
public tagsChips = this.tagsCreator.locator('mat-chip');
public tagsChipsXButton = this.tagsChips.locator('button');
public tagsAccordionCancelButton = this.getChild('[data-automation-id="reset-tags-metadata"]');
public tagsAccordionConfirmButton = this.getChild('[data-automation-id="save-tags-metadata"]');
public categoriesAccordionCancelButton = this.getChild('[data-automation-id="reset-metadata"]');
public categoriesAccordionConfirmButton = this.getChild('[data-automation-id="save-categories-metadata"]');
public categoriesInput = this.categoriesManagement.locator('input');
public categoriesListItems = this.categoriesManagement.locator('mat-list-item');
public categoriesItemRemoveButton = this.categoriesManagement.locator('[data-automation-id="categories-remove-category-button"]');
public categoriesCreatedList = this.getChild('.adf-metadata-categories');

async checkCommentsHeaderCount(): Promise<number> {
const commentsCountTextContent = await this.commentsHeader.textContent();
Expand Down

0 comments on commit 62f38ee

Please sign in to comment.