|
|
|
@ -1,11 +1,14 @@
|
|
|
|
|
import { Subject } from 'rxjs';
|
|
|
|
|
import { take } from 'rxjs/operators';
|
|
|
|
|
import { ABP } from '../models';
|
|
|
|
|
import { RoutesService } from '../services/routes.service';
|
|
|
|
|
import { DummyInjector } from './utils/common.utils';
|
|
|
|
|
import { mockPermissionService } from './utils/permission-service.spec.utils';
|
|
|
|
|
|
|
|
|
|
const updateStream$ = new Subject<void>();
|
|
|
|
|
|
|
|
|
|
type GroupType = ABP.Group<string>;
|
|
|
|
|
|
|
|
|
|
export const mockRoutesService = (injectorPayload = {} as { [key: string]: any }) => {
|
|
|
|
|
const injector = new DummyInjector({
|
|
|
|
|
PermissionService: mockPermissionService(),
|
|
|
|
@ -17,6 +20,10 @@ export const mockRoutesService = (injectorPayload = {} as { [key: string]: any }
|
|
|
|
|
|
|
|
|
|
describe('Routes Service', () => {
|
|
|
|
|
let service: RoutesService;
|
|
|
|
|
|
|
|
|
|
const fooGroup: GroupType = { key: 'foo', text: '::FooGroup' };
|
|
|
|
|
const barGroup: GroupType = { key: 'bar', text: '::BarGroup' };
|
|
|
|
|
|
|
|
|
|
const routes = [
|
|
|
|
|
{ path: '/foo', name: 'foo' },
|
|
|
|
|
{ path: '/foo/bar', name: 'bar', parentName: 'foo', invisible: true, order: 2 },
|
|
|
|
@ -25,6 +32,13 @@ describe('Routes Service', () => {
|
|
|
|
|
{ path: '/foo/x', name: 'x', parentName: 'foo', order: 1 },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const groupedRoutes = [
|
|
|
|
|
{ path: '/foo', name: 'foo', group: fooGroup },
|
|
|
|
|
{ path: '/foo/bar', name: 'bar', group: barGroup },
|
|
|
|
|
{ path: '/foo/bar/baz', name: 'baz', group: barGroup },
|
|
|
|
|
{ path: '/foo/y', name: 'y', parentName: 'foo' },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
service = mockRoutesService();
|
|
|
|
|
});
|
|
|
|
@ -59,6 +73,18 @@ describe('Routes Service', () => {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('#addGroup', () => {
|
|
|
|
|
it('should have routes with and without group', async () => {
|
|
|
|
|
service.add(groupedRoutes);
|
|
|
|
|
|
|
|
|
|
const grouped = await service.flat.filter(f => f.group);
|
|
|
|
|
const unGrouped = await service.flat.filter(f => !f.group);
|
|
|
|
|
|
|
|
|
|
expect(grouped.length).toBe(3);
|
|
|
|
|
expect(unGrouped.length).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('#find', () => {
|
|
|
|
|
it('should return node found based on query', () => {
|
|
|
|
|
service.add(routes);
|
|
|
|
|