Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACS-5688] create folder tests update #3519

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, 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);
});

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();
});
});
});
18 changes: 16 additions & 2 deletions 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(): Promise<void> {
try {
const userNodes = (await this.getNodeChildren('-my-')).list.entries;
const userNodesIds = userNodes.map((nodeChild) => nodeChild.entry.id);
await this.deleteNodes(userNodesIds);
} 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 @@ -356,7 +370,7 @@ export class NodesApi {
}

async createLinkToFileName(originalFileName: string, originalFileParentId: string, destinationParentId?: string): Promise<NodeEntry> {
destinationParentId = destinationParentId ?? originalFileParentId;
destinationParentId ??= originalFileParentId;

try {
const nodeId = await this.getNodeIdFromParent(originalFileName, originalFileParentId);
Expand All @@ -369,7 +383,7 @@ export class NodesApi {
}

async createLinkToFolderName(originalFolderName: string, originalFolderParentId: string, destinationParentId?: string): Promise<NodeEntry> {
destinationParentId = destinationParentId ?? originalFolderParentId;
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
Loading