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=38e3fa53c7c8d9d635e4bd8ce1747fdf4aed2afa;hb=18a21c8796772fab295df182763f59700333e9ab;hp=4767de6db974e47d2d450985c02fdef10d63db90;hpb=ad70d4114bbfc5dbf20fd1a8151095d89610c759;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 4767de6..38e3fa5 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,60 +17,107 @@ * 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 { 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 { UiService } from '@services/ui/ui.service'; +import { ProducersListComponent } from '@ei-coordinator/producers-list/producers-list.component'; +import { JobsListComponent } from '@ei-coordinator/jobs-list/jobs-list.component'; +import { MockComponent } from 'ng-mocks'; +import { By } from '@angular/platform-browser'; describe('EICoordinatorComponent', () => { let component: EICoordinatorComponent; let fixture: ComponentFixture; + let loader: HarnessLoader; - beforeEach(async(() => { - const jobDataSourceSpy = jasmine.createSpyObj('EIJobDataSource', [ 'loadJobs', 'eiJobs' ]); - const producerDataSourceSpy = jasmine.createSpyObj('EIProducerDataSource', [ 'loadProducers', 'eiProducers' ]); + beforeEach(async () => { - jobDataSourceSpy.eiJobs.and.returnValue([]); - - producerDataSourceSpy.eiProducers.and.returnValue([]); - - TestBed.configureTestingModule({ + await TestBed.configureTestingModule({ imports: [ + MatButtonModule, MatIconModule, MatTableModule, - BrowserAnimationsModule, - ReactiveFormsModule + BrowserAnimationsModule ], schemas: [ CUSTOM_ELEMENTS_SCHEMA ], declarations: [ - EICoordinatorComponent + EICoordinatorComponent, + MockComponent(JobsListComponent), + MockComponent(ProducersListComponent), ], 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' })); + + const jobsComponent: JobsListComponent = fixture.debugElement.query(By.directive(JobsListComponent)).componentInstance; + spyOn(jobsComponent, 'refreshDataClick'); + spyOn(jobsComponent, 'clearFilter'); + + const prodsComponent: ProducersListComponent = fixture.debugElement.query(By.directive(ProducersListComponent)).componentInstance; + spyOn(prodsComponent, 'loadProducers'); + spyOn(prodsComponent, 'clearFilter'); + + await refreshButton.click(); + + expect(jobsComponent.refreshDataClick).toHaveBeenCalled(); + expect(jobsComponent.clearFilter).toHaveBeenCalled(); + expect(prodsComponent.loadProducers).toHaveBeenCalled(); + expect(prodsComponent.clearFilter).toHaveBeenCalled(); + + }); + }); });