2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 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 { 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';
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';
37 describe('EICoordinatorComponent', () => {
38 let component: EICoordinatorComponent;
39 let fixture: ComponentFixture<EICoordinatorComponent>;
40 let loader: HarnessLoader;
42 beforeEach(async () => {
44 await TestBed.configureTestingModule({
49 BrowserAnimationsModule
52 CUSTOM_ELEMENTS_SCHEMA
55 EICoordinatorComponent,
56 MockComponent(JobsListComponent),
57 MockComponent(ProducersListComponent),
65 fixture = TestBed.createComponent(EICoordinatorComponent);
66 component = fixture.componentInstance;
68 fixture.detectChanges();
69 loader = TestbedHarnessEnvironment.loader(fixture);
72 it('should create', () => {
73 expect(component).toBeTruthy();
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');
83 it('should contain producers table', async () => {
84 const producersTableComponent = fixture.debugElement.nativeElement.querySelector('nrcp-producers-list');
85 expect(producersTableComponent).toBeTruthy();
88 it('should contain jobs table', async () => {
89 const jobsComponent = fixture.debugElement.nativeElement.querySelector('nrcp-jobs-list');
90 expect(jobsComponent).toBeTruthy();
93 it('should set correct dark mode from UIService', () => {
94 const uiService: UiService = TestBed.inject(UiService);
95 expect(component.darkMode).toBeTruthy();
97 uiService.darkModeState.next(false);
98 fixture.detectChanges();
99 expect(component.darkMode).toBeFalsy();
103 it('should refresh tables', async () => {
104 let refreshButton = await loader.getHarness(MatButtonHarness.with({ selector: '#refreshButton' }));
106 const jobsComponent: JobsListComponent = fixture.debugElement.query(By.directive(JobsListComponent)).componentInstance;
107 spyOn(jobsComponent, 'loadJobs');
108 spyOn(jobsComponent, 'clearFilter');
110 const prodsComponent: ProducersListComponent = fixture.debugElement.query(By.directive(ProducersListComponent)).componentInstance;
111 spyOn(prodsComponent, 'loadProducers');
112 spyOn(prodsComponent, 'clearFilter');
114 await refreshButton.click();
116 expect(jobsComponent.loadJobs).toHaveBeenCalled();
117 expect(jobsComponent.clearFilter).toHaveBeenCalled();
118 expect(prodsComponent.loadProducers).toHaveBeenCalled();
119 expect(prodsComponent.clearFilter).toHaveBeenCalled();