]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/core/idl.spec.ts
LP 1857351: admin-page grid column order respects specified fieldOrder
[Evergreen.git] / Open-ILS / src / eg2 / src / app / core / idl.spec.ts
1 import {IdlService} from './idl.service';
2
3 describe('IdlService', () => {
4     let service: IdlService;
5     beforeEach(() => {
6         service = new IdlService();
7     });
8
9     it('should parse the IDL', () => {
10         service.parseIdl();
11         expect(service.classes['aou'].fields.length).toBeGreaterThan(0);
12     });
13
14     it('should create an aou object', () => {
15         service.parseIdl();
16         const org = service.create('aou');
17         expect(typeof org.id).toBe('function');
18     });
19
20     it('should create an aou object with accessor/mutators', () => {
21         service.parseIdl();
22         const org = service.create('aou');
23         org.name('AN ORG');
24         expect(org.name()).toBe('AN ORG');
25     });
26
27     it('should correctly compare IDL pkey values', () => {
28         service.parseIdl();
29         const org1 = service.create('aou');
30         const org2 = service.create('aou');
31         org1.id(123);
32         org2.id(123);
33         expect(service.pkeyMatches(org1, org2)).toBe(true);
34     });
35
36     it('should correctly compare IDL pkey values', () => {
37         service.parseIdl();
38         const org1 = service.create('aou');
39         const org2 = service.create('aou');
40         org1.id(123);
41         org2.id(456);
42         expect(service.pkeyMatches(org1, org2)).toBe(false);
43     });
44
45     it('should correctly compare IDL classes in pkey match', () => {
46         service.parseIdl();
47         const org = service.create('aou');
48         const user = service.create('au');
49         org.id(123);
50         user.id(123);
51         expect(service.pkeyMatches(org, user)).toBe(false);
52     });
53
54     it('should sort an array of IDL fields according to an array of field names', () => {
55         const fieldNames = ['name', 'owner', 'active', 'id'];
56         const idlFields = [
57             {'name': 'id', 'label': 'Object ID', 'dataType': 'id'},
58             {'name': 'name', 'label': 'The name of this object', 'datatype': 'text'},
59             {'name': 'active', 'datatype': 'bool'},
60             {'name': 'owner', 'type': 'link', 'key': 'id', 'class': 'aou', 'reltype': 'has_a', 'datatype': 'org_unit'}
61         ];
62         const expectedOrder = [
63             {'name': 'name', 'label': 'The name of this object', 'datatype': 'text'},
64             {'name': 'owner', 'type': 'link', 'key': 'id', 'class': 'aou', 'reltype': 'has_a', 'datatype': 'org_unit'},
65             {'name': 'active', 'datatype': 'bool'},
66             {'name': 'id', 'label': 'Object ID', 'dataType': 'id'},
67         ];
68         expect(service.sortIdlFields(idlFields, fieldNames)).toEqual(expectedOrder);
69     });
70
71     it('should sort IDL fields by label when it runs out of specified field names', () => {
72         const fieldNames = ['owner'];
73         const idlFields = [
74             {'name': 'id', 'label': 'Object ID', 'dataType': 'id'},
75             {'name': 'name', 'label': 'The name of this object', 'datatype': 'text'},
76             {'name': 'owner', 'type': 'link', 'key': 'id', 'class': 'aou', 'reltype': 'has_a', 'datatype': 'org_unit'}
77         ];
78         const expectedOrder = [
79             {'name': 'owner', 'type': 'link', 'key': 'id', 'class': 'aou', 'reltype': 'has_a', 'datatype': 'org_unit'},
80             {'name': 'id', 'label': 'Object ID', 'dataType': 'id'},
81             {'name': 'name', 'label': 'The name of this object', 'datatype': 'text'},
82         ];
83         expect(service.sortIdlFields(idlFields, fieldNames)).toEqual(expectedOrder);
84     });
85
86     it('should sort IDL fields by name when it runs out of other ways to sort', () => {
87         const fieldNames = ['owner'];
88         const idlFields = [
89             {'name': 'id', 'dataType': 'id'},
90             {'name': 'name', 'label': 'The name of this object', 'datatype': 'text'},
91             {'name': 'active', 'datatype': 'bool'},
92             {'name': 'owner', 'type': 'link', 'key': 'id', 'class': 'aou', 'reltype': 'has_a', 'datatype': 'org_unit'}
93         ];
94         const expectedOrder = [
95             {'name': 'owner', 'type': 'link', 'key': 'id', 'class': 'aou', 'reltype': 'has_a', 'datatype': 'org_unit'},
96             {'name': 'name', 'label': 'The name of this object', 'datatype': 'text'},
97             {'name': 'active', 'datatype': 'bool'},
98             {'name': 'id', 'dataType': 'id'},
99         ];
100         expect(service.sortIdlFields(idlFields, fieldNames)).toEqual(expectedOrder);
101     });
102
103 });
104