]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/core/org.spec.ts
LP#1876163 - Fix Angular Test Failure
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / core / org.spec.ts
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';
10
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;
21
22     beforeEach(() => {
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);
32     });
33
34     const initTestData = () => {
35         idlService.parseIdl();
36         const win: any = window; // trick TS
37         win._eg_mock_data.generateOrgTree(idlService, orgService);
38     };
39
40     it('should provide get by ID', () => {
41         initTestData();
42         expect(orgService.get(orgService.tree().id())).toBe(orgService.root());
43     });
44
45     it('should provide get by node', () => {
46         initTestData();
47         expect(orgService.get(orgService.tree())).toBe(orgService.root());
48     });
49
50     it('should provide ancestors', () => {
51         initTestData();
52         expect(orgService.ancestors(2, true)).toEqual([2, 1]);
53     });
54
55     it('should provide descendants', () => {
56         initTestData();
57         expect(orgService.descendants(2, true)).toEqual([2, 4]);
58     });
59
60     it('should provide full path', () => {
61         initTestData();
62         expect(orgService.fullPath(4, true)).toEqual([4, 2, 1]);
63     });
64
65     it('should provide root', () => {
66         initTestData();
67         expect(orgService.root().id()).toEqual(1);
68     });
69
70     it('should sort tree by shortname', () => {
71         initTestData();
72         orgService.sortTree('shortname');
73         expect(orgService.root().children()[0].shortname()).toEqual('A');
74     });
75
76 });
77
78