Skip to content

Commit

Permalink
[ACS-4538] Fix folder-rules unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalKinas committed Jun 16, 2023
1 parent 2e76375 commit 1026712
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
6 changes: 5 additions & 1 deletion app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@
"assets": [
"app/src/assets",
"app/src/favicon-96x96.png",
"projects/aca-content/assets",
{
"glob": "**/*",
"input": "projects/aca-content/assets",
"output": "/assets"
},
{
"input": "app/.tmp",
"output": "/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
ruleSetWithLinkMock
} from '../mock/rule-sets.mock';
import { By } from '@angular/platform-browser';
import { owningFolderIdMock, owningFolderMock } from '../mock/node.mock';
import { getOwningFolderEntryMock, owningFolderIdMock, owningFolderMock } from '../mock/node.mock';
import { MatDialog } from '@angular/material/dialog';
import { ActionsService } from '../services/actions.service';
import { FolderRuleSetsService } from '../services/folder-rule-sets.service';
Expand All @@ -54,6 +54,7 @@ describe('ManageRulesSmartComponent', () => {
let folderRuleSetsService: FolderRuleSetsService;
let folderRulesService: FolderRulesService;
let actionsService: ActionsService;
let callApiSpy: jasmine.Spy;

beforeEach(() => {
TestBed.configureTestingModule({
Expand Down Expand Up @@ -82,6 +83,19 @@ describe('ManageRulesSmartComponent', () => {
actionsService = TestBed.inject(ActionsService);

spyOn(actionsService, 'loadActionDefinitions').and.stub();
spyOn(folderRulesService, 'getRuleSettings').and.returnValue(Promise.resolve(ruleSettingsMock));
callApiSpy = spyOn<any>(folderRuleSetsService, 'callApi');
callApiSpy
.withArgs(`/nodes/${owningFolderIdMock}/rule-sets?include=isLinkedTo,owningFolder,linkedToBy&skipCount=0&maxItems=100`, 'GET')
.and.returnValue(Promise.resolve(ownedRuleSetMock))
.withArgs(`/nodes/${owningFolderIdMock}/rule-sets/-default-?include=isLinkedTo,owningFolder,linkedToBy`, 'GET')
.and.returnValue(Promise.resolve(ownedRuleSetMock))
.withArgs(`/nodes/${owningFolderIdMock}?include=path%2Cproperties%2CallowableOperations%2Cpermissions`, 'GET')
.and.returnValue(Promise.resolve(getOwningFolderEntryMock));
});

afterEach(() => {
fixture.destroy();
});

it('should show a list of rule sets and rules', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RuleSetPickerOptions, RuleSetPickerSmartComponent } from './rule-set-picker.smart-component';
import { CoreTestingModule } from '@alfresco/adf-core';
import { folderToLinkMock } from '../mock/node.mock';
import { folderToLinkMock, otherFolderMock } from '../mock/node.mock';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { FolderRuleSetsService } from '../services/folder-rule-sets.service';
import { of } from 'rxjs';
import { ruleSetWithLinkMock, ruleSetWithNoRulesToLinkMock, ruleSetWithOwnedRulesToLinkMock } from '../mock/rule-sets.mock';
import { ownedRuleSetMock, ruleSetWithLinkMock, ruleSetWithNoRulesToLinkMock, ruleSetWithOwnedRulesToLinkMock } from '../mock/rule-sets.mock';
import { ContentApiService } from '../../../../aca-shared/src/public-api';
import { By } from '@angular/platform-browser';

describe('RuleSetPickerSmartComponent', () => {
Expand All @@ -38,6 +39,7 @@ describe('RuleSetPickerSmartComponent', () => {
let folderRuleSetsService: FolderRuleSetsService;

let loadRuleSetsSpy: jasmine.Spy;
let callApiSpy: jasmine.Spy;

const dialogRef = {
close: jasmine.createSpy('close'),
Expand All @@ -54,7 +56,18 @@ describe('RuleSetPickerSmartComponent', () => {
imports: [CoreTestingModule],
providers: [
{ provide: MatDialogRef, useValue: dialogRef },
{ provide: MAT_DIALOG_DATA, useValue: dialogOptions }
{ provide: MAT_DIALOG_DATA, useValue: dialogOptions },
{
provide: ContentApiService,
useValue: {
getNode: () => {
return of({ entry: folderToLinkMock });
},
getNodeInfo: () => {
return of(otherFolderMock);
}
}
}
]
});

Expand All @@ -63,7 +76,19 @@ describe('RuleSetPickerSmartComponent', () => {
component = fixture.componentInstance;
component['folderRuleSetsService'] = folderRuleSetsService;

loadRuleSetsSpy = spyOn(folderRuleSetsService, 'loadRuleSets');
loadRuleSetsSpy = spyOn(folderRuleSetsService, 'loadRuleSets').and.callThrough();
callApiSpy = spyOn<any>(folderRuleSetsService, 'callApi');
callApiSpy
.withArgs(`/nodes/${dialogOptions.nodeId}/rule-sets?include=isLinkedTo,owningFolder,linkedToBy&skipCount=0&maxItems=100`, 'GET')
.and.returnValue(Promise.resolve(ownedRuleSetMock))
.withArgs(`/nodes/${dialogOptions.nodeId}/rule-sets/-default-?include=isLinkedTo,owningFolder,linkedToBy`, 'GET')
.and.returnValue(Promise.resolve(ownedRuleSetMock))
.withArgs(`/nodes/${folderToLinkMock.id}?include=path%2Cproperties%2CallowableOperations%2Cpermissions`, 'GET')
.and.returnValue(Promise.resolve({ entry: folderToLinkMock }));
});

afterEach(() => {
fixture.destroy();
});

it('should load the rule sets of a node once it has been selected', () => {
Expand Down

0 comments on commit 1026712

Please sign in to comment.