1 import {IdlService} from './idl.service';
2 import {EventService} from './event.service';
3 import {DbStoreService} from './db-store.service';
4 import {NetService} from './net.service';
5 import {AuthService} from './auth.service';
6 import {PcrudService} from './pcrud.service';
7 import {StoreService} from './store.service';
8 import {OrgService} from './org.service';
9 import {HatchService} from './hatch.service';
11 describe('OrgService', () => {
12 let idlService: IdlService;
13 let netService: NetService;
14 let authService: AuthService;
15 let pcrudService: PcrudService;
16 let orgService: OrgService;
17 let evtService: EventService;
18 let storeService: StoreService;
19 let hatchService: HatchService;
20 let dbStoreService: DbStoreService;
23 idlService = new IdlService();
24 evtService = new EventService();
25 hatchService = new HatchService();
26 storeService = new StoreService(null /* CookieService */, hatchService);
27 netService = new NetService(evtService);
28 authService = new AuthService(evtService, netService, storeService);
29 pcrudService = new PcrudService(idlService, netService, authService);
30 dbStoreService = new DbStoreService();
31 orgService = new OrgService(dbStoreService, netService, authService, pcrudService);
34 const initTestData = () => {
35 idlService.parseIdl();
36 const win: any = window; // trick TS
37 win._eg_mock_data.generateOrgTree(idlService, orgService);
40 it('should provide get by ID', () => {
42 expect(orgService.get(orgService.tree().id())).toBe(orgService.root());
45 it('should provide get by node', () => {
47 expect(orgService.get(orgService.tree())).toBe(orgService.root());
50 it('should provide ancestors', () => {
52 expect(orgService.ancestors(2, true)).toEqual([2, 1]);
55 it('should provide descendants', () => {
57 expect(orgService.descendants(2, true)).toEqual([2, 4]);
60 it('should provide full path', () => {
62 expect(orgService.fullPath(4, true)).toEqual([4, 2, 1]);
65 it('should provide root', () => {
67 expect(orgService.root().id()).toEqual(1);
70 it('should sort tree by shortname', () => {
72 orgService.sortTree('shortname');
73 expect(orgService.root().children()[0].shortname()).toEqual('A');