Skip to content

Commit

Permalink
[ACS-5688] create folder tests update
Browse files Browse the repository at this point in the history
  • Loading branch information
azakrzewski-hy committed Nov 14, 2023
1 parent 4877a05 commit e234814
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 111 deletions.
156 changes: 79 additions & 77 deletions e2e/playwright/actions/src/tests/create-folder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,65 +23,73 @@
*/

import { expect } from '@playwright/test';
import { ApiClientFactory, Utils, folderErrors, getUserState, test } from '@alfresco/playwright-shared';
import {
AdfFolderDialogComponent,
ApiClientFactory,
DataTableComponent,
LoginPage,
NodesApi,
Utils,
errorStrings,
test
} from '@alfresco/playwright-shared';
import { logger } from '@alfresco/adf-cli/scripts/logger';

test.use({ storageState: getUserState('hruser') });
test.describe('Create folders', () => {
const apiClientFactory = new ApiClientFactory();
let nodesApi: NodesApi;
let folderDialog: AdfFolderDialogComponent;
let folderTable: DataTableComponent;
let randomFolderName: string;
let randomFolderTitle: string;
let randomFolderDescription: string;
const dialogString = 'dialog';
const createNewFolderString = 'Create new folder';
const spacesString = ' ';
const commonFolderName = `playwright-folder-${Utils.random()}`;
let folderId: string;
const username = `user-${Utils.random()}`;

test.beforeAll(async () => {
await apiClientFactory.setUpAcaBackend('hruser');
const node = await apiClientFactory.nodes.createNode('-my-', { name: commonFolderName, nodeType: 'cm:folder' });
folderId = node.entry.id;
try {
await apiClientFactory.setUpAcaBackend('admin');
await apiClientFactory.createUser({ username });
nodesApi = await NodesApi.initialize(username, username);
await nodesApi.createFolder(commonFolderName);
} catch (error) {
logger.error(`beforeAll failed : ${error}`);
}
});

test.beforeEach(async ({ personalFiles }) => {
test.beforeEach(async ({ personalFiles, page }) => {
randomFolderName = `playwright-folder-${Utils.random()}`;
randomFolderTitle = `folder-title-${Utils.random()}`;
randomFolderDescription = `folder-description-${Utils.random()}`;
await personalFiles.navigate();
folderDialog = personalFiles.folderDialog;
const loginPage = new LoginPage(page);
try {
await loginPage.loginUser(
{ username: username, password: username },
{
withNavigation: true,
waitForLoading: true
}
);
await personalFiles.navigate();
await personalFiles.selectCreateFolder();
} catch (error) {
logger.error(`beforeEach failed : ${error}`);
}
});

test.afterAll(async () => {
await apiClientFactory.nodes.deleteNode(folderId, { permanent: true });
});

test('[C216341] Create a folder with name only', async ({ personalFiles }) => {
const folderDialog = personalFiles.folderDialog;
const folderTable = personalFiles.dataTable;

await personalFiles.selectCreateFolder();
await folderDialog.createNewFolderDialog(randomFolderName);

await folderTable.goThroughPagesLookingForRowWithName(randomFolderName);
await expect(folderTable.getRowByName(randomFolderName)).toBeVisible();

await folderTable.performActionInExpandableMenu(randomFolderName, 'Delete');
});

test('[C216340] Create a folder with name, title and description', async ({ personalFiles }) => {
const folderDialog = personalFiles.folderDialog;
const folderTable = personalFiles.dataTable;

await personalFiles.selectCreateFolder();
await folderDialog.createNewFolderDialog(randomFolderName, randomFolderTitle, randomFolderDescription);

await folderTable.goThroughPagesLookingForRowWithName(randomFolderName);
await expect(folderTable.getCellLinkByName(randomFolderName)).toHaveAttribute('title', randomFolderTitle + `\n` + randomFolderDescription);

await folderTable.performActionInExpandableMenu(randomFolderName, 'Delete');
try {
await nodesApi.deleteCurrentUserNodes();
} catch (error) {
logger.error(`afterAll failed : ${error}`);
}
});

test('[C216345] Create new folder dialog check', async ({ personalFiles }) => {
const folderDialog = personalFiles.folderDialog;

await personalFiles.selectCreateFolder();

test('[C216345] Create new folder dialog check', async () => {
await expect(folderDialog.getLabelText('Name')).toBeVisible();
await expect(folderDialog.getLabelText('*')).toBeVisible();
await expect(folderDialog.folderNameInputLocator).toBeVisible();
Expand All @@ -93,84 +101,78 @@ test.describe('Create folders', () => {
await expect(folderDialog.createButton).toBeDisabled();
});

test('[C216346] Create a folder without a name', async ({ personalFiles }) => {
const folderDialog = personalFiles.folderDialog;

await personalFiles.selectCreateFolder();
test('[C216346] Create a folder without a name', async () => {
await folderDialog.folderNameInputLocator.fill(randomFolderName);
await expect(folderDialog.folderNameInputLocator).toHaveValue(randomFolderName);
await expect(folderDialog.createButton).toBeEnabled();

await folderDialog.folderNameInputLocator.clear();

await expect(folderDialog.folderNameInputLocator).toBeEmpty();
await expect(folderDialog.folderNameInputHint).toContainText(folderErrors.folderNameIsRequired);
await expect(folderDialog.folderNameInputHint).toContainText(errorStrings.folderNameIsRequired);
await expect(folderDialog.createButton).toBeDisabled();
});

test('[C216348] Create folder when a name that ends with a dot "."', async ({ personalFiles }) => {
const folderDialog = personalFiles.folderDialog;

await personalFiles.selectCreateFolder();
test('[C216348] Create folder when a name that ends with a dot "."', async () => {
await folderDialog.folderNameInputLocator.fill(randomFolderName + '.');

await expect(folderDialog.createButton).toBeDisabled();
await expect(folderDialog.folderNameInputHint).toContainText(folderErrors.folderNameCantEndWithAPeriod);
await expect(folderDialog.folderNameInputHint).toContainText(errorStrings.folderNameCantEndWithAPeriod);
});

test('[C216347] Create folder with a name containing special characters', async ({ personalFiles }) => {
test('[C216347] Create folder with a name containing special characters', async () => {
const namesWithSpecialChars = ['a*a', 'a"a', 'a<a', 'a>a', `a\\a`, 'a/a', 'a?a', 'a:a', 'a|a'];
const folderDialog = personalFiles.folderDialog;

await personalFiles.selectCreateFolder();
for (const folderName of namesWithSpecialChars) {
await folderDialog.folderNameInputLocator.fill(folderName);

await expect(folderDialog.createButton).toBeDisabled();
await expect(folderDialog.folderNameInputHint).toContainText(folderErrors.folderNameCantContainTheseCharacters);
await expect(folderDialog.folderNameInputHint).toContainText(errorStrings.folderNameCantContainTheseCharacters);
}
});

test('[C280406] Create a folder with a name containing only spaces', async ({ personalFiles }) => {
const folderDialog = personalFiles.folderDialog;

await personalFiles.selectCreateFolder();
await folderDialog.folderNameInputLocator.fill(' ');
test('[C280406] Create a folder with a name containing only spaces', async () => {
await folderDialog.folderNameInputLocator.fill(spacesString);

await expect(folderDialog.createButton).toBeDisabled();
await expect(folderDialog.folderNameInputHint).toContainText(folderErrors.folderNameCantContainOnlySpaces);
await expect(folderDialog.folderNameInputHint).toContainText(errorStrings.folderNameCantContainOnlySpaces);
});

test('[C216349] Cancel folder creation', async ({ personalFiles }) => {
const folderDialog = personalFiles.folderDialog;

await personalFiles.selectCreateFolder();
await expect(personalFiles.page.getByRole('dialog', { name: 'Create new folder' })).toBeVisible();
await expect(personalFiles.page.getByRole(dialogString, { name: createNewFolderString })).toBeVisible();
await folderDialog.folderNameInputLocator.fill(randomFolderName);
await folderDialog.cancelButton.click();
await expect(personalFiles.page.getByRole('dialog', { name: 'Create new folder' })).toBeHidden();
await expect(personalFiles.page.getByRole(dialogString, { name: createNewFolderString })).toBeHidden();
});

test('[C216350] Duplicate folder name error', async ({ personalFiles }) => {
const folderDialog = personalFiles.folderDialog;
const folderSnackBar = personalFiles.snackBar;

await personalFiles.selectCreateFolder();
await folderDialog.createNewFolderDialog(commonFolderName);

await expect(folderSnackBar.getByMessageLocator(folderErrors.thereIsAlreadyAFolderWithThisName)).toBeVisible();
await expect(folderSnackBar.getByMessageLocator(errorStrings.thereIsAlreadyAFolderWithThisName)).toBeVisible();
});

test('[C216351] Folder created after trimmed ending spaces from a folder name', async ({ personalFiles }) => {
const folderDialog = personalFiles.folderDialog;
const folderTable = personalFiles.dataTable;
test.describe('On Personal Files dataTable', () => {
test.beforeEach(async ({ personalFiles }) => {
folderTable = personalFiles.dataTable;
});

test('[C216341] Create a folder with name only', async () => {
await folderDialog.createNewFolderDialog(randomFolderName);

await expect(folderTable.getRowByName(randomFolderName)).toBeVisible();
});

test('[C216340] Create a folder with name, title and description', async () => {
await folderDialog.createNewFolderDialog(randomFolderName, randomFolderTitle, randomFolderDescription);

await personalFiles.selectCreateFolder();
await folderDialog.createNewFolderDialog(randomFolderName + ' ');
await expect(folderTable.getCellLinkByName(randomFolderName)).toHaveAttribute('title', randomFolderTitle + `\n` + randomFolderDescription);

Check failure on line 169 in e2e/playwright/actions/src/tests/create-folder.spec.ts

View workflow job for this annotation

GitHub Actions / E2e test suites: Playwright (actions, 1)

[Actions] › src/tests/create-folder.spec.ts:166:9 › Create folders › On Personal Files dataTable › [C216340] Create a folder with name

2) [Actions] › src/tests/create-folder.spec.ts:166:9 › Create folders › On Personal Files dataTable › [C216340] Create a folder with name, title and description Error: Timed out 5000ms waiting for expect(received).toHaveAttribute(expected) - Expected string - 1 + Received string + 1 - folder-title-1yudw + playwright-folder-1qn1yfolder-title-1yudw folder-description-1o6bo Call log: - expect.toHaveAttribute with timeout 5000ms - waiting for locator('adf-datatable .adf-cell-value span').filter({ hasText: 'playwright-folder-1qn1y' }) - locator resolved to <span role="link" tabindex="0" class="adf-datatable-ce…> playwright-folder-1qn1yfolder-title-1yudw </span> - unexpected value "playwright-folder-1qn1yfolder-title-1yudw folder-description-1o6bo" - locator resolved to <span role="link" tabindex="0" class="adf-datatable-ce…> playwright-folder-1qn1yfolder-title-1yudw </span> - unexpected value "playwright-folder-1qn1yfolder-title-1yudw folder-description-1o6bo" - locator resolved to <span role="link" tabindex="0" class="adf-datatable-ce…> playwright-folder-1qn1yfolder-title-1yudw </span> - unexpected value "playwright-folder-1qn1yfolder-title-1yudw folder-description-1o6bo" - locator resolved to <span role="link" tabindex="0" class="adf-datatable-ce…> playwright-folder-1qn1yfolder-title-1yudw </span> - unexpected value "playwright-folder-1qn1yfolder-title-1yudw folder-description-1o6bo" 167 | await folderDialog.createNewFolderDialog(randomFolderName, randomFolderTitle, randomFolderDescription); 168 | > 169 | await expect(folderTable.getCellLinkByName(randomFolderName)).toHaveAttribute('title', randomFolderTitle + `\n` + randomFolderDescription); | ^ 170 | }); 171 | 172 | test('[C216351] Folder created after trimmed ending spaces from a folder name', async () => { at /home/runner/work/alfresco-content-app/alfresco-content-app/e2e/playwright/actions/src/tests/create-folder.spec.ts:169:69
});

await folderTable.goThroughPagesLookingForRowWithName(randomFolderName);
await expect(folderTable.getRowByName(randomFolderName)).toBeVisible();
test('[C216351] Folder created after trimmed ending spaces from a folder name', async () => {
await folderDialog.createNewFolderDialog(randomFolderName + spacesString);

await folderTable.performActionInExpandableMenu(randomFolderName, 'Delete');
await expect(folderTable.getRowByName(randomFolderName)).toBeVisible();
});
});
});
16 changes: 15 additions & 1 deletion projects/aca-playwright-shared/src/api/nodes-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ export class NodesApi {
}
}

/**
* Delete all nodes of the currently logged in user
* @param userNodeId The id of User node, all child nodes of "userNodeId" will be gathered as a list and deleted ( e.g.: "-my-" - User Homes folder)
*/
async deleteCurrentUserNodes(userNodeId: string = '-my-',): Promise<void> {
try {
const userNodes = (await this.getNodeChildren(userNodeId)).list.entries;
const userNodesString = userNodes.map((nodeChild) => nodeChild.entry.id);
await this.deleteNodes(userNodesString);
} catch (error) {
logger.error(`${this.constructor.name} ${this.deleteCurrentUserNodes.name}`, error);
}
}

async lockNodes(nodeIds: string[], lockType: string = 'ALLOW_OWNER_CHANGES') {
try {
for (const nodeId of nodeIds) {
Expand Down Expand Up @@ -369,7 +383,7 @@ export class NodesApi {
}

async createLinkToFolderName(originalFolderName: string, originalFolderParentId: string, destinationParentId?: string): Promise<NodeEntry> {
destinationParentId = destinationParentId ?? originalFolderParentId;
destinationParentId = destinationParentId ?? originalFolderParentId;

try {
const nodeId = await this.getNodeIdFromParent(originalFolderName, originalFolderParentId);
Expand Down
7 changes: 6 additions & 1 deletion projects/aca-playwright-shared/src/utils/error-strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export const errorStrings = {
nameContainOnlySpacesError: `Name can't contain only spaces`,
titleLengthLimitError: 'Use 256 characters or less for title',
descriptionLengthLimitError: 'Use 512 characters or less for description',
nameAlreadyUsedError: 'This name is already in use, try a different name.'
nameAlreadyUsedError: 'This name is already in use, try a different name.',

folderNameIsRequired: 'Folder name is required',
folderNameCantEndWithAPeriod: `Folder name can't end with a period .`,
folderNameCantContainTheseCharacters: `Folder name can't contain these characters`,
folderNameCantContainOnlySpaces: `Folder name can't contain only spaces`,
thereIsAlreadyAFolderWithThisName: `There's already a folder with this name. Try a different name.`
}
31 changes: 0 additions & 31 deletions projects/aca-playwright-shared/src/utils/folder-errors.ts

This file was deleted.

1 change: 0 additions & 1 deletion projects/aca-playwright-shared/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export * from './paths';
export * from './timeouts';
export * from './exclude-tests';
export * from './state-helper';
export * from './folder-errors';
export * from './utils';
export * from './library-errors';
export * from './config';
Expand Down

0 comments on commit e234814

Please sign in to comment.