X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-frontend%2Fsrc%2Fapp%2Fei-coordinator%2Fei-coordinator.component.spec.ts;h=7c50ca01ed9faeb2d28823e96789bc040710e912;hb=869354bad80ea5db92893ad3017eaf9c421c0731;hp=b9c2e0f2f23e2af335a34018012ca7be17ccc6a6;hpb=87ffca501cf3dca8dfb050b56f5c3bf9b742b651;p=portal%2Fnonrtric-controlpanel.git diff --git a/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.spec.ts b/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.spec.ts index b9c2e0f..7c50ca0 100644 --- a/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.spec.ts +++ b/webapp-frontend/src/app/ei-coordinator/ei-coordinator.component.spec.ts @@ -17,63 +17,124 @@ * limitations under the License. * ========================LICENSE_END=================================== */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations' -import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; -import { FormBuilder, ReactiveFormsModule } from '@angular/forms'; -import { MatIconModule, MatTableModule } from '@angular/material'; - -import { of } from 'rxjs'; +import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; +import { HarnessLoader } from '@angular/cdk/testing'; +import { MatButtonModule } from '@angular/material/button'; +import { MatButtonHarness } from '@angular/material/button/testing'; +import { MatIconModule } from '@angular/material/icon'; +import { MatTableModule } from '@angular/material/table'; +import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { EICoordinatorComponent } from './ei-coordinator.component'; -import { EIJobDataSource } from './ei-job.datasource'; -import { EIProducerDataSource } from './ei-producer.datasource'; import { UiService } from '../services/ui/ui.service'; +import { ProducersListComponent } from './producers-list/producers-list.component'; +import { JobsListComponent } from './jobs-list/jobs-list.component'; describe('EICoordinatorComponent', () => { let component: EICoordinatorComponent; let fixture: ComponentFixture; + let loader: HarnessLoader; - beforeEach(async(() => { - const jobDataSourceSpy = jasmine.createSpyObj('EIJobDataSource', [ 'connect', 'getJobs', 'disconnect' ]); - const producerDataSourceSpy = jasmine.createSpyObj('EIProducerDataSource', [ 'connect', 'loadTable', 'getProducers', 'disconnect' ]); - - jobDataSourceSpy.connect.and.returnValue(of([])); - jobDataSourceSpy.disconnect(); - producerDataSourceSpy.connect.and.returnValue(of([])); - producerDataSourceSpy.getProducers.and.returnValue(of([])); - producerDataSourceSpy.disconnect(); + beforeEach(async () => { - TestBed.configureTestingModule({ + await TestBed.configureTestingModule({ imports: [ + MatButtonModule, MatIconModule, MatTableModule, - BrowserAnimationsModule, - ReactiveFormsModule + BrowserAnimationsModule ], schemas: [ CUSTOM_ELEMENTS_SCHEMA ], declarations: [ - EICoordinatorComponent + EICoordinatorComponent, + JobsListStubComponent, + ProducerListStubComponent, ], providers: [ - { provide: EIJobDataSource, useValue: jobDataSourceSpy }, - { provide: EIProducerDataSource, useValue: producerDataSourceSpy }, - UiService, - FormBuilder, + UiService ] }) - .compileComponents(); - })); + .compileComponents(); - beforeEach(() => { fixture = TestBed.createComponent(EICoordinatorComponent); component = fixture.componentInstance; + fixture.detectChanges(); + loader = TestbedHarnessEnvironment.loader(fixture); }); it('should create', () => { expect(component).toBeTruthy(); }); + + describe('#content', () => { + it('should contain refresh button with correct icon', async () => { + let refreshButton = await loader.getHarness(MatButtonHarness.with({ selector: '#refreshButton' })); + expect(refreshButton).toBeTruthy(); + expect(await refreshButton.getText()).toEqual('refresh'); + }); + + it('should contain producers table', async () => { + const producersTableComponent = fixture.debugElement.nativeElement.querySelector('nrcp-producers-list'); + expect(producersTableComponent).toBeTruthy(); + }); + + it('should contain jobs table', async () => { + const jobsComponent = fixture.debugElement.nativeElement.querySelector('nrcp-jobs-list'); + expect(jobsComponent).toBeTruthy(); + }); + + it('should set correct dark mode from UIService', () => { + const uiService: UiService = TestBed.inject(UiService); + expect(component.darkMode).toBeTruthy(); + + uiService.darkModeState.next(false); + fixture.detectChanges(); + expect(component.darkMode).toBeFalsy(); + + }); + + it('should refresh tables', async () => { + let refreshButton = await loader.getHarness(MatButtonHarness.with({ selector: '#refreshButton' })); + spyOn(component.producersList, 'refresh'); + spyOn(component.jobComponent, 'refresh'); + await refreshButton.click(); + + expect(component.jobComponent.refresh).toHaveBeenCalled(); + expect(component.producersList.refresh).toHaveBeenCalled(); + }); + }); + + @Component({ + selector: 'nrcp-jobs-list', + template: '', + providers: [ + { + provide: JobsListComponent, + useClass: JobsListStubComponent + } + ] + }) + class JobsListStubComponent { + refresh() { } + } + + @Component({ + selector: 'nrcp-producers-list', + template: '', + providers: [ + { + provide: ProducersListComponent, + useClass: ProducerListStubComponent + } + ] + }) + class ProducerListStubComponent { + refresh() { } + } + });