Polling mechanism to get jobs
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / ei-coordinator / ei-coordinator.component.spec.ts
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 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 { ComponentFixture, TestBed } from '@angular/core/testing';
21 import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
22 import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
23 import { HarnessLoader } from '@angular/cdk/testing';
24 import { MatButtonModule } from '@angular/material/button';
25 import { MatButtonHarness } from '@angular/material/button/testing';
26 import { MatIconModule } from '@angular/material/icon';
27 import { MatTableModule } from '@angular/material/table';
28 import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
29
30 import { EICoordinatorComponent } from './ei-coordinator.component';
31 import { UiService } from '@services/ui/ui.service';
32 import { ProducersListComponent } from '@ei-coordinator/producers-list/producers-list.component';
33 import { JobsListComponent } from '@ei-coordinator/jobs-list/jobs-list.component';
34 import { MockComponent } from 'ng-mocks';
35 import { By } from '@angular/platform-browser';
36
37 describe('EICoordinatorComponent', () => {
38   let component: EICoordinatorComponent;
39   let fixture: ComponentFixture<EICoordinatorComponent>;
40   let loader: HarnessLoader;
41
42   beforeEach(async () => {
43
44     await TestBed.configureTestingModule({
45       imports: [
46         MatButtonModule,
47         MatIconModule,
48         MatTableModule,
49         BrowserAnimationsModule
50       ],
51       schemas: [
52         CUSTOM_ELEMENTS_SCHEMA
53       ],
54       declarations: [
55         EICoordinatorComponent,
56         MockComponent(JobsListComponent),
57         MockComponent(ProducersListComponent),
58       ],
59       providers: [
60         UiService
61       ]
62     })
63       .compileComponents();
64
65     fixture = TestBed.createComponent(EICoordinatorComponent);
66     component = fixture.componentInstance;
67
68     fixture.detectChanges();
69     loader = TestbedHarnessEnvironment.loader(fixture);
70   });
71
72   it('should create', () => {
73     expect(component).toBeTruthy();
74   });
75
76   describe('#content', () => {
77     it('should contain refresh button with correct icon', async () => {
78       let refreshButton = await loader.getHarness(MatButtonHarness.with({ selector: '#refreshButton' }));
79       expect(refreshButton).toBeTruthy();
80       expect(await refreshButton.getText()).toEqual('refresh');
81     });
82
83     it('should contain producers table', async () => {
84       const producersTableComponent = fixture.debugElement.nativeElement.querySelector('nrcp-producers-list');
85       expect(producersTableComponent).toBeTruthy();
86     });
87
88     it('should contain jobs table', async () => {
89       const jobsComponent = fixture.debugElement.nativeElement.querySelector('nrcp-jobs-list');
90       expect(jobsComponent).toBeTruthy();
91     });
92
93     it('should set correct dark mode from UIService', () => {
94       const uiService: UiService = TestBed.inject(UiService);
95       expect(component.darkMode).toBeTruthy();
96
97       uiService.darkModeState.next(false);
98       fixture.detectChanges();
99       expect(component.darkMode).toBeFalsy();
100
101     });
102
103     it('should refresh tables', async () => {
104       let refreshButton = await loader.getHarness(MatButtonHarness.with({ selector: '#refreshButton' }));
105
106       const jobsComponent: JobsListComponent = fixture.debugElement.query(By.directive(JobsListComponent)).componentInstance;
107       spyOn(jobsComponent, 'refreshDataClick');
108       spyOn(jobsComponent, 'clearFilter');
109
110       const prodsComponent: ProducersListComponent = fixture.debugElement.query(By.directive(ProducersListComponent)).componentInstance;
111       spyOn(prodsComponent, 'loadProducers');
112       spyOn(prodsComponent, 'clearFilter');
113
114       await refreshButton.click();
115
116       expect(jobsComponent.refreshDataClick).toHaveBeenCalled();
117       expect(jobsComponent.clearFilter).toHaveBeenCalled();
118       expect(prodsComponent.loadProducers).toHaveBeenCalled();
119       expect(prodsComponent.clearFilter).toHaveBeenCalled();
120
121     });
122   });
123 });