mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
[ACS-4894] [E2E] Added new e2e for update folder rules (#3929)
* [ACS-4892] [E2E] Created new tests for adding folder rules * [ACS-4892] deleted the unused if enum * [ACS-4894] Added update folder rules tests * [ACS-4894] sonar fix 1 * [ACS-4894] sonar fix 2 * [ACS-4894] sonar fix 3 * [ACS-4894] review fixes 1 * [ACS-4894] review fixes 2 * [ACS-4894] review fixes 3 * [ACS-4894] comments deleted * [ACS-4894] eslint fix
This commit is contained in:
@@ -44,7 +44,6 @@ import {
|
||||
CategoriesApi,
|
||||
TagsApi
|
||||
} from '@alfresco/js-api';
|
||||
import { ActionTypes, Rule } from './rules-api';
|
||||
import { users } from '../base-config';
|
||||
import { Person, PersonModel } from './people-api-models';
|
||||
|
||||
@@ -90,7 +89,6 @@ export class ApiClientFactory {
|
||||
public queriesApi: QueriesApi;
|
||||
public categoriesApi: CategoriesApi;
|
||||
public tagsApi: TagsApi;
|
||||
|
||||
constructor() {
|
||||
this.alfrescoApi = new AlfrescoApi(config);
|
||||
}
|
||||
@@ -125,26 +123,6 @@ export class ApiClientFactory {
|
||||
return this;
|
||||
}
|
||||
|
||||
private callApi(path: string, httpMethod: string, body: object = {}): Promise<any> {
|
||||
// APIs used by this service are still private and not yet available for public use
|
||||
const params = [{}, {}, {}, {}, body, ['application/json'], ['application/json']];
|
||||
return this.alfrescoApi.contentPrivateClient.callApi(path, httpMethod, ...params);
|
||||
}
|
||||
|
||||
async createRule(nodeId: string, rule: Partial<Rule>, ruleSetId: string = '-default-'): Promise<Rule> {
|
||||
const response = await this.callApi(`/nodes/${nodeId}/rule-sets/${ruleSetId}/rules`, 'POST', { ...rule });
|
||||
return response.entry;
|
||||
}
|
||||
|
||||
async createRandomRule(folderId: string, ruleName: string): Promise<Rule> {
|
||||
const response = await this.createRule(folderId, {
|
||||
name: ruleName,
|
||||
isEnabled: true,
|
||||
actions: [ActionTypes.ADDFEATURES.value, ActionTypes.CHECKIN.value]
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
async login(userName: string, password?: string) {
|
||||
const predefinedUserKey = Object.keys(users).find((user) => user === userName || users[user].username === userName);
|
||||
const userToLog = predefinedUserKey ? users[predefinedUserKey] : undefined;
|
||||
|
@@ -22,21 +22,135 @@
|
||||
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { ApiClientFactory } from './api-client-factory';
|
||||
import { AcaFolderRulesModule } from '@alfresco/aca-content/folder-rules';
|
||||
import * as crypto from 'crypto';
|
||||
|
||||
export class RulesApi {
|
||||
private apiService: ApiClientFactory;
|
||||
|
||||
constructor() {
|
||||
this.apiService = new ApiClientFactory();
|
||||
}
|
||||
|
||||
static async initialize(userName: string, password?: string): Promise<RulesApi> {
|
||||
const classObj = new RulesApi();
|
||||
await classObj.apiService.setUpAcaBackend(userName, password);
|
||||
return classObj;
|
||||
}
|
||||
|
||||
private callApi(path: string, httpMethod: string, body: object = {}): Promise<any> {
|
||||
// APIs used by this service are still private and not yet available for public use
|
||||
const params = [{}, {}, {}, {}, body, ['application/json'], ['application/json']];
|
||||
return this.apiService.alfrescoApi.contentPrivateClient.callApi(path, httpMethod, ...params);
|
||||
}
|
||||
|
||||
async createRule(nodeId: string, rule: Partial<Rule>, ruleSetId: string = '-default-'): Promise<Rule> {
|
||||
const response = await this.callApi(`/nodes/${nodeId}/rule-sets/${ruleSetId}/rules`, 'POST', { ...rule });
|
||||
return response.entry;
|
||||
}
|
||||
|
||||
async createRandomRule(folderId: string, ruleName: string): Promise<Rule> {
|
||||
const randomActionsIndex = crypto.randomInt(0, ActionTypes.actions.length);
|
||||
const randomAction = ActionTypes.actions[randomActionsIndex];
|
||||
return await this.createRule(folderId, {
|
||||
name: ruleName,
|
||||
isEnabled: true,
|
||||
actions: [randomAction]
|
||||
});
|
||||
}
|
||||
|
||||
async createRandomRuleWithMultipleConditions(folderId: string, ruleName: string, numOfConditions: number): Promise<Rule> {
|
||||
if (numOfConditions > ConditionsTypes.conditions.length) {
|
||||
numOfConditions = ConditionsTypes.conditions.length;
|
||||
}
|
||||
const randomActionsIndex = crypto.randomInt(0, ActionTypes.actions.length);
|
||||
const randomAction = ActionTypes.actions[randomActionsIndex];
|
||||
let conditionsArray = [];
|
||||
for (let i = 0; i < numOfConditions; i++) {
|
||||
const randomIndex = crypto.randomInt(0, ConditionsTypes.conditions.length);
|
||||
const randomCondition = ConditionsTypes.conditions[randomIndex];
|
||||
conditionsArray.push(randomCondition);
|
||||
}
|
||||
return await this.createRule(folderId, {
|
||||
name: ruleName,
|
||||
isEnabled: true,
|
||||
actions: [randomAction],
|
||||
conditions: {
|
||||
inverted: false,
|
||||
booleanMode: 'and',
|
||||
compositeConditions: conditionsArray
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async createRandomRuleWithMultipleActions(folderId: string, ruleName: string, numOfActions: number): Promise<Rule> {
|
||||
if (numOfActions > ActionTypes.actions.length) {
|
||||
numOfActions = ActionTypes.actions.length;
|
||||
}
|
||||
let actionsArray = [];
|
||||
for (let i = 0; i < numOfActions; i++) {
|
||||
const randomIndex = crypto.randomInt(0, ActionTypes.actions.length);
|
||||
const randomAction = ActionTypes.actions[randomIndex];
|
||||
actionsArray.push(randomAction);
|
||||
}
|
||||
return await this.createRule(folderId, {
|
||||
name: ruleName,
|
||||
isEnabled: true,
|
||||
actions: actionsArray
|
||||
});
|
||||
}
|
||||
|
||||
async createRuleWithRandomAspects(folderId: string, ruleName: string): Promise<Rule> {
|
||||
return await this.createRule(folderId, {
|
||||
name: ruleName,
|
||||
isEnabled: true,
|
||||
actions: [
|
||||
{
|
||||
actionDefinitionId: 'add-features',
|
||||
params: {
|
||||
'aspect-name': 'sc:controlsAreClearance'
|
||||
}
|
||||
},
|
||||
{
|
||||
actionDefinitionId: 'add-features',
|
||||
params: {
|
||||
'aspect-name': 'sfdc:objectModel'
|
||||
}
|
||||
},
|
||||
{
|
||||
actionDefinitionId: 'add-features',
|
||||
params: {
|
||||
'aspect-name': 'sfdc:folder'
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async createRuleWithDestinationFolder(
|
||||
folderId: string,
|
||||
ruleName: string,
|
||||
actionType: 'move' | 'copy' | 'import',
|
||||
destinationFolderId: string
|
||||
): Promise<Rule> {
|
||||
return await this.createRule(folderId, {
|
||||
name: ruleName,
|
||||
isEnabled: true,
|
||||
actions: [
|
||||
{
|
||||
actionDefinitionId: actionType,
|
||||
params: {
|
||||
'destination-folder': destinationFolderId
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
type RuleTrigger = 'inbound' | 'update' | 'outbound';
|
||||
|
||||
export interface RuleCompositeCondition {
|
||||
inverted: boolean;
|
||||
booleanMode: 'and' | 'or';
|
||||
compositeConditions: RuleCompositeCondition[];
|
||||
simpleConditions: RuleSimpleCondition[];
|
||||
}
|
||||
|
||||
export interface RuleSimpleCondition {
|
||||
field: string;
|
||||
comparator: string;
|
||||
parameter: string;
|
||||
}
|
||||
|
||||
export interface Rule {
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -47,7 +161,7 @@ export interface Rule {
|
||||
errorScript: string;
|
||||
isShared: boolean;
|
||||
triggers: RuleTrigger[];
|
||||
conditions: RuleCompositeCondition;
|
||||
conditions: AcaFolderRulesModule;
|
||||
actions: RuleAction[];
|
||||
}
|
||||
|
||||
@@ -57,16 +171,84 @@ export interface RuleAction {
|
||||
}
|
||||
|
||||
export class ActionTypes {
|
||||
static ADDFEATURES = new ActionTypes('ADDFEATURES', {
|
||||
static readonly ADDFEATURES = new ActionTypes('ADDFEATURES', {
|
||||
actionDefinitionId: 'add-features',
|
||||
params: { 'aspect-name': 'cm:thumbnailed' }
|
||||
});
|
||||
static CHECKIN = new ActionTypes('CHECKIN', {
|
||||
static readonly CHECKIN = new ActionTypes('CHECKIN', {
|
||||
actionDefinitionId: 'check-in',
|
||||
params: {
|
||||
description: 'test',
|
||||
minorChange: true
|
||||
}
|
||||
});
|
||||
static readonly SPECIALISETYPE = new ActionTypes('SPECIALISETYPE', {
|
||||
actionDefinitionId: 'specialise-type',
|
||||
params: { 'type-name': 'sys:base' }
|
||||
});
|
||||
static readonly RECORDABLEVERSION = new ActionTypes('RECORDABLEVERSION', {
|
||||
actionDefinitionId: 'recordable-version-config',
|
||||
params: { version: 'ALL' }
|
||||
});
|
||||
static readonly SETPROPERTYVALUE = new ActionTypes('SETPROPERTYVALUE', {
|
||||
actionDefinitionId: 'set-property-value',
|
||||
params: { property: 'dl:ganttPercentComplete', value: 'test' }
|
||||
});
|
||||
static readonly actions = [
|
||||
ActionTypes.ADDFEATURES.value,
|
||||
ActionTypes.CHECKIN.value,
|
||||
ActionTypes.RECORDABLEVERSION.value,
|
||||
ActionTypes.SPECIALISETYPE.value,
|
||||
ActionTypes.SETPROPERTYVALUE.value
|
||||
];
|
||||
constructor(public key: string, public value: RuleAction) {}
|
||||
}
|
||||
|
||||
export class ConditionsTypes {
|
||||
static readonly MIMETYPE = new ConditionsTypes('MIMETYPE', {
|
||||
inverted: false,
|
||||
booleanMode: 'and',
|
||||
simpleConditions: [
|
||||
{
|
||||
field: 'mimetype',
|
||||
comparator: 'equals',
|
||||
parameter: 'video/3gpp'
|
||||
}
|
||||
]
|
||||
});
|
||||
static readonly CMNAME = new ConditionsTypes('CM:NAME', {
|
||||
inverted: false,
|
||||
booleanMode: 'and',
|
||||
simpleConditions: [
|
||||
{
|
||||
field: 'cm:name',
|
||||
comparator: 'equals',
|
||||
parameter: 'testname'
|
||||
}
|
||||
]
|
||||
});
|
||||
static readonly SIZE = new ConditionsTypes('SIZE', {
|
||||
inverted: false,
|
||||
booleanMode: 'and',
|
||||
simpleConditions: [
|
||||
{
|
||||
field: 'size',
|
||||
comparator: 'equals',
|
||||
parameter: '345'
|
||||
}
|
||||
]
|
||||
});
|
||||
static readonly TAG = new ConditionsTypes('TAG', {
|
||||
inverted: false,
|
||||
booleanMode: 'and',
|
||||
simpleConditions: [
|
||||
{
|
||||
field: 'tag',
|
||||
comparator: 'equals',
|
||||
parameter: 'testtag'
|
||||
}
|
||||
]
|
||||
});
|
||||
static readonly conditions = [ConditionsTypes.MIMETYPE.value, ConditionsTypes.CMNAME.value, ConditionsTypes.SIZE.value, ConditionsTypes.TAG.value];
|
||||
constructor(public key: string, public value: AcaFolderRulesModule) {}
|
||||
}
|
||||
|
@@ -52,7 +52,8 @@ export enum ActionType {
|
||||
export class ActionsDropdownComponent extends BaseComponent {
|
||||
private static rootElement = 'aca-edit-rule-dialog aca-rule-action-list';
|
||||
|
||||
private getOptionLocator = (optionName: string): Locator => this.page.locator('.mat-select-panel .mat-option-text', { hasText: optionName }).first();
|
||||
private getOptionLocator = (optionName: string): Locator =>
|
||||
this.page.locator('.mat-select-panel .mat-option-text', { hasText: optionName }).first();
|
||||
private ruleActionLocator = this.getChild('aca-rule-action');
|
||||
private addActionButtonLocator = this.getChild('[data-automation-id="rule-action-list-add-action-button"]');
|
||||
private actionDropdownLocator = this.getChild('[data-automation-id="rule-action-select"]');
|
||||
@@ -74,6 +75,7 @@ export class ActionsDropdownComponent extends BaseComponent {
|
||||
if (index > 0) {
|
||||
await this.addActionButtonLocator.click();
|
||||
}
|
||||
await this.actionDropdownLocator.nth(index).hover({ timeout: 1000 });
|
||||
await this.actionDropdownLocator.nth(index).click();
|
||||
const option = this.getOptionLocator(action);
|
||||
await option.click();
|
||||
|
@@ -58,7 +58,7 @@ export class ConditionComponent extends ManageRulesDialogComponent {
|
||||
}
|
||||
|
||||
async addCondition(fields: Partial<Field>, value: string, index: number, comparators?: Partial<Comparator>): Promise<void> {
|
||||
await this.addConditionButton.click();
|
||||
await this.addConditionButton.first().click();
|
||||
await this.selectField(fields, index);
|
||||
if (comparators) {
|
||||
await this.selectComparator(comparators, index);
|
||||
|
@@ -44,8 +44,24 @@ export class ManageRulesDialogComponent extends BaseComponent {
|
||||
public ruleInBackgroundCheckbox = this.getChild('[data-automation-id="rule-option-checkbox-asynchronous"]');
|
||||
public ruleSubfoldersCheckbox = this.getChild('[data-automation-id="rule-option-checkbox-inheritable"]');
|
||||
public ruleDisableCheckbox = this.getChild('[data-automation-id="rule-option-checkbox-disabled"]');
|
||||
public actionsEllipsisButtons = this.getChild('[data-automation-id="rule-action-list-action-menu"]');
|
||||
public actionsEllipsisDelete = this.page.locator('[data-automation-id="rule-action-list-remove-action-button"]');
|
||||
public conditionsEllipsisButtons = this.getChild('[data-automation-id="condition-actions-button"]');
|
||||
public conditionsEllipsisDelete = this.page.locator('button[title="Remove"]');
|
||||
|
||||
constructor(page: Page) {
|
||||
super(page, ManageRulesDialogComponent.rootElement);
|
||||
}
|
||||
|
||||
async deleteActions(noActions: number): Promise<void> {
|
||||
for(let i = 0; i < noActions; i++) {
|
||||
await this.actionsEllipsisButtons.first().click();
|
||||
await this.actionsEllipsisDelete.click();
|
||||
}}
|
||||
|
||||
async deleteConditions(noConditions: number): Promise<void> {
|
||||
for(let i = 0; i < noConditions; i++) {
|
||||
await this.conditionsEllipsisButtons.first().click();
|
||||
await this.conditionsEllipsisDelete.click();
|
||||
}}
|
||||
}
|
||||
|
@@ -37,6 +37,8 @@ export class ManageRules extends BaseComponent {
|
||||
public ruleDetailsWhenText = this.getChild('[data-automation-id="rule-details-triggers-component"]');
|
||||
public ruleDetailsPerformActionsDiv = this.getChild('adf-card-view-textitem mat-form-field input');
|
||||
public rulesEmptyListTitle = this.getChild('.adf-empty-content__title');
|
||||
public ruleActions = this.getChild('aca-rule-action');
|
||||
public ruleConditionsInGroup = this.getChild('aca-rule-composite-condition aca-rule-simple-condition');
|
||||
|
||||
constructor(page: Page) {
|
||||
super(page, ManageRules.rootElement);
|
||||
@@ -56,4 +58,19 @@ export class ManageRules extends BaseComponent {
|
||||
async checkIfRuleIsOnTheList(ruleName: string): Promise<void> {
|
||||
await expect(this.getGroupsList(ruleName)).toBeVisible({ timeout: 5000 });
|
||||
}
|
||||
|
||||
async countConditionsInGroup(): Promise<number> {
|
||||
return await this.ruleConditionsInGroup.count();
|
||||
}
|
||||
|
||||
async turnOffRuleToggle(): Promise<void> {
|
||||
await expect(async () => {
|
||||
await this.ruleToggle.hover({ timeout: 1000 });
|
||||
await this.ruleToggle.click();
|
||||
await expect(this.ruleToggleFalse).toBeVisible();
|
||||
}).toPass({
|
||||
intervals: [2_000, 2_000, 2_000, 2_000, 2_000, 2_000, 2_000],
|
||||
timeout: 20_000
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user