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