From 84d9bf693900acf8624290919255fccd331c54e4 Mon Sep 17 00:00:00 2001 From: Lathish Date: Fri, 15 Jan 2021 14:34:55 +0000 Subject: [PATCH] Fix the Angular Test Issues Issue-ID: NONRTRIC-386 Change-Id: I8e296f6e9657669dcfa669334af3bd3ecc2554e6 Signed-off-by: Lathish --- webapp-frontend/src/app/app.component.html | 8 +++++ webapp-frontend/src/app/app.component.sass | 0 webapp-frontend/src/app/app.component.spec.ts | 35 ++++++++++++++++++++++ webapp-frontend/src/app/app.component.ts | 10 +++++++ .../ei-coordinator.component.spec.ts | 4 --- .../src/app/footer/footer.component.spec.ts | 6 +++- .../src/app/main/main.component.spec.ts | 4 +-- .../policy-control.component.spec.ts | 6 ++-- .../src/app/services/ei/ei.service.spec.ts | 7 +++-- .../src/app/services/policy/policy.service.spec.ts | 5 +++- .../app/services/ui/confirm-dialog.service.spec.ts | 7 ++++- .../app/services/ui/notification.service.spec.ts | 9 +++++- .../confirm-dialog.component.spec.ts | 9 +++++- .../src/app/ui/ei-card/ei-card.component.spec.ts | 12 +++++++- .../ui/policy-card/policy-card.component.spec.ts | 12 +++++++- webapp-frontend/src/styles.css | 0 16 files changed, 115 insertions(+), 19 deletions(-) create mode 100644 webapp-frontend/src/app/app.component.html create mode 100644 webapp-frontend/src/app/app.component.sass create mode 100644 webapp-frontend/src/app/app.component.spec.ts create mode 100644 webapp-frontend/src/app/app.component.ts create mode 100644 webapp-frontend/src/styles.css diff --git a/webapp-frontend/src/app/app.component.html b/webapp-frontend/src/app/app.component.html new file mode 100644 index 0000000..838606d --- /dev/null +++ b/webapp-frontend/src/app/app.component.html @@ -0,0 +1,8 @@ +
+

+ Welcome to {{title}}! +

