Reorganise policy control part of frontend
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / policy / policy-type / policy-type.datasource.spec.ts
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2021 Nordix Foundation
6  * %%
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20
21 import { TestBed } from '@angular/core/testing';
22 import { BehaviorSubject, of } from 'rxjs';
23 import { ToastrModule } from 'ngx-toastr';
24 import { PolicyTypeDataSource } from './policy-type.datasource';
25 import { PolicyService } from '@services/policy/policy.service';
26 import { PolicyTypeSchema } from '@interfaces/policy.types';
27
28 describe('PolicyTypeDataSource', () => {
29   let policyTypeDataSource: PolicyTypeDataSource;
30   let policyServiceSpy: any;
31
32   let policySchema = {
33     policy_schema: {
34       "$schema": "http://json-schema.org/draft-07/schema#",
35       "description": "Type 1 policy type",
36       "additionalProperties": false,
37       "title": "1",
38       "type": "object"
39     }
40   };
41
42   beforeEach(() => {
43     policyServiceSpy = jasmine.createSpyObj('PolicyService', ['getPolicyTypes', 'getPolicyType']);
44
45     policyServiceSpy.getPolicyTypes.and.returnValue(of({ policytype_ids: ['1', '2'] }));
46     policyServiceSpy.getPolicyType.and.returnValue(of(policySchema));
47     TestBed.configureTestingModule({
48       imports: [ToastrModule.forRoot()],
49       providers: [
50         { provide: PolicyService, useValue: policyServiceSpy }
51       ]
52     });
53   });
54
55   describe('#getPolicyTypes', () => {
56     let expectedPolicyTypeValue: PolicyTypeSchema[];
57     beforeEach(() => {
58       expectedPolicyTypeValue = [
59         {
60           'id': '1',
61           'name': '1',
62           'schemaObject': policySchema.policy_schema
63         },
64         {
65           'id': '2',
66           'name': '1',
67           'schemaObject': policySchema.policy_schema
68         }
69       ];
70     });
71
72     it('should create', () => {
73       policyTypeDataSource = TestBed.inject(PolicyTypeDataSource);
74       expect(policyTypeDataSource).toBeTruthy();
75     });
76
77     it('should return all policy type with Schema', () => {
78       policyTypeDataSource.getPolicyTypes();
79       const jobsSubject: BehaviorSubject<PolicyTypeSchema[]> = policyTypeDataSource.policyTypeSubject;
80       const value = jobsSubject.getValue();
81       expect(value).toEqual(expectedPolicyTypeValue);
82     });
83   });
84 });