[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,6 +24,8 @@
import { ApiClientFactory } from './api-client-factory';
import { FavoriteEntry } from '@alfresco/js-api';
import { Logger } from '@alfresco/adf-testing';
import { Utils } from '../utils';
export class FavoritesPageApi {
private apiService: ApiClientFactory;
@@ -47,4 +49,38 @@ export class FavoritesPageApi {
};
return await this.apiService.favorites.createFavorite('-me-', data);
}
private async getFavorites(username: string) {
try {
return await this.apiService.favorites.listFavorites(username);
} catch (error) {
Logger.error(`FavoritesApi getFavorites : catch : `, error);
return null;
}
}
async isFavorite(username: string, nodeId: string) {
try {
return JSON.stringify((await this.getFavorites(username)).list.entries).includes(nodeId);
} catch (error) {
Logger.error(`FavoritesApi isFavorite : catch : `, error);
return null;
}
}
async isFavoriteWithRetry(username: string, nodeId: string, data: { expect: boolean }) {
let isFavorite = false;
try {
const favorite = async () => {
isFavorite = await this.isFavorite(username, nodeId);
if (isFavorite !== data.expect) {
return Promise.reject(isFavorite);
} else {
return Promise.resolve(isFavorite);
}
};
return await Utils.retryCall(favorite);
} catch (error) {}
return isFavorite;
}
}

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}`);
}
}
}

View File

@@ -23,8 +23,7 @@
*/
import { ApiClientFactory } from './api-client-factory';
import { FavoritePaging, SharedLinkEntry } from '@alfresco/js-api';
import { logger } from '@alfresco/adf-cli/scripts/logger';
import { SharedLinkEntry } from '@alfresco/js-api';
export class SharedLinksApi {
private apiService: ApiClientFactory;
@@ -49,22 +48,4 @@ export class SharedLinksApi {
return null;
}
}
private async getFavorites(userName: string): Promise<FavoritePaging> {
try {
return await this.apiService.favorites.listFavorites(userName);
} catch (error) {
logger.error(`\n--- Error while fetching favourites list ${error} :`);
return null;
}
}
async isFavorite(nodeId: string, userName: string): Promise<boolean> {
try {
return JSON.stringify((await this.getFavorites(userName)).list.entries).includes(nodeId);
} catch (error) {
logger.error(`\n--- Error while checking favourite node ${error} ${error} :`);
return null;
}
}
}

View File

@@ -32,7 +32,7 @@ export class AcaHeader extends BaseComponent {
public viewButton = this.getChild('button[title="View"]');
public searchButton = this.getChild('button[title="Search"]');
public fullScreenButton = this.getChild('button[id="app.viewer.fullscreen"]');
public shareButton = this.getChild('button[id="app.viewer.fullscreen"]');
public shareButton = this.getChild('button[id="share-action-button"]');
public downloadButton = this.getChild('button[id="app.viewer.download"]');
constructor(page: Page) {

View File

@@ -34,6 +34,7 @@ export class ViewerComponent extends BaseComponent {
public closeButtonLocator = this.getChild('.adf-viewer-close-button');
public fileTitleButtonLocator = this.getChild('.adf-viewer__file-title');
public pdfViewerContentPages = this.getChild('.adf-pdf-viewer__content .page');
public shareButton = this.getChild('button[id="share-action-button"]');
toolbar = new AcaHeader(this.page);

View File

@@ -25,9 +25,17 @@
const crypto = require('crypto');
export class Utils {
static random(): string {
return crypto.getRandomValues(new Uint32Array(1))[0].toString(36).substring(0, 5).toLowerCase();
}
static retryCall(fn: () => Promise<any>, retry: number = 30, delay: number = 1500): Promise<any> {
const pause = (duration: number) => new Promise((res) => setTimeout(res, duration));
const run = (retries: number): Promise<any> => {
return fn().catch((err) => (retries > 1 ? pause(delay).then(() => run(retries - 1)) : Promise.reject(err)));
};
return run(retry);
}
}