mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2026-09-09 18:02:54 +00:00
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:
@@ -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 = '"!@£$%^&*()_+{}|:""?><,/.\';][=-`~"';
|
||||
|
||||
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' });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user