a891d5f45d028d0f74b5e111a34fd506dafc848b
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / ei-coordinator / ei-job.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 { of } from 'rxjs';
22
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';
27
28 describe('EIJobDataSource', () => {
29     let dataSource: EIJobDataSource;
30     let eiServiceSpy: any;
31
32     const job = { ei_job_identity: '1', ei_job_data: 'data', ei_type_identity: 'Type ID 1',  target_uri: 'hhtp://url', owner: 'owner'};
33
34     beforeEach(() => {
35         eiServiceSpy = jasmine.createSpyObj('EIService', ['getProducerIds', 'getJobsForProducer']);
36
37         eiServiceSpy.getProducerIds.and.returnValue(of([ 'producer1', 'producer2']));
38         eiServiceSpy.getJobsForProducer.and.returnValue(of([job]));
39         TestBed.configureTestingModule({
40             imports: [ToastrModule.forRoot()],
41             providers: [
42                 { provide: EIService, useValue: eiServiceSpy }
43             ]
44         });
45     });
46
47     it('should create', () => {
48         dataSource = TestBed.get(EIJobDataSource);
49         expect(dataSource).toBeTruthy();
50     });
51
52     it('#getJobs', () => {
53         dataSource.loadJobs();
54         const actualJobs: EIJob[] = dataSource.eiJobs();
55         expect(actualJobs).toEqual([ job, job ]);
56         expect(dataSource.rowCount).toEqual(2);
57     });
58 });