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 { EIJobDataSource } from './ei-job.datasource';
24 import { EIService } from '../services/ei/ei.service';
25 import { NotificationService } from '../services/ui/notification.service';
26 import { ToastrModule } from 'ngx-toastr';
27 import { EIJob } from '../interfaces/ei.types';
29 describe('EIJobDataSource', () => {
30 let dataSource: EIJobDataSource;
31 let eiServiceSpy: any;
33 let job = { ei_job_identity: '1', ei_job_data: 'data', ei_type_identity: 'Type ID 1', target_uri: 'hhtp://url', owner: 'owner'};
36 eiServiceSpy = jasmine.createSpyObj('EIService', ['getProducerIds', 'getJobsForProducer']);
38 eiServiceSpy.getProducerIds.and.returnValue(of([ 'producer1', 'producer2']));
39 eiServiceSpy.getJobsForProducer.and.returnValue(of([job]));
40 TestBed.configureTestingModule({
41 imports: [ToastrModule.forRoot()],
43 { provide: EIService, useValue: eiServiceSpy },
49 it('should create', () => {
50 dataSource = TestBed.get(EIJobDataSource);
51 expect(dataSource).toBeTruthy();
54 it('#getJobs', () => {
56 const jobsSubject: BehaviorSubject<EIJob[]> = dataSource.eiJobsSubject;
57 const value = jobsSubject.getValue();
58 expect(value).toEqual([ job, job ]);
59 expect(dataSource.rowCount).toEqual(2);