ACS 9871 - add additional transformation rule tests (#4927)

* ACS-9871: Add transformation rule tests and supporting methods

* ACS-9871: Add transformation rule tests and supporting methods (Addressed PR Comments)

* ACS-9871: Fix async expect pattern in transformation tests

* ACS-9871: Add readonly modifiers and clean up code formatting

* ACS-9871: Simplify expect statements and reorder assertions

* ACS-9871: Refactor transformation tests with helper function

- Add testTransformation helper function to reduce code duplication
- Refactor PDF, BMP, and JPG transformation tests to use helper
- Improve test maintainability and readability
- Add comprehensive JSDoc documentation

* ACS-9871: Replace any types with proper Page Object types

- Replace 'any' with PersonalFilesPage, NodesPage, and LoginPage
- Add proper imports for page object types
- Improve type safety in testTransformation helper function

* ACS-9871: Add image transformation tests for GIF, TIFF, and PNG - Add new test cases for GIF, TIFF, and PNG transformations - Add MimeType enums for GIFImage, TIFFImage, and PNGImage - Add TIFF_FILE and BMP_FILE to test-files registry - Add physical test files (file-tif.tif, file-bmp.bmp) - Test multiple image format conversions (JPG, PNG, BMP, GIF, TIFF)

* Fix parallel test execution by removing logout/login cycle in transformation tests

* Refactor transformation tests to reduce code duplication for SonarQube

* Refactor transformation tests following Single Responsibility Principle and extract TestFileConfig interface to shared models

* Replace any type with Page type in triggerTransformation function
This commit is contained in:
Rakesh Ghosal
2025-12-17 15:03:11 +05:30
committed by GitHub
parent 3f25c12b6f
commit 44b8ec53d8
7 changed files with 197 additions and 40 deletions
@@ -22,7 +22,7 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/
import { expect } from '@playwright/test';
import { expect, Page } from '@playwright/test';
import {
ActionType,
ApiClientFactory,
@@ -32,9 +32,79 @@ import {
NodesApi,
MimeType,
FileActionsApi,
TEST_FILES
TEST_FILES,
PersonalFilesPage,
NodesPage,
timeouts,
TestFileConfig
} from '@alfresco/aca-playwright-shared';
function generateUniqueFiles(testFiles: Array<TestFileConfig>): Array<TestFileConfig> {
return testFiles.map((file) => ({ path: file.path, name: `${file.name}-${Utils.random()}` }));
}
async function setupTransformationTest(
context: { personalFiles: PersonalFilesPage; nodesPage: NodesPage },
config: {
nodesApi: NodesApi;
testString: string;
parentFolderName: string;
destinationFolderName: string;
mimeType: MimeType;
}
): Promise<string> {
const { personalFiles, nodesPage } = context;
const { nodesApi, testString, parentFolderName, destinationFolderName, mimeType } = config;
const parentFolderId = (await nodesApi.createFolder(parentFolderName)).entry.id;
await nodesApi.createFolder(destinationFolderName);
await personalFiles.navigate({ remoteUrl: `#/nodes/${parentFolderId}/rules` });
await nodesPage.toolbar.clickCreateRuleButton();
await nodesPage.manageRulesDialog.ruleNameInputLocator.fill(testString);
await nodesPage.manageRulesDialog.ruleDescriptionInputLocator.fill(testString);
await nodesPage.actionsDropdown.selectAction(ActionType.TransformAndCopyContent, 0);
await nodesPage.actionsDropdown.selectMimeType(mimeType, 0);
await nodesPage.actionsDropdown.selectDestinationFolderTransformAndCopyContent(0, destinationFolderName);
await nodesPage.manageRulesDialog.createRuleButton.click();
await expect(nodesPage.manageRules.getGroupsList(testString)).toBeVisible();
return parentFolderId;
}
async function triggerTransformation(config: {
fileActionApi: FileActionsApi;
files: Array<TestFileConfig>;
parentFolderId: string;
page: Page;
}): Promise<void> {
const { fileActionApi, files, parentFolderId, page } = config;
for (const file of files) {
await fileActionApi.uploadFile(file.path, file.name, parentFolderId);
}
await page.waitForTimeout(timeouts.medium);
}
async function verifyTransformation(
context: { personalFiles: PersonalFilesPage },
config: {
destinationFolderName: string;
files: Array<TestFileConfig>;
expectedExtension: string;
}
): Promise<void> {
const { personalFiles } = context;
const { destinationFolderName, files, expectedExtension } = config;
await personalFiles.navigate();
await personalFiles.dataTable.performClickFolderOrFileToOpen(destinationFolderName);
await personalFiles.spinner.waitForReload();
for (const file of files) {
const transformedFileName = `${file.name}.${expectedExtension}`;
const exists = await personalFiles.dataTable.isItemPresent(transformedFileName);
expect(exists, `Transformed file ${transformedFileName} was not present in data table`).toBe(true);
}
}
test.use({ launchOptions: { slowMo: 300 } });
test.describe('Folder Rules Actions', () => {
const apiClientFactory = new ApiClientFactory();
@@ -42,17 +112,8 @@ test.describe('Folder Rules Actions', () => {
let trashcanApi: TrashcanApi;
let fileActionApi: FileActionsApi;
const username = `user-e2e-${Utils.random()}`;
const randomFolderName1 = `folder-name-${Utils.random()}`;
const randomDocxName = `${TEST_FILES.DOCX.name}-${Utils.random()}`;
const randomXLSXName = `${TEST_FILES.XLSX.name}-${Utils.random()}`;
const randomPPTXName = `${TEST_FILES.PPTX_FILE.name}-${Utils.random()}`;
const copyFileName = `copy-file-${Utils.random()}`;
const testString = '"!@£$%^&*()_+{}|:""?&gt;&lt;,/.\';][=-`~"';
let randomFolderName1Id: string;
test.beforeAll(async () => {
try {
await apiClientFactory.setUpAcaBackend('admin');
@@ -60,8 +121,6 @@ test.describe('Folder Rules Actions', () => {
nodesApi = await NodesApi.initialize(username, username);
trashcanApi = await TrashcanApi.initialize(username, username);
fileActionApi = await FileActionsApi.initialize(username, username);
randomFolderName1Id = (await nodesApi.createFolder(randomFolderName1)).entry.id;
await nodesApi.createFile(copyFileName, randomFolderName1Id);
} catch (error) {
console.error(`beforeAll failed : ${error}`);
}
@@ -75,31 +134,87 @@ test.describe('Folder Rules Actions', () => {
await Utils.deleteNodesSitesEmptyTrashcan(nodesApi, trashcanApi, 'afterAll failed');
});
test('[XAT-8050] Supported types transformation to PDF', async ({ personalFiles, nodesPage, loginPage }) => {
const toFolderName = 'TO_PDF';
await nodesApi.createFolder(toFolderName);
await personalFiles.navigate({ remoteUrl: `#/nodes/${randomFolderName1Id}/rules` });
await nodesPage.toolbar.clickCreateRuleButton();
await nodesPage.manageRulesDialog.ruleNameInputLocator.fill(testString);
await nodesPage.manageRulesDialog.ruleDescriptionInputLocator.fill(testString);
await nodesPage.actionsDropdown.selectAction(ActionType.TransformAndCopyContent, 0);
await nodesPage.actionsDropdown.selectMimeType(MimeType.AdobePDFDocument, 0);
await nodesPage.actionsDropdown.selectDestinationFolderTransformAndCopyContent(0, toFolderName);
await nodesPage.manageRulesDialog.createRuleButton.click();
await expect(nodesPage.manageRules.getGroupsList(testString)).toBeVisible();
await fileActionApi.uploadFile(TEST_FILES.DOCX.path, randomDocxName, randomFolderName1Id);
await fileActionApi.uploadFile(TEST_FILES.XLSX.path, randomXLSXName, randomFolderName1Id);
await fileActionApi.uploadFile(TEST_FILES.PPTX_FILE.path, randomPPTXName, randomFolderName1Id);
await loginPage.logoutUser();
await expect(loginPage.username, 'User name was not visible').toBeVisible();
await Utils.tryLoginUser(loginPage, username, username, 'beforeEach failed');
await personalFiles.dataTable.performClickFolderOrFileToOpen(toFolderName);
await personalFiles.spinner.waitForReload();
const docxToPDF = `${randomDocxName}.pdf`;
const xlsxToPDF = `${randomXLSXName}.pdf`;
const pptxToPDF = `${randomPPTXName}.pdf`;
expect(await personalFiles.dataTable.isItemPresent(docxToPDF), `Converted PDF from DOCX ${docxToPDF} was not present in data table`).toBe(true);
expect(await personalFiles.dataTable.isItemPresent(pptxToPDF), `Converted PDF from PPTX ${pptxToPDF} was not present in data table`).toBe(true);
expect(await personalFiles.dataTable.isItemPresent(xlsxToPDF), `Converted PDF from XLSX ${xlsxToPDF} was not present in data table`).toBe(true);
test('[XAT-8050] Supported types transformation to PDF', async ({ personalFiles, nodesPage }) => {
const parentFolderName = `parent-pdf-${Utils.random()}`;
const destinationFolderName = `TO_PDF-${Utils.random()}`;
const files = generateUniqueFiles([TEST_FILES.DOCX, TEST_FILES.XLSX, TEST_FILES.PPTX_FILE]);
const parentFolderId = await setupTransformationTest(
{ personalFiles, nodesPage },
{ nodesApi, testString, parentFolderName, destinationFolderName, mimeType: MimeType.AdobePDFDocument }
);
await triggerTransformation({ fileActionApi, files, parentFolderId, page: personalFiles.page });
await verifyTransformation({ personalFiles }, { destinationFolderName, files, expectedExtension: 'pdf' });
});
test('[XAT-8051] Supported types transformation to BMP', async ({ personalFiles, nodesPage }) => {
const parentFolderName = `parent-bmp-${Utils.random()}`;
const destinationFolderName = `TO_BMP-${Utils.random()}`;
const files = generateUniqueFiles([TEST_FILES.JPG_FILE, TEST_FILES.PNG_FILE, TEST_FILES.GIF_FILE, TEST_FILES.TIFF_FILE]);
const parentFolderId = await setupTransformationTest(
{ personalFiles, nodesPage },
{ nodesApi, testString, parentFolderName, destinationFolderName, mimeType: MimeType.BitmapImage }
);
await triggerTransformation({ fileActionApi, files, parentFolderId, page: personalFiles.page });
await verifyTransformation({ personalFiles }, { destinationFolderName, files, expectedExtension: 'bmp' });
});
test('[XAT-8052] Supported types transformation to JPG', async ({ personalFiles, nodesPage }) => {
const parentFolderName = `parent-jpg-${Utils.random()}`;
const destinationFolderName = `TO_JPG-${Utils.random()}`;
const files = generateUniqueFiles([TEST_FILES.PNG_FILE, TEST_FILES.GIF_FILE, TEST_FILES.BMP_FILE, TEST_FILES.TIFF_FILE]);
const parentFolderId = await setupTransformationTest(
{ personalFiles, nodesPage },
{ nodesApi, testString, parentFolderName, destinationFolderName, mimeType: MimeType.JPEGImage }
);
await triggerTransformation({ fileActionApi, files, parentFolderId, page: personalFiles.page });
await verifyTransformation({ personalFiles }, { destinationFolderName, files, expectedExtension: 'jpg' });
});
test('[XAT-8053] Supported types transformation to GIF', async ({ personalFiles, nodesPage }) => {
const parentFolderName = `parent-gif-${Utils.random()}`;
const destinationFolderName = `TO_GIF-${Utils.random()}`;
const files = generateUniqueFiles([TEST_FILES.PNG_FILE, TEST_FILES.JPG_FILE, TEST_FILES.BMP_FILE, TEST_FILES.TIFF_FILE]);
const parentFolderId = await setupTransformationTest(
{ personalFiles, nodesPage },
{ nodesApi, testString, parentFolderName, destinationFolderName, mimeType: MimeType.GIFImage }
);
await triggerTransformation({ fileActionApi, files, parentFolderId, page: personalFiles.page });
await verifyTransformation({ personalFiles }, { destinationFolderName, files, expectedExtension: 'gif' });
});
test('[XAT-8054] Supported types transformation to TIFF', async ({ personalFiles, nodesPage }) => {
const parentFolderName = `parent-tiff-${Utils.random()}`;
const destinationFolderName = `TO_TIFF-${Utils.random()}`;
const files = generateUniqueFiles([TEST_FILES.PNG_FILE, TEST_FILES.JPG_FILE, TEST_FILES.BMP_FILE, TEST_FILES.GIF_FILE]);
const parentFolderId = await setupTransformationTest(
{ personalFiles, nodesPage },
{ nodesApi, testString, parentFolderName, destinationFolderName, mimeType: MimeType.TIFFImage }
);
await triggerTransformation({ fileActionApi, files, parentFolderId, page: personalFiles.page });
await verifyTransformation({ personalFiles }, { destinationFolderName, files, expectedExtension: 'tif' });
});
test('[XAT-8055] Supported types transformation to PNG', async ({ personalFiles, nodesPage }) => {
const parentFolderName = `parent-png-${Utils.random()}`;
const destinationFolderName = `TO_PNG-${Utils.random()}`;
const files = generateUniqueFiles([TEST_FILES.JPG_FILE, TEST_FILES.BMP_FILE, TEST_FILES.GIF_FILE, TEST_FILES.TIFF_FILE]);
const parentFolderId = await setupTransformationTest(
{ personalFiles, nodesPage },
{ nodesApi, testString, parentFolderName, destinationFolderName, mimeType: MimeType.PNGImage }
);
await triggerTransformation({ fileActionApi, files, parentFolderId, page: personalFiles.page });
await verifyTransformation({ personalFiles }, { destinationFolderName, files, expectedExtension: 'png' });
});
});
@@ -24,3 +24,4 @@
export * from './user-model';
export * from './custom-config';
export * from './test-file.model';
@@ -0,0 +1,28 @@
/*!
* Copyright © 2005-2025 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 interface TestFileConfig {
path: string;
name: string;
}
@@ -51,7 +51,12 @@ export enum ActionType {
}
export enum MimeType {
AdobePDFDocument = 'Adobe PDF Document [application/pdf]'
AdobePDFDocument = 'Adobe PDF Document [application/pdf]',
BitmapImage = 'Bitmap Image [image/bmp]',
JPEGImage = 'JPEG Image [image/jpeg]',
GIFImage = 'GIF Image [image/gif]',
TIFFImage = 'TIFF Image [image/tiff]',
PNGImage = 'PNG Image [image/png]'
}
export class ActionsDropdownComponent extends BaseComponent {
Binary file not shown.

After

Width:  |  Height:  |  Size: 78 B

@@ -78,6 +78,14 @@ export const TEST_FILES = {
path: resolve(__dirname, 'file-gif.gif'),
name: 'file-gif'
},
TIFF_FILE: {
path: resolve(__dirname, 'file-tif.tif'),
name: 'file-tif'
},
BMP_FILE: {
path: resolve(__dirname, 'file-bmp.bmp'),
name: 'file-bmp'
},
PPTX_FILE: {
path: resolve(__dirname, 'file-pptx.pptx'),
name: 'file-pptx'