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 { Component, 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 './producers-list/producers-list.component';
33 import { JobsListComponent } from './jobs-list/jobs-list.component';
35 describe('EICoordinatorComponent', () => {
36 let component: EICoordinatorComponent;
37 let fixture: ComponentFixture<EICoordinatorComponent>;
38 let loader: HarnessLoader;
40 beforeEach(async () => {
42 await TestBed.configureTestingModule({
47 BrowserAnimationsModule
50 CUSTOM_ELEMENTS_SCHEMA
53 EICoordinatorComponent,
54 JobsListStubComponent,
55 ProducerListStubComponent,
63 fixture = TestBed.createComponent(EICoordinatorComponent);
64 component = fixture.componentInstance;
66 fixture.detectChanges();
67 loader = TestbedHarnessEnvironment.loader(fixture);
70 it('should create', () => {
71 expect(component).toBeTruthy();
74 describe('#content', () => {
75 it('should contain refresh button with correct icon', async () => {
76 let refreshButton = await loader.getHarness(MatButtonHarness.with({ selector: '#refreshButton' }));
77 expect(refreshButton).toBeTruthy();
78 expect(await refreshButton.getText()).toEqual('refresh');
81 it('should contain producers table', async () => {
82 const producersTableComponent = fixture.debugElement.nativeElement.querySelector('nrcp-producers-list');
83 expect(producersTableComponent).toBeTruthy();
86 it('should contain jobs table', async () => {
87 const jobsComponent = fixture.debugElement.nativeElement.querySelector('nrcp-jobs-list');
88 expect(jobsComponent).toBeTruthy();
91 it('should set correct dark mode from UIService', () => {
92 const uiService: UiService = TestBed.inject(UiService);
93 expect(component.darkMode).toBeTruthy();
95 uiService.darkModeState.next(false);
96 fixture.detectChanges();
97 expect(component.darkMode).toBeFalsy();
101 it('should refresh tables', async () => {
102 let refreshButton = await loader.getHarness(MatButtonHarness.with({ selector: '#refreshButton' }));
103 spyOn(component.producersList, 'loadProducers');
104 spyOn(component.jobComponent, 'loadJobs');
105 await refreshButton.click();
107 expect(component.jobComponent.loadJobs).toHaveBeenCalled();
108 expect(component.producersList.loadProducers).toHaveBeenCalled();
113 selector: 'nrcp-jobs-list',
117 provide: JobsListComponent,
118 useClass: JobsListStubComponent
122 class JobsListStubComponent {
127 selector: 'nrcp-producers-list',
131 provide: ProducersListComponent,
132 useClass: ProducerListStubComponent
136 class ProducerListStubComponent {