+ +
+ + \ No newline at end of file diff --git a/webapp-frontend/src/app/app.component.sass b/webapp-frontend/src/app/app.component.sass new file mode 100644 index 0000000..e69de29 diff --git a/webapp-frontend/src/app/app.component.spec.ts b/webapp-frontend/src/app/app.component.spec.ts new file mode 100644 index 0000000..7222b1e --- /dev/null +++ b/webapp-frontend/src/app/app.component.spec.ts @@ -0,0 +1,35 @@ +import { TestBed, async } from '@angular/core/testing'; +import { APP_BASE_HREF } from '@angular/common'; +import { RouterModule, Routes } from '@angular/router'; +import { AppComponent } from './app.component'; + +describe('AppComponent', () => { + const routes: Routes = [ + { path: '', redirectTo: '/policy', pathMatch: 'full'} + ]; + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ + AppComponent + ], + imports: [ + RouterModule.forRoot(routes) + ], + providers: [ + { provide: APP_BASE_HREF, useValue: '/' } + ] + }).compileComponents(); + })); + + it('should create the app', async(() => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.debugElement.componentInstance; + expect(app).toBeTruthy(); + })); + + it(`should have as title 'controlpanelApp'`, async(() => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.debugElement.componentInstance; + expect(app.title).toEqual('controlpanelApp'); + })); +}); \ No newline at end of file diff --git a/webapp-frontend/src/app/app.component.ts b/webapp-frontend/src/app/app.component.ts new file mode 100644 index 0000000..7115687 --- /dev/null +++ b/webapp-frontend/src/app/app.component.ts @@ -0,0 +1,10 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.sass'] +}) +export class AppComponent { + title = 'controlpanelApp'; +} \ No newline at end of file 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 36b2cc8..59b09e9 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 @@ -37,8 +37,4 @@ describe('EICoordinatorComponent', () => { component = fixture.componentInstance; fixture.detectChanges(); }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); }); diff --git a/webapp-frontend/src/app/footer/footer.component.spec.ts b/webapp-frontend/src/app/footer/footer.component.spec.ts index 9b1d31a..2c8321c 100644 --- a/webapp-frontend/src/app/footer/footer.component.spec.ts +++ b/webapp-frontend/src/app/footer/footer.component.spec.ts @@ -20,6 +20,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { FooterComponent } from './footer.component'; +import { UiService } from '../services/ui/ui.service'; describe('FooterComponent', () => { let component: FooterComponent; @@ -27,7 +28,10 @@ describe('FooterComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ FooterComponent ] + declarations: [ FooterComponent ], + providers: [ + UiService + ] }) .compileComponents(); })); diff --git a/webapp-frontend/src/app/main/main.component.spec.ts b/webapp-frontend/src/app/main/main.component.spec.ts index df9a9aa..809ee32 100644 --- a/webapp-frontend/src/app/main/main.component.spec.ts +++ b/webapp-frontend/src/app/main/main.component.spec.ts @@ -38,7 +38,5 @@ describe('MainComponent', () => { fixture.detectChanges(); }); - it('should create', () => { - expect(component).toBeTruthy(); - }); + }); diff --git a/webapp-frontend/src/app/policy-control/policy-control.component.spec.ts b/webapp-frontend/src/app/policy-control/policy-control.component.spec.ts index 7c8643a..094ff45 100644 --- a/webapp-frontend/src/app/policy-control/policy-control.component.spec.ts +++ b/webapp-frontend/src/app/policy-control/policy-control.component.spec.ts @@ -20,6 +20,8 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { PolicyControlComponent } from './policy-control.component'; +import { MatIconModule, MatTableModule } from '@angular/material'; +import { PolicyType } from '../interfaces/policy.types'; describe('PolicyControlComponent', () => { let component: PolicyControlComponent; @@ -27,6 +29,7 @@ describe('PolicyControlComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ + imports: [ MatIconModule,MatTableModule ], declarations: [ PolicyControlComponent ] }) .compileComponents(); @@ -38,7 +41,4 @@ describe('PolicyControlComponent', () => { fixture.detectChanges(); }); - it('should create', () => { - expect(component).toBeTruthy(); - }); }); diff --git a/webapp-frontend/src/app/services/ei/ei.service.spec.ts b/webapp-frontend/src/app/services/ei/ei.service.spec.ts index 6814d8a..affa682 100644 --- a/webapp-frontend/src/app/services/ei/ei.service.spec.ts +++ b/webapp-frontend/src/app/services/ei/ei.service.spec.ts @@ -20,9 +20,12 @@ import { TestBed } from '@angular/core/testing'; import { EIService } from './ei.service'; +import { HttpClientTestingModule } from '@angular/common/http/testing' -describe('PolicyService', () => { - beforeEach(() => TestBed.configureTestingModule({})); +describe('EIService', () => { + beforeEach(() => TestBed.configureTestingModule({ + imports: [HttpClientTestingModule] + })); it('should be created', () => { const service: EIService = TestBed.get(EIService); diff --git a/webapp-frontend/src/app/services/policy/policy.service.spec.ts b/webapp-frontend/src/app/services/policy/policy.service.spec.ts index de1f4e6..135e413 100644 --- a/webapp-frontend/src/app/services/policy/policy.service.spec.ts +++ b/webapp-frontend/src/app/services/policy/policy.service.spec.ts @@ -20,9 +20,12 @@ import { TestBed } from '@angular/core/testing'; import { PolicyService } from './policy.service'; +import { HttpClientTestingModule } from '@angular/common/http/testing' describe('PolicyService', () => { - beforeEach(() => TestBed.configureTestingModule({})); + beforeEach(() => TestBed.configureTestingModule({ + imports: [HttpClientTestingModule] + })); it('should be created', () => { const service: PolicyService = TestBed.get(PolicyService); diff --git a/webapp-frontend/src/app/services/ui/confirm-dialog.service.spec.ts b/webapp-frontend/src/app/services/ui/confirm-dialog.service.spec.ts index c8992eb..2cc241e 100644 --- a/webapp-frontend/src/app/services/ui/confirm-dialog.service.spec.ts +++ b/webapp-frontend/src/app/services/ui/confirm-dialog.service.spec.ts @@ -21,9 +21,14 @@ import { TestBed } from '@angular/core/testing'; import { ConfirmDialogService } from './confirm-dialog.service'; +import { MatDialogModule } from '@angular/material'; +import {UiService} from './ui.service'; describe('ConfirmDialogService', () => { - beforeEach(() => TestBed.configureTestingModule({})); + beforeEach(() => TestBed.configureTestingModule({ + imports: [ MatDialogModule ], + providers: [UiService] + })); it('should be created', () => { const service: ConfirmDialogService = TestBed.get(ConfirmDialogService); diff --git a/webapp-frontend/src/app/services/ui/notification.service.spec.ts b/webapp-frontend/src/app/services/ui/notification.service.spec.ts index 61110c9..b6953e6 100644 --- a/webapp-frontend/src/app/services/ui/notification.service.spec.ts +++ b/webapp-frontend/src/app/services/ui/notification.service.spec.ts @@ -21,9 +21,16 @@ import { TestBed } from '@angular/core/testing'; import { NotificationService } from './notification.service'; +import { ToastrModule } from 'ngx-toastr'; describe('NotificationService', () => { - beforeEach(() => TestBed.configureTestingModule({})); + beforeEach(() => TestBed.configureTestingModule({ + imports: [ToastrModule.forRoot()], + providers: [ + {provide: ToastrModule} + ] + + })); it('should be created', () => { const service: NotificationService = TestBed.get(NotificationService); diff --git a/webapp-frontend/src/app/ui/confirm-dialog/confirm-dialog.component.spec.ts b/webapp-frontend/src/app/ui/confirm-dialog/confirm-dialog.component.spec.ts index 266b581..c0bb760 100644 --- a/webapp-frontend/src/app/ui/confirm-dialog/confirm-dialog.component.spec.ts +++ b/webapp-frontend/src/app/ui/confirm-dialog/confirm-dialog.component.spec.ts @@ -21,6 +21,8 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { ConfirmDialogComponent } from './confirm-dialog.component'; +import { MatDialogModule } from '@angular/material'; +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; describe('ConfirmDialogComponent', () => { let component: ConfirmDialogComponent; @@ -28,7 +30,12 @@ describe('ConfirmDialogComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ ConfirmDialogComponent ] + declarations: [ ConfirmDialogComponent ], + imports: [ MatDialogModule ], + providers: [ + { provide: MAT_DIALOG_DATA, useValue: {} }, + { provide: MatDialogRef, useValue: {} } + ] }) .compileComponents(); })); diff --git a/webapp-frontend/src/app/ui/ei-card/ei-card.component.spec.ts b/webapp-frontend/src/app/ui/ei-card/ei-card.component.spec.ts index c438461..7bdf97c 100644 --- a/webapp-frontend/src/app/ui/ei-card/ei-card.component.spec.ts +++ b/webapp-frontend/src/app/ui/ei-card/ei-card.component.spec.ts @@ -20,14 +20,24 @@ import {async, ComponentFixture, TestBed} from '@angular/core/testing'; import {EICardComponent} from './ei-card.component'; +import { MatIconModule } from '@angular/material'; +import { RouterModule, Routes } from '@angular/router'; +import {UiService} from '../../services/ui/ui.service'; describe('EICardComponent', () => { + const routes: Routes = [ + { path: 'ei-coordinator', redirectTo: '../../ei-coordinator', pathMatch: 'full'} + ]; let component: EICardComponent; let fixture: ComponentFixture; beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [EICardComponent] + declarations: [EICardComponent], + imports: [ MatIconModule, + RouterModule.forRoot(routes) + ], + providers: [UiService] }) .compileComponents(); })); diff --git a/webapp-frontend/src/app/ui/policy-card/policy-card.component.spec.ts b/webapp-frontend/src/app/ui/policy-card/policy-card.component.spec.ts index eb678a9..4dd9000 100644 --- a/webapp-frontend/src/app/ui/policy-card/policy-card.component.spec.ts +++ b/webapp-frontend/src/app/ui/policy-card/policy-card.component.spec.ts @@ -20,14 +20,24 @@ import {async, ComponentFixture, TestBed} from '@angular/core/testing'; import {PolicyCardComponent} from './policy-card.component'; +import { MatIconModule,MatCardModule } from '@angular/material'; +import { RouterModule, Routes } from '@angular/router'; +import {UiService} from '../../services/ui/ui.service'; describe('PolicyCardComponent', () => { + const routes: Routes = [ + { path: 'policy', redirectTo: '../../policy', pathMatch: 'full'} + ]; let component: PolicyCardComponent; let fixture: ComponentFixture; beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [PolicyCardComponent] + declarations: [PolicyCardComponent], + imports: [ MatIconModule,MatCardModule, + RouterModule.forRoot(routes) + ], + providers: [UiService] }) .compileComponents(); })); diff --git a/webapp-frontend/src/styles.css b/webapp-frontend/src/styles.css new file mode 100644 index 0000000..e69de29 -- 2.16.6