[ACA-4070] Add unit tests for linking rule sets (#2878)

* Commit before rebase

* Added some tests in the rule set picker

* Add unit tests for manage rules component
This commit is contained in:
Thomas Hunter
2023-01-04 16:14:03 +00:00
committed by GitHub
parent d8aba8c174
commit 8f28408607
8 changed files with 199 additions and 15 deletions

View File

@@ -0,0 +1,116 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
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 { 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 { By } from '@angular/platform-browser';
describe('RuleSetPickerSmartComponent', () => {
let fixture: ComponentFixture<RuleSetPickerSmartComponent>;
let component: RuleSetPickerSmartComponent;
let folderRuleSetsService: FolderRuleSetsService;
let loadRuleSetsSpy: jasmine.Spy;
const dialogRef = {
close: jasmine.createSpy('close'),
open: jasmine.createSpy('open')
};
const dialogOptions: RuleSetPickerOptions = {
nodeId: 'folder-1-id',
defaultNodeId: 'folder-1-id'
};
beforeEach(() => {
TestBed.configureTestingModule({
imports: [CoreTestingModule],
providers: [
{ provide: MatDialogRef, useValue: dialogRef },
{ provide: MAT_DIALOG_DATA, useValue: dialogOptions }
]
});
folderRuleSetsService = TestBed.inject(FolderRuleSetsService);
fixture = TestBed.createComponent(RuleSetPickerSmartComponent);
component = fixture.componentInstance;
component['folderRuleSetsService'] = folderRuleSetsService;
loadRuleSetsSpy = spyOn(folderRuleSetsService, 'loadRuleSets');
});
it('should load the rule sets of a node once it has been selected', () => {
expect(loadRuleSetsSpy).not.toHaveBeenCalled();
component.onNodeSelect([folderToLinkMock]);
expect(loadRuleSetsSpy).toHaveBeenCalledWith(folderToLinkMock.id, false);
component.onNodeSelect([folderToLinkMock]);
expect(loadRuleSetsSpy).toHaveBeenCalledTimes(1);
});
it('should show an empty list message if a selected folder has no rules', () => {
component.mainRuleSet$ = of(ruleSetWithNoRulesToLinkMock);
component.rulesLoading$ = of(false);
component.onNodeSelect([folderToLinkMock]);
fixture.detectChanges();
const items = fixture.debugElement.queryAll(By.css('.aca-rule-set-picker__content__rule-list aca-rule-list-item'));
expect(items.length).toBe(0);
const emptyList = fixture.debugElement.query(By.css('adf-empty-content'));
expect(emptyList).not.toBeNull();
});
it('should show an empty list message if a selected folder has linked rules', () => {
component.mainRuleSet$ = of(ruleSetWithLinkMock);
component.rulesLoading$ = of(false);
component.onNodeSelect([folderToLinkMock]);
fixture.detectChanges();
const items = fixture.debugElement.queryAll(By.css('.aca-rule-set-picker__content__rule-list aca-rule-list-item'));
expect(items.length).toBe(0);
const emptyList = fixture.debugElement.query(By.css('adf-empty-content'));
expect(emptyList).not.toBeNull();
});
it('should show a list of items if a selected folder has owned rules', () => {
component.mainRuleSet$ = of(ruleSetWithOwnedRulesToLinkMock);
component.rulesLoading$ = of(false);
component.onNodeSelect([folderToLinkMock]);
fixture.detectChanges();
const items = fixture.debugElement.queryAll(By.css('.aca-rule-set-picker__content__rule-list aca-rule-list-item'));
expect(items.length).toBe(2);
const emptyList = fixture.debugElement.query(By.css('adf-empty-content'));
expect(emptyList).toBeNull();
});
});

View File

@@ -44,12 +44,7 @@ export interface RuleSetPickerOptions {
styleUrls: ['./rule-set-picker.smart-component.scss'],
encapsulation: ViewEncapsulation.None,
host: { class: 'aca-rule-set-picker' },
providers: [
{
provide: FolderRuleSetsService,
useClass: FolderRuleSetsService
}
]
providers: [FolderRuleSetsService]
})
export class RuleSetPickerSmartComponent {
nodeId = '-root-';