test refactored

pull/15938/head
masumulu28 3 years ago
parent 309eeada03
commit bfb3b0ccd9

@ -1,4 +1,4 @@
import { Injectable, Injector, Inject, OnDestroy} from '@angular/core'; import { Injectable, Injector, OnDestroy } from '@angular/core';
import { BehaviorSubject, Observable, Subscription } from 'rxjs'; import { BehaviorSubject, Observable, Subscription } from 'rxjs';
import { ABP } from '../models/common'; import { ABP } from '../models/common';
import { OTHERS_GROUP } from '../tokens'; import { OTHERS_GROUP } from '../tokens';
@ -182,9 +182,13 @@ export abstract class AbstractNavTreeService<T extends ABP.Nav>
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class RoutesService extends AbstractNavTreeService<ABP.Route> { export class RoutesService extends AbstractNavTreeService<ABP.Route> {
constructor(injector: Injector, @Inject(OTHERS_GROUP) private readonly othersGroup: string) { private readonly othersGroup: string;
constructor(injector: Injector) {
super(injector); super(injector);
this.othersGroup = injector.get(OTHERS_GROUP);
} }
get groupedVisible(): ABP.RouteGroup[] | undefined { get groupedVisible(): ABP.RouteGroup[] | undefined {
const hasGroup = this.visible.some(node => !!node.group); const hasGroup = this.visible.some(node => !!node.group);
if (!hasGroup) return; if (!hasGroup) return;

@ -10,9 +10,10 @@ export const mockRoutesService = (injectorPayload = {} as { [key: string]: any }
const injector = new DummyInjector({ const injector = new DummyInjector({
PermissionService: mockPermissionService(), PermissionService: mockPermissionService(),
ConfigStateService: { createOnUpdateStream: () => updateStream$ }, ConfigStateService: { createOnUpdateStream: () => updateStream$ },
OTHERS_GROUP: 'OthersGroup',
...injectorPayload, ...injectorPayload,
}); });
return new RoutesService(injector, 'OthersGroup'); return new RoutesService(injector);
}; };
describe('Routes Service', () => { describe('Routes Service', () => {
@ -71,9 +72,8 @@ describe('Routes Service', () => {
expect(visible[0].children[0].name).toBe('x'); expect(visible[0].children[0].name).toBe('x');
}); });
}); });
describe('#groupedVisible', () => { describe('#groupedVisible', () => {
it('should have groups and items', async () => { it('should return grouped route list', () => {
service.add(groupedRoutes); service.add(groupedRoutes);
const tree = service.groupedVisible; const tree = service.groupedVisible;

@ -14,6 +14,6 @@ export class DummyInjector extends Injector {
): T; ): T;
get(token: any, notFoundValue?: any): any; get(token: any, notFoundValue?: any): any;
get(token, notFoundValue?, flags?: InjectFlags): any { get(token, notFoundValue?, flags?: InjectFlags): any {
return this.payload[token.name || token]; return this.payload[token.name || token._desc || token];
} }
} }

Loading…
Cancel
Save