107daae2168b37d72db8e85ba840bc7ba5c9aa1a
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / ei-coordinator / ei-producer.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 import { TestBed } from '@angular/core/testing';
21 import { BehaviorSubject, of } from 'rxjs';
22
23 import { EIService } from '../services/ei/ei.service';
24 import { NotificationService } from '../services/ui/notification.service';
25 import { ToastrModule } from 'ngx-toastr';
26 import { EIProducer, OperationalState, ProducerRegistrationInfo, ProducerStatus } from '../interfaces/ei.types';
27 import { EIProducerDataSource } from './ei-producer.datasource';
28
29 describe('EIProducerDataSource', () => {
30     let dataSource: EIProducerDataSource;
31     let eiServiceSpy: any;
32
33     let producer1 = {
34         supported_ei_types: [ 'type1', 'type2' ]
35     } as ProducerRegistrationInfo;
36     let producer2 = {
37         supported_ei_types: [ 'type3', 'type4' ]
38     } as ProducerRegistrationInfo;
39     let producerStatus1 = {
40         opState: OperationalState.ENABLED
41     } as ProducerStatus;
42     let producerStatus2 = {
43         opState: OperationalState.DISABLED
44     } as ProducerStatus;
45
46     let expectedProducer1 = {
47         ei_producer_id: 'producer1',
48         ei_producer_types: [ 'type1', 'type2' ],
49         status: 'ENABLED'
50     } as EIProducer;
51     let expectedProducer2 = {
52         ei_producer_id: 'producer2',
53         ei_producer_types: [ 'type3', 'type4' ],
54         status: 'DISABLED'
55     } as EIProducer;
56
57     beforeEach(() => {
58         eiServiceSpy = jasmine.createSpyObj('EIService', ['getProducerIds', 'getProducer', 'getProducerStatus']);
59
60         eiServiceSpy.getProducerIds.and.returnValue(of([ 'producer1', 'producer2']));
61         eiServiceSpy.getProducer.and.returnValues(of(producer1), of(producer2));
62         eiServiceSpy.getProducerStatus.and.returnValues(of(producerStatus1), of(producerStatus2));
63         TestBed.configureTestingModule({
64             imports: [ToastrModule.forRoot()],
65             providers: [
66                 { provide: EIService, useValue: eiServiceSpy },
67                 NotificationService
68             ]
69         });
70     });
71
72     it('should create', () => {
73         dataSource = TestBed.get(EIProducerDataSource);
74         expect(dataSource).toBeTruthy();
75     });
76
77     it('#loadProducers', () => {
78         dataSource.loadProducers();
79         const jobsSubject: BehaviorSubject<EIProducer[]> = dataSource.producerSubject;
80         const value = jobsSubject.getValue();
81         expect(value).toEqual([ expectedProducer1, expectedProducer2 ]);
82         expect(dataSource.rowCount).toEqual(2);
83     });
84 });