Commit 9b1bcb9c authored by Marcin Siodelski's avatar Marcin Siodelski Committed by Tomek Mrugalski

[#164] Make remaining tests pass

- provided mocking router
- initialize input values required by components
- do not use http client testing module
parent 0a73f084
......@@ -2,6 +2,22 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'
import { AppDaemonsStatusComponent } from './app-daemons-status.component'
class Daemon {}
class Details {
daemons: Daemon[]
}
class Machine {
id = 1
}
class App {
id = 1
machine = new Machine()
details = new Details()
}
describe('AppDaemonsStatusComponent', () => {
let component: AppDaemonsStatusComponent
let fixture: ComponentFixture<AppDaemonsStatusComponent>
......@@ -15,6 +31,7 @@ describe('AppDaemonsStatusComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(AppDaemonsStatusComponent)
component = fixture.componentInstance
component.app = new App()
fixture.detectChanges()
})
......
......@@ -7,30 +7,23 @@ import { SplitButtonModule } from 'primeng/splitbutton'
import { ProgressSpinnerModule } from 'primeng/progressspinner'
import { ToastModule } from 'primeng/toast'
import { GeneralService, UsersService, SettingsService, ServicesService } from './backend'
import { HttpClient, HttpHandler } from '@angular/common/http'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { MessageService } from 'primeng/api'
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
RouterTestingModule.withRoutes([{ path: 'apps/bind9/all', component: AppComponent }]),
TooltipModule,
MenubarModule,
SplitButtonModule,
ProgressSpinnerModule,
ToastModule,
HttpClientTestingModule,
],
declarations: [AppComponent],
providers: [
GeneralService,
HttpClient,
HttpHandler,
UsersService,
MessageService,
ServicesService,
SettingsService,
],
providers: [GeneralService, UsersService, MessageService, ServicesService, SettingsService],
}).compileComponents()
}))
......
......@@ -13,10 +13,11 @@ import { TabPanel, TabViewModule } from 'primeng/tabview'
import { HaStatusComponent } from '../ha-status/ha-status.component'
import { PanelModule } from 'primeng/panel'
import { MessageModule } from 'primeng/message'
import { ActivatedRoute, Router, RouterModule } from '@angular/router'
import { ActivatedRoute, Router, RouterModule, convertToParamMap } from '@angular/router'
import { ServicesService } from '../backend'
import { HttpClient, HttpHandler } from '@angular/common/http'
import { MessageService } from 'primeng/api'
import { RouterTestingModule } from '@angular/router/testing'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { of } from 'rxjs'
describe('AppsPageComponent', () => {
......@@ -25,23 +26,9 @@ describe('AppsPageComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
providers: [
ServicesService,
HttpClient,
HttpHandler,
MessageService,
{
provide: ActivatedRoute,
useValue: {
paramMap: of({}),
},
},
{
provide: Router,
useValue: {},
},
],
providers: [ServicesService, MessageService],
imports: [
HttpClientTestingModule,
TabMenuModule,
MenuModule,
FormsModule,
......@@ -51,6 +38,7 @@ describe('AppsPageComponent', () => {
PanelModule,
MessageModule,
RouterModule,
RouterTestingModule.withRoutes([{ path: 'apps/:appType/all', component: AppsPageComponent }]),
],
declarations: [
AppsPageComponent,
......@@ -65,6 +53,7 @@ describe('AppsPageComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(AppsPageComponent)
component = fixture.componentInstance
component.appType = 'bind9'
fixture.detectChanges()
})
......
import { Component, OnInit } from '@angular/core'
import { ActivatedRoute, ParamMap, Router, NavigationEnd } from '@angular/router'
import { ActivatedRoute, Router, NavigationEnd } from '@angular/router'
import { BehaviorSubject } from 'rxjs'
import { MessageService, MenuItem } from 'primeng/api'
......
......@@ -2,18 +2,16 @@ import { TestBed, async, inject } from '@angular/core/testing'
import { AuthGuard } from './auth.guard'
import { RouterModule, Router } from '@angular/router'
import { HttpClient, HttpHandler } from '@angular/common/http'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { UsersService } from './backend'
import { MessageService } from 'primeng/api'
describe('AuthGuard', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [RouterModule],
imports: [RouterModule, HttpClientTestingModule],
providers: [
AuthGuard,
HttpClient,
HttpHandler,
UsersService,
MessageService,
{
......
import { TestBed } from '@angular/core/testing'
import { AuthService } from './auth.service'
import { HttpClient, HttpHandler } from '@angular/common/http'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { UsersService } from './backend'
import { RouterModule, Router } from '@angular/router'
import { MessageService } from 'primeng/api'
......@@ -10,8 +10,6 @@ describe('AuthService', () => {
beforeEach(() =>
TestBed.configureTestingModule({
providers: [
HttpClient,
HttpHandler,
UsersService,
{
provide: Router,
......@@ -19,6 +17,7 @@ describe('AuthService', () => {
},
MessageService,
],
imports: [HttpClientTestingModule],
})
)
......
......@@ -2,10 +2,34 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'
import { Bind9AppTabComponent } from './bind9-app-tab.component'
import { RouterLink, Router, RouterModule, ActivatedRoute } from '@angular/router'
import { RouterTestingModule } from '@angular/router/testing'
import { TooltipModule } from 'primeng/tooltip'
import { TabViewModule } from 'primeng/tabview'
import { LocaltimePipe } from '../localtime.pipe'
import { LocationStrategy } from '@angular/common'
import { MockLocationStrategy } from '@angular/common/testing'
import { of } from 'rxjs'
class Daemon {
name = 'bind9'
}
class Details {
daemon: Daemon = new Daemon()
}
class Machine {
id = 1
}
class App {
id = 1
machine = new Machine()
details = new Details()
}
class AppTab {
app: App = new App()
}
describe('Bind9AppTabComponent', () => {
let component: Bind9AppTabComponent
......@@ -13,25 +37,18 @@ describe('Bind9AppTabComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [TooltipModule, TabViewModule, RouterModule],
imports: [TooltipModule, TabViewModule, RouterModule, RouterTestingModule],
declarations: [Bind9AppTabComponent, LocaltimePipe],
providers: [
LocationStrategy,
{
provide: Router,
useValue: {},
},
{
provide: ActivatedRoute,
useValue: {},
},
],
providers: [MockLocationStrategy],
}).compileComponents()
}))
beforeEach(() => {
fixture = TestBed.createComponent(Bind9AppTabComponent)
component = fixture.componentInstance
const appTab = new AppTab()
component.refreshedAppTab = of(appTab)
component.appTab = appTab
fixture.detectChanges()
})
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing'
import { BreadcrumbsComponent } from './breadcrumbs.component'
import { RouterTestingModule } from '@angular/router/testing'
describe('BreadcrumbsComponent', () => {
let component: BreadcrumbsComponent
......@@ -8,6 +8,7 @@ describe('BreadcrumbsComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule],
declarations: [BreadcrumbsComponent],
}).compileComponents()
}))
......@@ -15,6 +16,7 @@ describe('BreadcrumbsComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(BreadcrumbsComponent)
component = fixture.componentInstance
component.items = []
fixture.detectChanges()
})
......
......@@ -5,7 +5,7 @@ import { PanelModule } from 'primeng/panel'
import { ButtonModule } from 'primeng/button'
import { Router, RouterModule, ActivatedRoute } from '@angular/router'
import { ServicesService, DHCPService, SettingsService, UsersService } from '../backend'
import { HttpClient, HttpHandler } from '@angular/common/http'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { MessageService } from 'primeng/api'
import { LocationStrategy } from '@angular/common'
......@@ -15,12 +15,10 @@ describe('DashboardComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [PanelModule, ButtonModule, RouterModule],
imports: [PanelModule, ButtonModule, RouterModule, HttpClientTestingModule],
declarations: [DashboardComponent],
providers: [
ServicesService,
HttpClient,
HttpHandler,
LocationStrategy,
DHCPService,
MessageService,
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing'
import { EntityLinkComponent } from './entity-link.component'
import { RouterTestingModule } from '@angular/router/testing'
describe('EntityLinkComponent', () => {
let component: EntityLinkComponent
......@@ -8,6 +8,7 @@ describe('EntityLinkComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule],
declarations: [EntityLinkComponent],
}).compileComponents()
}))
......
import { HttpClient, HttpHandler } from '@angular/common/http'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { async, ComponentFixture, TestBed } from '@angular/core/testing'
import { ActivatedRoute, Router } from '@angular/router'
import { MessageService } from 'primeng/api'
......@@ -14,8 +14,6 @@ describe('EventsPanelComponent', () => {
TestBed.configureTestingModule({
providers: [
EventsService,
HttpClient,
HttpHandler,
UsersService,
ServicesService,
MessageService,
......@@ -28,6 +26,7 @@ describe('EventsPanelComponent', () => {
useValue: {},
},
],
imports: [HttpClientTestingModule],
declarations: [EventsPanelComponent],
}).compileComponents()
}))
......
......@@ -2,7 +2,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'
import { GlobalSearchComponent } from './global-search.component'
import { SearchService } from '../backend/api/api'
import { HttpClient, HttpHandler } from '@angular/common/http'
import { HttpClientTestingModule } from '@angular/common/http/testing'
describe('GlobalSearchComponent', () => {
let component: GlobalSearchComponent
......@@ -11,7 +11,8 @@ describe('GlobalSearchComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [GlobalSearchComponent],
providers: [SearchService, HttpClient, HttpHandler],
providers: [SearchService],
imports: [HttpClientTestingModule],
}).compileComponents()
}))
......
......@@ -2,6 +2,8 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'
import { HaStatusPanelComponent } from './ha-status-panel.component'
import { of } from 'rxjs'
describe('HaStatusPanelComponent', () => {
let component: HaStatusPanelComponent
let fixture: ComponentFixture<HaStatusPanelComponent>
......@@ -15,6 +17,7 @@ describe('HaStatusPanelComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(HaStatusPanelComponent)
component = fixture.componentInstance
component.serverStatus = of({ state: 'unavailable' })
fixture.detectChanges()
})
......
......@@ -7,7 +7,7 @@ import { MessageModule } from 'primeng/message'
import { LocaltimePipe } from '../localtime.pipe'
import { RouterModule } from '@angular/router'
import { ServicesService } from '../backend'
import { HttpClient, HttpHandler } from '@angular/common/http'
import { HttpClientTestingModule } from '@angular/common/http/testing'
describe('HaStatusComponent', () => {
let component: HaStatusComponent
......@@ -15,15 +15,16 @@ describe('HaStatusComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [PanelModule, TooltipModule, MessageModule, RouterModule],
imports: [PanelModule, TooltipModule, MessageModule, RouterModule, HttpClientTestingModule],
declarations: [HaStatusComponent, LocaltimePipe],
providers: [ServicesService, HttpClient, HttpHandler],
providers: [ServicesService],
}).compileComponents()
}))
beforeEach(() => {
fixture = TestBed.createComponent(HaStatusComponent)
component = fixture.componentInstance
component.appId = 4
fixture.detectChanges()
})
......
......@@ -4,8 +4,8 @@ import { HostsPageComponent } from './hosts-page.component'
import { FormsModule } from '@angular/forms'
import { TableModule } from 'primeng/table'
import { DHCPService } from '../backend'
import { HttpClient, HttpHandler } from '@angular/common/http'
import { ActivatedRoute, Router } from '@angular/router'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { ActivatedRoute, Router, convertToParamMap } from '@angular/router'
import { of } from 'rxjs'
class MockParamMap {
......@@ -22,13 +22,12 @@ describe('HostsPageComponent', () => {
TestBed.configureTestingModule({
providers: [
DHCPService,
HttpClient,
HttpHandler,
{
provide: ActivatedRoute,
useValue: {
snapshot: { queryParamMap: new MockParamMap() },
queryParamMap: of(new MockParamMap()),
paramMap: of(convertToParamMap({ id: 1 })),
},
},
{
......@@ -36,7 +35,7 @@ describe('HostsPageComponent', () => {
useValue: {},
},
],
imports: [FormsModule, TableModule],
imports: [FormsModule, TableModule, HttpClientTestingModule],
declarations: [HostsPageComponent],
}).compileComponents()
}))
......
......@@ -2,16 +2,36 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'
import { KeaAppTabComponent } from './kea-app-tab.component'
import { RouterModule, Router, ActivatedRoute } from '@angular/router'
import { RouterTestingModule } from '@angular/router/testing'
import { HaStatusComponent } from '../ha-status/ha-status.component'
import { TableModule } from 'primeng/table'
import { TabViewModule } from 'primeng/tabview'
import { LocaltimePipe } from '../localtime.pipe'
import { DHCPService, ServicesService } from '../backend'
import { HttpClient, HttpHandler } from '@angular/common/http'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { PanelModule } from 'primeng/panel'
import { TooltipModule } from 'primeng/tooltip'
import { MessageModule } from 'primeng/message'
import { LocationStrategy } from '@angular/common'
import { MockLocationStrategy } from '@angular/common/testing'
import { of } from 'rxjs'
class Details {
daemons: any = []
}
class Machine {
id = 1
}
class App {
id = 1
machine = new Machine()
details = new Details()
}
class AppTab {
app = new App()
}
describe('KeaAppTabComponent', () => {
let component: KeaAppTabComponent
......@@ -19,22 +39,17 @@ describe('KeaAppTabComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
providers: [
DHCPService,
HttpClient,
HttpHandler,
ServicesService,
LocationStrategy,
{
provide: ActivatedRoute,
useValue: {},
},
{
provide: Router,
useValue: {},
},
providers: [DHCPService, ServicesService, MockLocationStrategy],
imports: [
RouterModule,
RouterTestingModule,
TableModule,
TabViewModule,
PanelModule,
TooltipModule,
MessageModule,
HttpClientTestingModule,
],
imports: [RouterModule, TableModule, TabViewModule, PanelModule, TooltipModule, MessageModule],
declarations: [KeaAppTabComponent, HaStatusComponent, LocaltimePipe],
}).compileComponents()
}))
......@@ -42,6 +57,9 @@ describe('KeaAppTabComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(KeaAppTabComponent)
component = fixture.componentInstance
const appTab = new AppTab()
component.refreshedAppTab = of(appTab)
component.appTab = appTab
fixture.detectChanges()
})
......
import { HttpClient, HttpHandler } from '@angular/common/http'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { async, ComponentFixture, TestBed } from '@angular/core/testing'
import { ActivatedRoute } from '@angular/router'
import { ActivatedRoute, convertToParamMap } from '@angular/router'
import { ServicesService } from '../backend'
import { LogViewPageComponent } from './log-view-page.component'
import { of } from 'rxjs'
......@@ -13,15 +13,14 @@ describe('LogViewPageComponent', () => {
TestBed.configureTestingModule({
providers: [
ServicesService,
HttpClient,
HttpHandler,
{
provide: ActivatedRoute,
useValue: {
paramMap: of({}),
paramMap: of(convertToParamMap({})),
},
},
],
imports: [HttpClientTestingModule],
declarations: [LogViewPageComponent],
}).compileComponents()
}))
......
......@@ -3,7 +3,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'
import { LoginScreenComponent } from './login-screen.component'
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { GeneralService, UsersService } from '../backend'
import { HttpClient, HttpHandler } from '@angular/common/http'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { RouterModule, Router, ActivatedRoute } from '@angular/router'
import { MessageService } from 'primeng/api'
......@@ -13,12 +13,10 @@ describe('LoginScreenComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ReactiveFormsModule, FormsModule, RouterModule],
imports: [ReactiveFormsModule, FormsModule, RouterModule, HttpClientTestingModule],
declarations: [LoginScreenComponent],
providers: [
GeneralService,
HttpClient,
HttpHandler,
UsersService,
MessageService,
{
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing'
import { MachinesPageComponent } from './machines-page.component'
import { ActivatedRoute, Router } from '@angular/router'
import { ActivatedRoute, Router, convertToParamMap } from '@angular/router'
import { RouterTestingModule } from '@angular/router/testing'
import { ServicesService, UsersService } from '../backend'
import { HttpClient, HttpHandler } from '@angular/common/http'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { MessageService } from 'primeng/api'
import { of } from 'rxjs'
......@@ -13,22 +14,10 @@ describe('MachinesPageComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
providers: [
MessageService,
{
provide: ActivatedRoute,
useValue: {
paramMap: of({}),
},
},
{
provide: Router,
useValue: {},
},
ServicesService,
HttpClient,
HttpHandler,
UsersService,
providers: [MessageService, ServicesService, UsersService],
imports: [
HttpClientTestingModule,
RouterTestingModule.withRoutes([{ path: 'machines/all', component: MachinesPageComponent }]),
],
declarations: [MachinesPageComponent],
}).compileComponents()
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing'
import { PasswordChangePageComponent } from './password-change-page.component'
import { HttpClient, HttpHandler } from '@angular/common/http'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { Router } from '@angular/router'
import { FormBuilder } from '@angular/forms'
import { UsersService } from '../backend'
......@@ -16,14 +16,13 @@ describe('PasswordChangePageComponent', () => {
providers: [
FormBuilder,
UsersService,
HttpClient,