Skip to content

Commit

Permalink
[ACS-7365] Optimise Search providers and unit tests (#9477)
Browse files Browse the repository at this point in the history
refactor: optimise node selector imports and tests
  • Loading branch information
DenysVuika committed Mar 27, 2024
1 parent 77d9e7d commit f66342d
Show file tree
Hide file tree
Showing 142 changed files with 1,617 additions and 2,193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AspectListDialogComponent } from './aspect-list-dialog.component';
import { TranslateModule } from '@ngx-translate/core';
import { of, Subject } from 'rxjs';
import { ContentTestingModule } from '../testing/content.testing.module';
import { AspectListDialogComponentData } from './aspect-list-dialog-data.interface';
Expand Down Expand Up @@ -114,7 +113,7 @@ describe('AspectListDialogComponent', () => {
excludedAspects: []
};
await TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), ContentTestingModule, MatDialogModule],
imports: [ContentTestingModule, MatDialogModule],
providers: [
{ provide: MAT_DIALOG_DATA, useValue: data },
{
Expand Down Expand Up @@ -310,8 +309,7 @@ describe('AspectListDialogComponent', () => {
data.excludedAspects = ['some aspect 1', 'some aspect 2'];

fixture.detectChanges();
expect(fixture.debugElement.query(By.directive(AspectListComponent)).componentInstance.excludedAspects)
.toBe(data.excludedAspects);
expect(fixture.debugElement.query(By.directive(AspectListComponent)).componentInstance.excludedAspects).toBe(data.excludedAspects);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { NodesApiService } from '../common/services/nodes-api.service';
import { ContentTestingModule } from '../testing/content.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import { AspectListComponent } from './aspect-list.component';
import { AspectListService } from './services/aspect-list.service';
import { EMPTY, of } from 'rxjs';
Expand Down Expand Up @@ -120,7 +119,7 @@ describe('AspectListComponent', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), ContentTestingModule],
imports: [ContentTestingModule],
providers: [AspectListService]
});
});
Expand Down Expand Up @@ -176,8 +175,8 @@ describe('AspectListComponent', () => {
});

it('should show all the aspects', async () => {
expect(await loader.hasHarness(MatExpansionPanelHarness.with({selector: '#aspect-list-FirstAspect'}))).toBe(true);
expect(await loader.hasHarness(MatExpansionPanelHarness.with({selector: '#aspect-list-SecondAspect'}))).toBe(true);
expect(await loader.hasHarness(MatExpansionPanelHarness.with({ selector: '#aspect-list-FirstAspect' }))).toBe(true);
expect(await loader.hasHarness(MatExpansionPanelHarness.with({ selector: '#aspect-list-SecondAspect' }))).toBe(true);
});

