Fixing SO-Monitoring UI tests
[so.git] / so-monitoring / so-monitoring-ui / src / main / frontend / src / app / home / home.component.spec.ts
1 /**\r
2 ============LICENSE_START=======================================================\r
3  Copyright (C) 2018 Ericsson. All rights reserved.\r
4 ================================================================================\r
5 Licensed under the Apache License, Version 2.0 (the "License");\r
6 you may not use this file except in compliance with the License.\r
7 You may obtain a copy of the License at\r
8 \r
9     http://www.apache.org/licenses/LICENSE-2.0\r
10 \r
11 Unless required by applicable law or agreed to in writing, software\r
12 distributed under the License is distributed on an "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 See the License for the specific language governing permissions and\r
15  limitations under the License.\r
16 \r
17 SPDX-License-Identifier: Apache-2.0\r
18 ============LICENSE_END=========================================================\r
19 \r
20 @authors: ronan.kenny@ericsson.com, waqas.ikram@ericsson.com\r
21 */\r
22 \r
23 import { async, ComponentFixture, TestBed } from '@angular/core/testing';\r
24 \r
25 import { HomeComponent } from './home.component';\r
26 import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';\r
27 import { MatTableModule } from '@angular/material';\r
28 import { FormsModule } from '@angular/forms';\r
29 import { MatDatepickerModule } from '@angular/material/datepicker';\r
30 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';\r
31 import { HttpClientModule } from '@angular/common/http';\r
32 import { HttpClient } from '@angular/common/http';\r
33 import { inject } from '@angular/core/testing';\r
34 import { RouterModule } from '@angular/router';\r
35 import { APP_BASE_HREF } from '@angular/common';\r
36 import { ToastrNotificationService } from '../toastr-notification-service.service';\r
37 import { environment } from '../../environments/environment.prod';\r
38 \r
39 class StubbedToastrNotificationService extends ToastrNotificationService {\r
40   toastrSettings() {\r
41   }\r
42 }\r
43 \r
44 describe('HomeComponent', () => {\r
45   let component: HomeComponent;\r
46   let fixture: ComponentFixture<HomeComponent>;\r
47 \r
48   beforeEach(async(() => {\r
49     TestBed.configureTestingModule({\r
50       providers: [HomeComponent, HttpClient, HttpTestingController,\r
51         { provide: APP_BASE_HREF, useValue: '/' },\r
52         { provide: ToastrNotificationService, useClass: StubbedToastrNotificationService }],\r
53       imports: [MatTableModule, FormsModule, MatDatepickerModule, HttpClientModule, RouterModule.forRoot([])],\r
54       declarations: [HomeComponent],\r
55       schemas: [\r
56         CUSTOM_ELEMENTS_SCHEMA\r
57       ]\r
58     })\r
59       .compileComponents();\r
60   }));\r
61 \r
62   // Ensure creation of HomeComponent component\r
63   it('component should be created', inject([HttpTestingController, HomeComponent],\r
64     (httpClient: HttpTestingController, service: HomeComponent) => {\r
65       expect(service).toBeTruthy();\r
66     }));\r
67 \r
68   // Ensure all statistic variables are initialised to zero\r
69   it('ensure statistic variables are defaulted at zero', async(inject([HttpTestingController, HomeComponent],\r
70     (httpClient: HttpTestingController, service: HomeComponent) => {\r
71       expect(service.totalVal === 0 && service.completeVal === 0 &&\r
72         service.inProgressVal === 0 && service.failedVal === 0 &&\r
73         service.pendingVal === 0 && service.unlockedVal === 0 &&\r
74         service.percentageComplete === 0 && service.percentageFailed === 0 &&\r
75         service.percentageInProg === 0 && service.percentagePending === 0 &&\r
76         service.percentageUnlocked === 0).toBeTruthy();\r
77     })));\r
78 });\r