2 * ========================LICENSE_START=================================
5 * Copyright (C) 2021 Nordix Foundation
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
21 import { TestBed } from '@angular/core/testing';
22 import { BehaviorSubject, of } from 'rxjs';
23 import { NotificationService } from '../services/ui/notification.service';
24 import { ToastrModule } from 'ngx-toastr';
25 import { PolicyTypeDataSource } from './policy-type.datasource';
26 import { PolicyService } from '../services/policy/policy.service';
27 import { PolicyTypeSchema } from '../interfaces/policy.types';
29 describe('PolicyTypeDataSource', () => {
30 let policyTypeDataSource: PolicyTypeDataSource;
31 let policyServiceSpy: any;
35 "$schema": "http://json-schema.org/draft-07/schema#",
36 "description": "Type 1 policy type",
37 "additionalProperties": false,
44 policyServiceSpy = jasmine.createSpyObj('PolicyService', ['getPolicyTypes', 'getPolicyType']);
46 policyServiceSpy.getPolicyTypes.and.returnValue(of({ policytype_ids: ['1', '2'] }));
47 policyServiceSpy.getPolicyType.and.returnValue(of(policySchema));
48 TestBed.configureTestingModule({
49 imports: [ToastrModule.forRoot()],
51 { provide: PolicyService, useValue: policyServiceSpy },
57 describe('#getPolicyTypes', () => {
58 let expectedPolicyTypeValue: PolicyTypeSchema[];
60 expectedPolicyTypeValue = [
64 'schemaObject': policySchema.policy_schema
69 'schemaObject': policySchema.policy_schema
74 it('should create', () => {
75 policyTypeDataSource = TestBed.get(PolicyTypeDataSource);
76 expect(policyTypeDataSource).toBeTruthy();
79 it('should return all policy type with Schema', () => {
80 policyTypeDataSource.getPolicyTypes();
81 const jobsSubject: BehaviorSubject<PolicyTypeSchema[]> = policyTypeDataSource.policyTypeSubject;
82 const value = jobsSubject.getValue();
83 expect(value).toEqual(expectedPolicyTypeValue);