it('should show aspect id when name or title is not set', () => {
Expand Down Expand Up @@ -259,8 +258,7 @@ describe('AspectListComponent', () => {
component.excludedAspects = ['cst:nonamedAspect'];

fixture.detectChanges();
expect(fixture.nativeElement.querySelector(`#aspect-list-${component.excludedAspects[0].replace(':', '-')}`))
.toBeNull();
expect(fixture.nativeElement.querySelector(`#aspect-list-${component.excludedAspects[0].replace(':', '-')}`)).toBeNull();
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/

import { TranslateModule } from '@ngx-translate/core';
import { ContentTestingModule } from '../../testing/content.testing.module';
import { DialogAspectListService } from './dialog-aspect-list.service';
import { AspectListDialogComponent } from '../aspect-list-dialog.component';
Expand All @@ -32,10 +31,7 @@ describe('DialogAspectListService', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
ContentTestingModule
]
imports: [ContentTestingModule]
});
dialogAspectListService = TestBed.inject(DialogAspectListService);
dialog = TestBed.inject(MatDialog);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import { Node } from '@alfresco/js-api';
import { TestBed } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { NodesApiService } from '../../common/services/nodes-api.service';
import { EMPTY, of } from 'rxjs';
import { ContentTestingModule } from '../../testing/content.testing.module';
Expand All @@ -34,7 +33,7 @@ describe('NodeAspectService', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), ContentTestingModule]
imports: [ContentTestingModule]
});
dialogAspectListService = TestBed.inject(DialogAspectListService);
nodeAspectService = TestBed.inject(NodeAspectService);
Expand Down Expand Up @@ -74,7 +73,7 @@ describe('NodeAspectService', () => {

it('should send and update node event once the node has been updated', () => {
let lastValue: Node;
nodeApiService.nodeUpdated.subscribe((nodeUpdated) => lastValue = nodeUpdated);
nodeApiService.nodeUpdated.subscribe((nodeUpdated) => (lastValue = nodeUpdated));
const fakeNode = new Node({ id: 'fake-node-id', aspectNames: ['a', 'b', 'c'] });
spyOn(dialogAspectListService, 'openAspectListDialog').and.returnValue(of(['a', 'b', 'c']));
spyOn(nodeApiService, 'updateNode').and.returnValue(of(fakeNode));
Expand All @@ -86,7 +85,7 @@ describe('NodeAspectService', () => {

it('should send and update node aspect once the node has been updated', () => {
let lastValue: Node;
cardViewContentUpdateService.updatedAspect$.subscribe((nodeUpdated) => lastValue = nodeUpdated);
cardViewContentUpdateService.updatedAspect$.subscribe((nodeUpdated) => (lastValue = nodeUpdated));
const fakeNode = new Node({ id: 'fake-node-id', aspectNames: ['a', 'b', 'c'] });
spyOn(dialogAspectListService, 'openAspectListDialog').and.returnValue(of(['a', 'b', 'c']));
spyOn(nodeApiService, 'updateNode').and.returnValue(of(fakeNode));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,21 @@ import { DocumentListComponent, DocumentListService } from '../document-list';
import { BreadcrumbComponent } from './breadcrumb.component';
import { ContentTestingModule } from '../testing/content.testing.module';
import { of } from 'rxjs';
import { TranslateModule } from '@ngx-translate/core';

describe('Breadcrumb', () => {

let component: BreadcrumbComponent;
let fixture: ComponentFixture<BreadcrumbComponent>;
let documentListService: DocumentListService = jasmine.createSpyObj({
loadFolderByNodeId : of(''),
loadFolderByNodeId: of(''),
isCustomSourceService: false
});
let documentListComponent: DocumentListComponent;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
ContentTestingModule
],
imports: [ContentTestingModule],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers : [{ provide: DocumentListService, useValue: documentListService }]
providers: [{ provide: DocumentListService, useValue: documentListService }]
});
fixture = TestBed.createComponent(BreadcrumbComponent);
component = fixture.componentInstance;
Expand Down Expand Up @@ -80,7 +75,6 @@ describe('Breadcrumb', () => {
});

describe('target', () => {

let folderNode: Node;

beforeEach(() => {
Expand Down Expand Up @@ -115,11 +109,13 @@ describe('Breadcrumb', () => {

component.onRoutePathClick(node, null);

expect(documentListService.loadFolderByNodeId).toHaveBeenCalledWith(node.id,
expect(documentListService.loadFolderByNodeId).toHaveBeenCalledWith(
node.id,
documentListComponent.DEFAULT_PAGINATION,
documentListComponent.includeFields,
documentListComponent.where,
documentListComponent.orderBy);
documentListComponent.orderBy
);
});

it('should build the path based on the document list node', () => {
Expand Down Expand Up @@ -186,9 +182,7 @@ describe('Breadcrumb', () => {
id: 'test-id',
name: 'test-name',
path: {
elements: [
{ id: 'element-id', name: 'element-name' }
]
elements: [{ id: 'element-id', name: 'element-name' }]
}
};
const route = component.parseRoute(node);
Expand Down Expand Up @@ -295,11 +289,11 @@ describe('Breadcrumb', () => {
]
}
};
component.transform = ((transformNode) => {
component.transform = (transformNode) => {
transformNode.id = 'test-id';
transformNode.name = 'test-name';
return transformNode;
});
};
component.folderNode = node;
component.ngOnChanges();
expect(component.route.length).toBe(4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { DocumentListComponent, DocumentListService } from '../document-list';
import { DropdownBreadcrumbComponent } from './dropdown-breadcrumb.component';
import { ContentTestingModule } from '../testing/content.testing.module';
import { of } from 'rxjs';
import { TranslateModule } from '@ngx-translate/core';

describe('DropdownBreadcrumb', () => {
let component: DropdownBreadcrumbComponent;
Expand All @@ -33,7 +32,7 @@ describe('DropdownBreadcrumb', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), ContentTestingModule],
imports: [ContentTestingModule],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [{ provide: DocumentListService, useValue: documentListService }]
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { Validators } from '@angular/forms';
import { MatError } from '@angular/material/form-field';
import { MatList } from '@angular/material/list';
import { By } from '@angular/platform-browser';
import { TranslateModule } from '@ngx-translate/core';
import { of, Subject } from 'rxjs';
import { ContentTestingModule } from '../../testing/content.testing.module';
import { CategoriesManagementMode } from './categories-management-mode';
Expand Down Expand Up @@ -49,7 +48,7 @@ describe('CategoriesManagementComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [CategoriesManagementComponent],
imports: [TranslateModule.forRoot(), ContentTestingModule],
imports: [ContentTestingModule],
providers: [
{
provide: CategoryService,
Expand Down Expand Up @@ -384,7 +383,7 @@ describe('CategoriesManagementComponent', () => {
flush();
}));

it ('should disable existing categories list if category already selected and multiSelect is false', fakeAsync(() => {
it('should disable existing categories list if category already selected and multiSelect is false', fakeAsync(() => {
component.multiSelect = false;
fixture.detectChanges();
typeCategory('test');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,15 @@ import { TestBed } from '@angular/core/testing';
import { ContentService } from './content.service';
import { AppConfigService, AuthenticationService, StorageService, CoreTestingModule } from '@alfresco/adf-core';
import { Node, PermissionsInfo } from '@alfresco/js-api';
import { TranslateModule } from '@ngx-translate/core';

describe('ContentService', () => {

let contentService: ContentService;
let authService: AuthenticationService;
let storage: StorageService;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
CoreTestingModule
]
imports: [CoreTestingModule]
});
authService = TestBed.inject(AuthenticationService);
contentService = TestBed.inject(ContentService);
Expand All @@ -47,7 +42,6 @@ describe('ContentService', () => {
});

describe('AllowableOperations', () => {

it('should hasAllowableOperations be false if allowableOperation is not present in the node', () => {
const permissionNode = new Node({});
expect(contentService.hasAllowableOperations(permissionNode, 'create')).toBeFalsy();
Expand All @@ -59,7 +53,7 @@ describe('ContentService', () => {
expect(contentService.hasAllowableOperations(permissionNode, 'create')).toBeTruthy();
});

it('should hasAllowableOperations be false if allowableOperation is present but you don\'t have the permission for the request operation', () => {
it('should hasAllowableOperations be false if allowableOperation is present but you do not have the permission for the request operation', () => {
const permissionNode = new Node({ allowableOperations: ['delete', 'update', 'updatePermissions'] });
expect(contentService.hasAllowableOperations(permissionNode, 'create')).toBeFalsy();
});
Expand All @@ -81,30 +75,58 @@ describe('ContentService', () => {
});

describe('Permissions', () => {

it('should havePermission be false if allowableOperation is not present in the node', () => {
const permissionNode = new Node({});
expect(contentService.hasPermissions(permissionNode, 'manager')).toBeFalsy();
});

it('should havePermission be true if permissions is present and you have the permission for the request operation', () => {
const permissionNode = new Node({ permissions: { locallySet: [{ name: 'manager', authorityId: 'user1' }, { name: 'collaborator', authorityId: 'user2' }, { name: 'consumer', authorityId: 'user3' }] } });
const permissionNode = new Node({
permissions: {
locallySet: [
{ name: 'manager', authorityId: 'user1' },
{ name: 'collaborator', authorityId: 'user2' },
{ name: 'consumer', authorityId: 'user3' }
]
}
});

expect(contentService.hasPermissions(permissionNode, 'manager', 'user1')).toBeTruthy();
});

it('should havePermission be false if permissions is present but you don\'t have the permission for the request operation', () => {
const permissionNode = new Node({ permissions: { locallySet: [{ name: 'collaborator', authorityId: 'user1' }, { name: 'consumer', authorityId: 'user2' }] } });
it('should havePermission be false if permissions is present but you do not have the permission for the request operation', () => {
const permissionNode = new Node({
permissions: {
locallySet: [
{ name: 'collaborator', authorityId: 'user1' },
{ name: 'consumer', authorityId: 'user2' }
]
}
});
expect(contentService.hasPermissions(permissionNode, 'manager', 'user1')).toBeFalsy();
});

it('should havePermission works in the opposite way with negate value', () => {
const permissionNode = new Node({ permissions: { locallySet: [{ name: 'collaborator', authorityId: 'user1' }, { name: 'consumer', authorityId: 'user2' }] } });
const permissionNode = new Node({
permissions: {
locallySet: [
{ name: 'collaborator', authorityId: 'user1' },
{ name: 'consumer', authorityId: 'user2' }
]
}
});
expect(contentService.hasPermissions(permissionNode, '!manager', 'user1')).toBeTruthy();
});

it('should havePermission return false if no permission parameter are passed', () => {
const permissionNode = new Node({ permissions: { locallySet: [{ name: 'collaborator', authorityId: 'user1' }, { name: 'consumer', authorityId: 'user2' }] } });
const permissionNode = new Node({
permissions: {
locallySet: [
{ name: 'collaborator', authorityId: 'user1' },
{ name: 'consumer', authorityId: 'user2' }
]
}
});
expect(contentService.hasPermissions(permissionNode, null, 'user1')).toBeFalsy();
});

Expand All @@ -119,13 +141,27 @@ describe('ContentService', () => {
});

it('should havePermission be true if inherited permissions is present and you have the permission for the request operation', () => {
const permissionNode = new Node({ permissions: { inherited: [{ name: 'manager', authorityId: 'user1' }, { name: 'collaborator', authorityId: 'user2' } ] } });
const permissionNode = new Node({
permissions: {
inherited: [
{ name: 'manager', authorityId: 'user1' },
{ name: 'collaborator', authorityId: 'user2' }
]
}
});
expect(contentService.hasPermissions(permissionNode, 'manager', 'user1')).toBeTruthy();
});

it('should take current logged user id if userId undefined ', () => {
spyOn(authService, 'getEcmUsername').and.returnValue('user1');
const permissionNode = new Node({ permissions: { inherited: [{ name: 'manager', authorityId: 'user1' }, { name: 'collaborator', authorityId: 'user2' } ] } });
const permissionNode = new Node({
permissions: {
inherited: [
{ name: 'manager', authorityId: 'user1' },
{ name: 'collaborator', authorityId: 'user2' }
]
}
});
expect(contentService.hasPermissions(permissionNode, 'manager')).toBeTruthy();
});
});
Expand Down

0 comments on commit f66342d

Please sign in to comment.