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 { EIJobDataSource } from './ei-job.datasource';
24 import { EIService } from '../services/ei/ei.service';
25 import { ToastrModule } from 'ngx-toastr';
26 import { EIJob } from '../interfaces/ei.types';
28 describe('EIJobDataSource', () => {
29 let dataSource: EIJobDataSource;
30 let eiServiceSpy: any;
32 const job = { ei_job_identity: '1', ei_job_data: 'data', ei_type_identity: 'Type ID 1', target_uri: 'hhtp://url', owner: 'owner' };
35 eiServiceSpy = jasmine.createSpyObj('EIService', ['getProducerIds', 'getJobsForProducer']);
37 eiServiceSpy.getProducerIds.and.returnValue(of(['producer1', 'producer2']));
38 eiServiceSpy.getJobsForProducer.and.returnValue(of([job]));
39 TestBed.configureTestingModule({
40 imports: [ToastrModule.forRoot()],
42 { provide: EIService, useValue: eiServiceSpy }
47 it('should create', () => {
48 dataSource = TestBed.inject(EIJobDataSource);
49 expect(dataSource).toBeTruthy();
52 it('#getJobs', () => {
53 dataSource.loadJobs();
54 const actualJobs: EIJob[] = dataSource.eiJobs();
55 expect(actualJobs).toEqual([job, job]);
56 expect(dataSource.rowCount).toEqual(2);