[ACS-5688] create folder tests update (#3519)

* [ACS-5688] create folder tests update

* fixes for comments

* short expression
This commit is contained in:
Adam Zakrzewski
2023-11-14 15:44:08 +01:00
committed by GitHub
parent 4877a0549b
commit 7a0d21cfd2
5 changed files with 101 additions and 112 deletions

View File

@@ -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 });
try {
await nodesApi.deleteCurrentUserNodes();
} catch (error) {
logger.error(`afterAll failed : ${error}`);
}
});
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');
});
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();
@@ -93,10 +101,7 @@ 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();
@@ -104,73 +109,70 @@ test.describe('Create folders', () => {
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;
});
await personalFiles.selectCreateFolder();
await folderDialog.createNewFolderDialog(randomFolderName + ' ');
test('[C216341] Create a folder with name only', async () => {
await folderDialog.createNewFolderDialog(randomFolderName);
await folderTable.goThroughPagesLookingForRowWithName(randomFolderName);
await expect(folderTable.getRowByName(randomFolderName)).toBeVisible();
await expect(folderTable.getRowByName(randomFolderName)).toBeVisible();
});
await folderTable.performActionInExpandableMenu(randomFolderName, 'Delete');
test('[C216340] Create a folder with name, title and description', async () => {
await folderDialog.createNewFolderDialog(randomFolderName, randomFolderTitle, randomFolderDescription);
await expect(folderTable.getCellLinkByName(randomFolderName)).toHaveAttribute('title', randomFolderTitle + `\n` + randomFolderDescription);
});
test('[C216351] Folder created after trimmed ending spaces from a folder name', async () => {
await folderDialog.createNewFolderDialog(randomFolderName + spacesString);
await expect(folderTable.getRowByName(randomFolderName)).toBeVisible();
});
});
});

View File

@@ -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) {
@@ -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);
@@ -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);

View File

@@ -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.`
}

View File

@@ -1,31 +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 <http://www.gnu.org/licenses/>.
*/
export const folderErrors = {
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.`
}

View File

@@ -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';