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 { of } from 'rxjs';
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';
28 describe('EIProducerDataSource', () => {
29 let dataSource: EIProducerDataSource;
30 let eiServiceSpy: any;
33 supported_ei_types: ['type1', 'type2']
34 } as ProducerRegistrationInfo;
36 supported_ei_types: ['type3', 'type4']
37 } as ProducerRegistrationInfo;
38 let producerStatus1 = {
39 operational_state: OperationalState.ENABLED
41 let producerStatus2 = {
42 operational_state: OperationalState.DISABLED
45 let expectedProducer1 = {
46 ei_producer_id: 'producer1',
47 ei_producer_types: ['type1', 'type2'],
50 let expectedProducer2 = {
51 ei_producer_id: 'producer2',
52 ei_producer_types: ['type3', 'type4'],
57 eiServiceSpy = jasmine.createSpyObj('EIService', ['getProducerIds', 'getProducer', 'getProducerStatus']);
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()],
65 { provide: EIService, useValue: eiServiceSpy }
70 it('should create', () => {
71 dataSource = TestBed.inject(EIProducerDataSource);
72 expect(dataSource).toBeTruthy();
75 it('#loadProducers', () => {
76 dataSource.loadProducers();
77 const actualProducers: EIProducer[] = dataSource.eiProducers();
78 expect(actualProducers).toEqual([expectedProducer1, expectedProducer2]);
79 expect(dataSource.rowCount).toEqual(2);