[ACS-5639] fix viewer exclude test from protractor and playwright (#3443)

* [ACS-5923] sidenav and singleclick test

* remove protractor test and fix flaky test

* test fix

* [ACS-5639] fix exclude test  in viewer

* remove exclude test and fix test
This commit is contained in:
Akash Rathod
2023-09-25 18:39:16 +02:00
committed by GitHub
parent 97f01386f8
commit be761bae7d
13 changed files with 191 additions and 375 deletions

View File

@@ -24,32 +24,125 @@
import * as fs from 'fs';
import { ApiClientFactory } from './api-client-factory';
import { Utils } from '../utils';
import { ApiUtil, Logger } from '@alfresco/adf-testing';
import { NodeEntry } from '@alfresco/js-api';
export class FileActionsApi {
private apiService: ApiClientFactory;
private apiService: ApiClientFactory;
constructor() {
this.apiService = new ApiClientFactory();
}
constructor() {
this.apiService = new ApiClientFactory();
}
static async initialize(userName: string, password?: string): Promise<FileActionsApi> {
const classObj = new FileActionsApi();
await classObj.apiService.setUpAcaBackend(userName, password);
return classObj;
}
static async initialize(userName: string, password?: string): Promise<FileActionsApi> {
const classObj = new FileActionsApi();
await classObj.apiService.setUpAcaBackend(userName, password);
return classObj;
}
async uploadFile(fileLocation: string, fileName: string, parentFolderId: string): Promise<any> {
const file = fs.createReadStream(fileLocation);
return this.apiService.upload.uploadFile(
file,
'',
parentFolderId,
null,
{
name: fileName,
nodeType: 'cm:content',
renditions: 'doclib'
}
);
async uploadFile(fileLocation: string, fileName: string, parentFolderId: string): Promise<any> {
const file = fs.createReadStream(fileLocation);
return this.apiService.upload.uploadFile(file, '', parentFolderId, null, {
name: fileName,
nodeType: 'cm:content',
renditions: 'doclib'
});
}
async lockNodes(nodeIds: string[], lockType: string = 'ALLOW_OWNER_CHANGES') {
try {
for (const nodeId of nodeIds) {
await this.apiService.nodes.lockNode(nodeId, { type: lockType });
}
} catch (error) {
Logger.error(`${this.constructor.name} ${this.lockNodes.name}`, error);
}
}
async getNodeById(id: string): Promise<NodeEntry | null> {
try {
return await this.apiService.nodes.getNode(id);
} catch (error) {
Logger.error(`${this.constructor.name} ${this.getNodeById.name}`, error);
return null;
}
}
async getNodeProperty(nodeId: string, property: string): Promise<string> {
try {
const node = await this.getNodeById(nodeId);
return (node.entry.properties && node.entry.properties[property]) || '';
} catch (error) {
Logger.error(`${this.constructor.name} ${this.getNodeProperty.name}`, error);
return '';
}
}
private async getLockType(nodeId: string): Promise<string> {
try {
const lockType = await this.getNodeProperty(nodeId, 'cm:lockType');
return lockType || '';
} catch (error) {
Logger.error(`${this.constructor.name} ${this.getLockType.name}`, error);
return '';
}
}
async isFileLockedWriteWithRetry(nodeId: string, expect: boolean): Promise<boolean> {
const data = {
expect: expect,
retry: 5
};
let isLocked = false;
try {
const locked = async () => {
isLocked = (await this.getLockType(nodeId)) === 'WRITE_LOCK';
if (isLocked !== data.expect) {
return Promise.reject(isLocked);
} else {
return Promise.resolve(isLocked);
}
};
return await Utils.retryCall(locked, data.retry);
} catch (error) {
Logger.error(`${this.constructor.name} ${this.isFileLockedWriteWithRetry.name}`, error);
}
return isLocked;
}
private async queryNodesNames(searchTerm: string) {
const data = {
query: {
query: `cm:name:\"${searchTerm}*\"`,
language: 'afts'
},
filterQueries: [{ query: `+TYPE:'cm:folder' OR +TYPE:'cm:content'` }]
};
try {
return this.apiService.search.search(data);
} catch (error) {
Logger.error(`SearchApi queryNodesNames : catch : `, error);
return null;
}
}
async waitForNodes(searchTerm: string, data: { expect: number }) {
const predicate = (totalItems: number) => totalItems === data.expect;
const apiCall = async () => {
try {
return (await this.queryNodesNames(searchTerm)).list.pagination.totalItems;
} catch (error) {
return 0;
}
};
try {
await ApiUtil.waitForApi(apiCall, predicate, 30, 2500);
} catch (error) {
Logger.error(`SearchApi waitForNodes : catch : `);
Logger.error(`\tExpected: ${data.expect} items, but found ${error}`);
}
}
}