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===================================
20 import { TestBed } from '@angular/core/testing';
21 import { BehaviorSubject, of } from 'rxjs';
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';
29 describe('EIProducerDataSource', () => {
30 let dataSource: EIProducerDataSource;
31 let eiServiceSpy: any;
34 supported_ei_types: [ 'type1', 'type2' ]
35 } as ProducerRegistrationInfo;
37 supported_ei_types: [ 'type3', 'type4' ]
38 } as ProducerRegistrationInfo;
39 let producerStatus1 = {
40 opState: OperationalState.ENABLED
42 let producerStatus2 = {
43 opState: OperationalState.DISABLED
46 let expectedProducer1 = {
47 ei_producer_id: 'producer1',
48 ei_producer_types: [ 'type1', 'type2' ],
51 let expectedProducer2 = {
52 ei_producer_id: 'producer2',
53 ei_producer_types: [ 'type3', 'type4' ],
58 eiServiceSpy = jasmine.createSpyObj('EIService', ['getProducerIds', 'getProducer', 'getProducerStatus']);
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()],
66 { provide: EIService, useValue: eiServiceSpy },
72 it('should create', () => {
73 dataSource = TestBed.get(EIProducerDataSource);
74 expect(dataSource).toBeTruthy();
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);