SI-001 Unitests for basic components added, index to modules classes renamed
Signed-off-by: Dimitrios Chalepakis <dimitrios.chalepakis@pta.de>
diff --git a/projects/grid-failure-information-app/src/app/app-config.service.spec.ts b/projects/grid-failure-information-app/src/app/app-config.service.spec.ts
index 8dd4c89..088f839 100644
--- a/projects/grid-failure-information-app/src/app/app-config.service.spec.ts
+++ b/projects/grid-failure-information-app/src/app/app-config.service.spec.ts
@@ -12,6 +12,7 @@
********************************************************************************/
import { async } from '@angular/core/testing';
import { ConfigService } from '@grid-failure-information-app/app/app-config.service';
+import { of } from 'rxjs/observable/of';
describe('ConfigService', () => {
let component: ConfigService;
@@ -19,14 +20,44 @@
let baseHref: any;
beforeEach(async(() => {
- http = {} as any;
+ http = {
+ get: () =>
+ of({
+ json: () => of({ env: 'env_json' }),
+ }),
+ } as any;
}));
beforeEach(() => {
+ baseHref = '/test';
component = new ConfigService(http, baseHref);
});
it('should create', () => {
expect(component).toBeTruthy();
});
+
+ it('should get env', () => {
+ const keyValue = 'test';
+ (component as any).env = { key: keyValue };
+ const key: any = 'key';
+ const res = component.getEnv(key);
+ expect(res).toBe(keyValue);
+ });
+
+ it('should get config key', () => {
+ const keyValue = 'test';
+ (component as any).config = { key: keyValue };
+ const key: any = 'key';
+ const res = component.get(key);
+ expect(res).toBe(keyValue);
+ });
+
+ it('should load the config file', () => {
+ const keyValue = 'test';
+ (component as any).config = { key: keyValue };
+ (component as any).env = { key: keyValue };
+ component.load();
+ expect((component as any).config).toBeDefined();
+ });
});
diff --git a/projects/grid-failure-information-app/src/app/app-config.service.ts b/projects/grid-failure-information-app/src/app/app-config.service.ts
index b2f133d..1fdbf26 100644
--- a/projects/grid-failure-information-app/src/app/app-config.service.ts
+++ b/projects/grid-failure-information-app/src/app/app-config.service.ts
@@ -1,4 +1,4 @@
- /********************************************************************************
+/********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
@@ -10,29 +10,28 @@
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
-import { Injectable, Inject } from '@angular/core';
+import { APP_BASE_HREF } from '@angular/common';
+import { Inject, Injectable } from '@angular/core';
+import { Headers, Http } from '@angular/http';
import { Observable } from 'rxjs';
-import { Http, Headers, RequestOptions } from '@angular/http';
-import { APP_BASE_HREF } from '@angular/common';
@Injectable()
export class ConfigService {
private config: Object;
- private env: Object;
+ private env: Object;
- constructor(private http: Http,
- @Inject(APP_BASE_HREF) private baseHref: string) {}
+ constructor(private http: Http, @Inject(APP_BASE_HREF) private baseHref: string) {}
/**
* Loads the environment config file first. Reads the environment variable from the file
* and based on that loads the appropriate configuration file - development or production
*/
- load() {
+ load() {
return new Promise((resolve, reject) => {
const headers = new Headers({
Accept: 'application/json',
'Content-Type': 'application/json',
- DataType: 'application/json'
+ DataType: 'application/json',
});
this.http
diff --git a/projects/grid-failure-information-app/src/app/app.component.spec.ts b/projects/grid-failure-information-app/src/app/app.component.spec.ts
index 1c7d463..cde624b 100644
--- a/projects/grid-failure-information-app/src/app/app.component.spec.ts
+++ b/projects/grid-failure-information-app/src/app/app.component.spec.ts
@@ -12,13 +12,13 @@
********************************************************************************/
import { async } from '@angular/core/testing';
-import { AppComponent } from './app.component';
import { User } from '@grid-failure-information-app/shared/models/user';
-import { ActivatedRoute } from '@angular/router';
-import { Observable } from 'rxjs';
+import { of } from 'rxjs';
+import { AppComponent } from '@grid-failure-information-app/app/app.component';
class FakeRouter {
- public events = new Observable();
+ public events: any = of({ url: '/overview' });
+
navigate(commands: any[]) {
return commands[0];
}
@@ -36,10 +36,10 @@
let component: AppComponent;
const fakeRouter: any = new FakeRouter();
const sandbox = new FakeSandbox();
- const fakeRoute = new ActivatedRoute();
+ const fakeActivatedRoute: any = { params: of(1) };
beforeEach(() => {
- component = new AppComponent(fakeRouter, sandbox as any, fakeRoute);
+ component = new AppComponent(fakeRouter, sandbox as any, fakeActivatedRoute);
});
it('should create the app', async(() => {
@@ -91,4 +91,36 @@
const param1 = inkognito._getParametersFromUrl();
expect(param1).toBe(null);
});
+
+ it('should set up componet on ngOnInit call', () => {
+ const spy = spyOn(sandbox, 'setupLanguage');
+ const spy2 = spyOn(component as any, '_extractTokenFromParameters');
+ const spy3 = spyOn(component as any, '_registerEvents');
+
+ component.ngOnInit();
+ expect(spy).toHaveBeenCalled();
+ expect(spy2).toHaveBeenCalled();
+ expect(spy3).toHaveBeenCalled();
+ });
+
+ it('should extract token from parameters', () => {
+ const spy = spyOn(component as any, '_getParametersFromUrl').and.returnValue('im_an_accessToken');
+ const spy2 = spyOn(component as any, '_processAccessToken');
+ (component as any)._extractTokenFromParameters();
+ expect(spy).toHaveBeenCalled();
+ expect(spy2).toHaveBeenCalled();
+ });
+
+ it('should set user if _getParametersFromUrl doeasnt return an accestoken', () => {
+ const spy = spyOn(component as any, '_getParametersFromUrl');
+ const spy2 = spyOn(sandbox, 'setUser');
+ (component as any)._extractTokenFromParameters();
+ expect(spy).toHaveBeenCalled();
+ expect(spy2).toHaveBeenCalled();
+ });
+
+ it('should register events', () => {
+ (component as any)._registerEvents();
+ expect(component.isLoginPage).toBeTruthy();
+ });
});
diff --git a/projects/grid-failure-information-app/src/app/app.component.ts b/projects/grid-failure-information-app/src/app/app.component.ts
index 14b60b7..bb66463 100644
--- a/projects/grid-failure-information-app/src/app/app.component.ts
+++ b/projects/grid-failure-information-app/src/app/app.component.ts
@@ -13,7 +13,7 @@
import { Component, OnInit, HostBinding } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
-import { AppSandbox } from './app.sandbox';
+import { AppSandbox } from '@grid-failure-information-app/app/app.sandbox';
import { JwtHelperService } from '@auth0/angular-jwt';
import { User } from '@grid-failure-information-app/shared/models/user';
diff --git a/projects/grid-failure-information-app/src/app/app.module.ts b/projects/grid-failure-information-app/src/app/app.module.ts
index 25c1ec0..b966b31 100644
--- a/projects/grid-failure-information-app/src/app/app.module.ts
+++ b/projects/grid-failure-information-app/src/app/app.module.ts
@@ -48,7 +48,7 @@
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { environment } from '@grid-failure-information-app/environments/environment';
-import { ContainersModule } from '@grid-failure-information-app/shared/containers';
+import { ContainersModule } from '@grid-failure-information-app/shared/containers/containers.module';
import { NgbModalModule } from '@ng-bootstrap/ng-bootstrap';
import { SimpleNotificationsModule } from 'angular2-notifications';
diff --git a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure.module.ts b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure.module.ts
index a0d1aa9..ba584f9 100644
--- a/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure.module.ts
+++ b/projects/grid-failure-information-app/src/app/pages/grid-failure/grid-failure.module.ts
@@ -21,14 +21,14 @@
import { ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
-import { ComponentsModule } from '@grid-failure-information-app/shared/components';
+import { ComponentsModule } from '@grid-failure-information-app/shared/components/components.module';
import { TranslateModule } from '@ngx-translate/core';
import { NgrxFormsModule } from 'ngrx-forms';
import { FormsModule } from '@angular/forms';
import { AgGridModule } from 'ag-grid-angular';
import { DirectivesModule } from '@grid-failure-information-app/shared/directives';
-import { FiltersModule } from '@grid-failure-information-app/shared/filters/index.module';
-import { ContainersModule } from '@grid-failure-information-app/shared/containers';
+import { FiltersModule } from '@grid-failure-information-app/shared/filters/filters.module';
+import { ContainersModule } from '@grid-failure-information-app/shared/containers/containers.module';
import { SetFilterComponent } from '@grid-failure-information-app/shared/filters/ag-grid/set-filter/set-filter.component';
import { GridFailureService } from '@grid-failure-information-app/pages/grid-failure/grid-failure.service';
import { GridFailureApiClient } from '@grid-failure-information-app/pages/grid-failure/grid-failure-api-client';
@@ -39,7 +39,7 @@
import { gridFailureReducers } from '@grid-failure-information-app/shared/store';
import { NgbDatepickerModule, NgbTimepickerModule } from '@ng-bootstrap/ng-bootstrap';
import { UtilityModule } from '@grid-failure-information-app/shared/utility';
-import { PipesModule } from '@grid-failure-information-app/shared/pipes';
+import { PipesModule } from '@grid-failure-information-app/shared/pipes/pipes.module';
import { GridFailureInformationMapModule } from 'openk/grid-failure-information-map/src/public-api';
@NgModule({
diff --git a/projects/grid-failure-information-app/src/app/pages/imported-grid-failure/imported-grid-failure.module.ts b/projects/grid-failure-information-app/src/app/pages/imported-grid-failure/imported-grid-failure.module.ts
index c270d25..cb66ea1 100644
--- a/projects/grid-failure-information-app/src/app/pages/imported-grid-failure/imported-grid-failure.module.ts
+++ b/projects/grid-failure-information-app/src/app/pages/imported-grid-failure/imported-grid-failure.module.ts
@@ -13,11 +13,11 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
-import { ComponentsModule } from '@grid-failure-information-app/shared/components';
+import { ComponentsModule } from '@grid-failure-information-app/shared/components/components.module';
import { TranslateModule } from '@ngx-translate/core';
import { FormsModule } from '@angular/forms';
import { DirectivesModule } from '@grid-failure-information-app/shared/directives';
-import { ContainersModule } from '@grid-failure-information-app/shared/containers';
+import { ContainersModule } from '@grid-failure-information-app/shared/containers/containers.module';
import { ImportedGridFailureListComponent } from '@grid-failure-information-app/app/pages/imported-grid-failure/imported-grid-failure-list/imported-grid-failure-list.component';
import { ImportedGridFailureListSandbox } from '@grid-failure-information-app/app/pages/imported-grid-failure/imported-grid-failure-list/imported-grid-failure-list.sandbox';
import { ImportedGridFailureApiClient } from '@grid-failure-information-app/app/pages/imported-grid-failure/imported-grid-failure-api-client';
diff --git a/projects/grid-failure-information-app/src/app/pages/logout/logout.module.ts b/projects/grid-failure-information-app/src/app/pages/logout/logout.module.ts
index a98356e..615669d 100644
--- a/projects/grid-failure-information-app/src/app/pages/logout/logout.module.ts
+++ b/projects/grid-failure-information-app/src/app/pages/logout/logout.module.ts
@@ -13,11 +13,11 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
-import { ComponentsModule } from '@grid-failure-information-app/shared/components';
+import { ComponentsModule } from '@grid-failure-information-app/shared/components/components.module';
import { TranslateModule } from '@ngx-translate/core';
import { FormsModule } from '@angular/forms';
import { DirectivesModule } from '@grid-failure-information-app/shared/directives';
-import { ContainersModule } from '@grid-failure-information-app/shared/containers';
+import { ContainersModule } from '@grid-failure-information-app/shared/containers/containers.module';
import { LogoutPageSandbox } from '@grid-failure-information-app/pages/logout/logout/logout.sandbox';
import { LogoutPageComponent } from '@grid-failure-information-app/pages/logout/logout/logout.component';
import { LoggedOutPageComponent } from '@grid-failure-information-app/pages/logout/logged-out/logged-out.component';
diff --git a/projects/grid-failure-information-app/src/app/shared/async-services/http/httpResponseHandler.service.spec.ts b/projects/grid-failure-information-app/src/app/shared/async-services/http/httpResponseHandler.service.spec.ts
new file mode 100644
index 0000000..e5bb980
--- /dev/null
+++ b/projects/grid-failure-information-app/src/app/shared/async-services/http/httpResponseHandler.service.spec.ts
@@ -0,0 +1,266 @@
+/********************************************************************************
+ * Copyright (c) 2020 Contributors to the Eclipse Foundation
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ ********************************************************************************/
+
+import { HttpResponseHandler } from '@grid-failure-information-app/shared/async-services/http/httpResponseHandler.service';
+
+describe('HttpResponseHandler with undefined configService->unauthorizedEndpoints', () => {
+ let component: HttpResponseHandler;
+ let router: any;
+ let translateService: any;
+ let notificationsService: any;
+ let configService: any;
+
+ beforeEach(() => {
+ router = {
+ navigate() {},
+ } as any;
+ translateService = {
+ instant() {},
+ };
+ notificationsService = {
+ error() {},
+ info() {},
+ };
+ configService = {
+ get: () => ({ options: 'options', unauthorizedEndpoints: [] }),
+ };
+
+ component = new HttpResponseHandler(router, translateService, notificationsService, configService);
+ });
+
+ it('should create the component', () => {
+ expect(component).toBeTruthy();
+ });
+
+ it('should call handleBadRequest when response status is 400', () => {
+ const spy = spyOn(component as any, 'handleBadRequest');
+ const response = { status: 400 };
+ component.onCatch(response, {} as any);
+ expect(spy).toHaveBeenCalled();
+ });
+
+ it('should call handleUnauthorized when response status is 401', () => {
+ const spy = spyOn(component as any, 'handleUnauthorized');
+ const response = { status: 401 };
+ component.onCatch(response, {} as any);
+ expect(spy).toHaveBeenCalled();
+ });
+
+ it('should call handleForbidden when response status is 403', () => {
+ const spy = spyOn(component as any, 'handleForbidden');
+ const response = { status: 403 };
+ component.onCatch(response, {} as any);
+ expect(spy).toHaveBeenCalled();
+ });
+
+ it('should call handleNotFound when response status is 404', () => {
+ const spy = spyOn(component as any, 'handleNotFound');
+ const response = { status: 404 };
+ component.onCatch(response, {} as any);
+ expect(spy).toHaveBeenCalled();
+ });
+
+ it('should call handleRefExists when response status is 409', () => {
+ const spy = spyOn(component as any, 'handleRefExists');
+ const response = { status: 409 };
+ component.onCatch(response, {} as any);
+ expect(spy).toHaveBeenCalled();
+ });
+
+ it('should call handleServerError when response status is 500', () => {
+ const spy = spyOn(component as any, 'handleServerError');
+ const response = { status: 500 };
+ component.onCatch(response, {} as any);
+ expect(spy).toHaveBeenCalled();
+ });
+
+ it('should break when response status is not one from the defined', () => {
+ const spy = spyOn(component as any, 'handleBadRequest');
+ const spy2 = spyOn(component as any, 'handleUnauthorized');
+ const spy3 = spyOn(component as any, 'handleForbidden');
+ const spy4 = spyOn(component as any, 'handleNotFound');
+ const spy5 = spyOn(component as any, 'handleRefExists');
+ const spy6 = spyOn(component as any, 'handleServerError');
+ const response = { status: 999 };
+ component.onCatch(response, {} as any);
+ expect(spy).not.toHaveBeenCalled();
+ expect(spy2).not.toHaveBeenCalled();
+ expect(spy3).not.toHaveBeenCalled();
+ expect(spy4).not.toHaveBeenCalled();
+ expect(spy5).not.toHaveBeenCalled();
+ expect(spy6).not.toHaveBeenCalled();
+ });
+
+ it('should handle an error message when calling handleBadRequest with a valid body', () => {
+ const spy = spyOn(component as any, 'handleErrorMessages');
+ const responseBody: any = {
+ _body: {
+ timestamp: '2020-03-26T09:05:01.564+0000',
+ status: 400,
+ },
+ json() {},
+ };
+ (component as any).handleBadRequest(responseBody);
+ expect(spy).toHaveBeenCalled();
+ });
+
+ it('should handle a server error when calling handleBadRequest with a not valid body', () => {
+ const spy = spyOn(component as any, 'handleServerError');
+ const responseBody: any = {
+ _body: null,
+ json() {},
+ };
+ (component as any).handleBadRequest(responseBody);
+ expect(spy).toHaveBeenCalled();
+ });
+
+ it('should not show a 401 notification when calling handleUnauthorized without unauthorizedEndpoints', () => {
+ const spy = spyOn(translateService, 'instant');
+ const spy1 = spyOn(notificationsService, 'info');
+ const spy2 = spyOn(router, 'navigate');
+
+ const responseBody: any = {
+ url: 'endpoint1' as string,
+ };
+ (component as any).handleUnauthorized(responseBody);
+ expect(spy).not.toHaveBeenCalledWith('ServerError401');
+ expect(spy1).not.toHaveBeenCalled();
+ expect(spy2).toHaveBeenCalledWith(['/login']);
+ });
+
+ it('should show a 403 notification and navigate to login when calling handleForbidden', () => {
+ const spy = spyOn(translateService, 'instant');
+ const spy2 = spyOn(notificationsService, 'error');
+ const spy3 = spyOn(router, 'navigate');
+
+ (component as any).handleForbidden();
+ expect(spy).toHaveBeenCalledWith('ServerError403');
+ expect(spy2).toHaveBeenCalled();
+ expect(spy3).toHaveBeenCalledWith(['/login']);
+ });
+
+ it('should show an 404 error notification when calling handleNotFound', () => {
+ const spy = spyOn(translateService, 'instant');
+ const spy2 = spyOn(component as any, 'showNotificationError');
+
+ (component as any).handleNotFound();
+ expect(spy).toHaveBeenCalledWith('ServerError404');
+ expect(spy2).toHaveBeenCalled();
+ });
+
+ it('should show an error notification when calling handleRefExists', () => {
+ const spy = spyOn(translateService, 'instant');
+ const spy2 = spyOn(component as any, 'showNotificationError');
+
+ (component as any).handleRefExists();
+ expect(spy).toHaveBeenCalledWith('ServerError409');
+ expect(spy2).toHaveBeenCalled();
+ });
+
+ it('should show an 500 error notification when calling handleServerError', () => {
+ const spy = spyOn(translateService, 'instant');
+ const spy2 = spyOn(component as any, 'showNotificationError');
+
+ (component as any).handleServerError();
+ expect(spy).toHaveBeenCalledWith('ServerError500');
+ expect(spy2).toHaveBeenCalled();
+ });
+
+ it('should return without action calling handleErrorMessages with undefined response', () => {
+ const spy = spyOn(component as any, 'showNotificationError');
+ const spy2 = spyOn(component as any, 'getTranslatedValue');
+
+ const response: any = undefined;
+
+ (component as any).handleErrorMessages(response);
+ expect(spy).not.toHaveBeenCalled();
+ expect(spy2).not.toHaveBeenCalled();
+ });
+
+ it('should show one error notification when calling handleErrorMessages and there is only one error', () => {
+ const spy = spyOn(component as any, 'showNotificationError');
+ const response: any = {
+ key: '[value1]',
+ };
+
+ (component as any).handleErrorMessages(response);
+ expect(spy).toHaveBeenCalled();
+ });
+
+ it('should show as many error notification as responses when calling handleErrorMessages and there are more than one errors', () => {
+ const spy = spyOn(component as any, 'showNotificationError');
+ const spy2 = spyOn(component as any, 'getTranslatedValue');
+
+ const response: any = { key: ['[value1]', '[value2]', '[value3]'] };
+
+ (component as any).handleErrorMessages(response);
+ expect(spy).toHaveBeenCalledTimes(3);
+ expect(spy2).toHaveBeenCalled();
+ });
+
+ it('should get the translated value when calling getTranslatedValue', () => {
+ const value: string = 'value';
+
+ const result = (component as any).getTranslatedValue(value);
+ expect(result).toBe(value);
+ });
+
+ it('should call notifications service with an error message when calling showNotificationError', () => {
+ const title: string = 'title';
+ const message: string = 'message';
+ const spy = spyOn(notificationsService, 'error');
+
+ (component as any).showNotificationError(title, message);
+ expect(spy).toHaveBeenCalled();
+ });
+});
+
+describe('HttpResponseHandler with defined configService->unauthorizedEndpoints', () => {
+ let component: HttpResponseHandler;
+ let router: any;
+ let translateService: any;
+ let notificationsService: any;
+ let configService: any;
+
+ beforeEach(() => {
+ router = {
+ navigate() {},
+ } as any;
+ translateService = {
+ instant() {},
+ };
+ notificationsService = {
+ error() {},
+ info() {},
+ };
+ configService = {
+ get: () => ({ options: 'options', unauthorizedEndpoints: ['endpoint1', 'endpoint2'] }),
+ };
+
+ component = new HttpResponseHandler(router, translateService, notificationsService, configService);
+ });
+
+ it('should show a 401 notification when calling handleUnauthorized with unauthorizedEndpoints', () => {
+ const spy = spyOn(translateService, 'instant');
+ const spy1 = spyOn(notificationsService, 'info');
+ const spy2 = spyOn(router, 'navigate');
+
+ const responseBody: any = {
+ url: 'endpoint1' as string,
+ };
+ (component as any).handleUnauthorized(responseBody);
+ expect(spy).toHaveBeenCalledWith('ServerError401');
+ expect(spy1).toHaveBeenCalled();
+ expect(spy2).toHaveBeenCalledWith(['/login']);
+ });
+});
diff --git a/projects/grid-failure-information-app/src/app/shared/async-services/http/httpResponseHandler.service.ts b/projects/grid-failure-information-app/src/app/shared/async-services/http/httpResponseHandler.service.ts
index d5b163a..91dc5dc 100644
--- a/projects/grid-failure-information-app/src/app/shared/async-services/http/httpResponseHandler.service.ts
+++ b/projects/grid-failure-information-app/src/app/shared/async-services/http/httpResponseHandler.service.ts
@@ -16,6 +16,7 @@
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import { ConfigService } from '@grid-failure-information-app/app/app-config.service';
+import { throwError } from 'rxjs';
@Injectable()
export class HttpResponseHandler {
@@ -63,7 +64,7 @@
break;
}
- return Observable.throw(response);
+ return throwError(response);
}
/**
diff --git a/projects/grid-failure-information-app/src/app/shared/components/index.ts b/projects/grid-failure-information-app/src/app/shared/components/components.module.ts
similarity index 93%
rename from projects/grid-failure-information-app/src/app/shared/components/index.ts
rename to projects/grid-failure-information-app/src/app/shared/components/components.module.ts
index 59a3ab1..3a14379 100644
--- a/projects/grid-failure-information-app/src/app/shared/components/index.ts
+++ b/projects/grid-failure-information-app/src/app/shared/components/components.module.ts
@@ -10,31 +10,30 @@
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
-import { SafetyQueryDialogComponent } from '@grid-failure-information-app/shared/components/dialogs/safety-query-dialog/safety-query-dialog.component';
-import { BoolCellRendererComponent } from '@grid-failure-information-app/shared/components/cell-renderer/bool-cell-renderer/bool-cell-renderer.component';
-import { IconCellRendererComponent } from '@grid-failure-information-app/shared/components/cell-renderer/icon-cell-renderer/icon-cell-renderer.component';
-import { PaginationComponent } from '@grid-failure-information-app/shared/components/pagination/pagination.component';
-import { LoadingSpinnerComponent } from '@grid-failure-information-app/shared/components/loading-spinner/loading-spinner.component';
+import { CommonModule, DatePipe } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
-import { CommonModule, DatePipe } from '@angular/common';
-import { PipesModule } from '@grid-failure-information-app/shared/pipes';
-import { TranslateModule } from '@ngx-translate/core';
-import { SpinnerComponent } from '@grid-failure-information-app/shared/components/spinner/spinner.component';
-import { HeaderComponent } from '@grid-failure-information-app/shared/components/header/header.component';
-import { PageNotFoundComponent } from '@grid-failure-information-app/shared/components/page-not-found/pageNotFound.component';
-import { LoadingPlaceholderComponent } from '@grid-failure-information-app/shared/components/loading-placeholder/loading-placeholder.component';
-import { VersionInfo } from '@grid-failure-information-app/shared/components/version-info/version-info.component';
-import { AngularFontAwesomeModule } from 'angular-font-awesome';
-import { ExpandableComponent } from '@grid-failure-information-app/shared/components/expandable/expandable.component';
-import { AgGridModule } from 'ag-grid-angular';
-import { NgrxFormsModule } from 'ngrx-forms';
-import { DirectivesModule } from '@grid-failure-information-app/shared/directives/index';
-import { NgbModule, NgbDateParserFormatter, NgbDatepickerModule } from '@ng-bootstrap/ng-bootstrap';
-import { NgbDateCustomParserFormatter } from '@grid-failure-information-app/shared/pipes/ngb-date-custom-parser-formatter';
+import { BoolCellRendererComponent } from '@grid-failure-information-app/shared/components/cell-renderer/bool-cell-renderer/bool-cell-renderer.component';
import { DateCellRendererComponent } from '@grid-failure-information-app/shared/components/cell-renderer/date-cell-renderer/date-cell-renderer.component';
+import { IconCellRendererComponent } from '@grid-failure-information-app/shared/components/cell-renderer/icon-cell-renderer/icon-cell-renderer.component';
import { DateTimePickerComponent } from '@grid-failure-information-app/shared/components/date-time-picker/date-time-picker.component';
+import { SafetyQueryDialogComponent } from '@grid-failure-information-app/shared/components/dialogs/safety-query-dialog/safety-query-dialog.component';
+import { ExpandableComponent } from '@grid-failure-information-app/shared/components/expandable/expandable.component';
+import { HeaderComponent } from '@grid-failure-information-app/shared/components/header/header.component';
+import { LoadingPlaceholderComponent } from '@grid-failure-information-app/shared/components/loading-placeholder/loading-placeholder.component';
+import { LoadingSpinnerComponent } from '@grid-failure-information-app/shared/components/loading-spinner/loading-spinner.component';
+import { PageNotFoundComponent } from '@grid-failure-information-app/shared/components/page-not-found/pageNotFound.component';
+import { PaginationComponent } from '@grid-failure-information-app/shared/components/pagination/pagination.component';
+import { SpinnerComponent } from '@grid-failure-information-app/shared/components/spinner/spinner.component';
+import { VersionInfo } from '@grid-failure-information-app/shared/components/version-info/version-info.component';
+import { DirectivesModule } from '@grid-failure-information-app/shared/directives/index';
+import { PipesModule } from '@grid-failure-information-app/shared/pipes/pipes.module';
+import { NgbDatepickerModule, NgbModule } from '@ng-bootstrap/ng-bootstrap';
+import { TranslateModule } from '@ngx-translate/core';
+import { AgGridModule } from 'ag-grid-angular';
+import { AngularFontAwesomeModule } from 'angular-font-awesome';
+import { NgrxFormsModule } from 'ngrx-forms';
export const COMPONENTS = [
SpinnerComponent,
diff --git a/projects/grid-failure-information-app/src/app/shared/containers/index.ts b/projects/grid-failure-information-app/src/app/shared/containers/containers.module.ts
similarity index 87%
rename from projects/grid-failure-information-app/src/app/shared/containers/index.ts
rename to projects/grid-failure-information-app/src/app/shared/containers/containers.module.ts
index 3fe9e6b..a3988ed 100644
--- a/projects/grid-failure-information-app/src/app/shared/containers/index.ts
+++ b/projects/grid-failure-information-app/src/app/shared/containers/containers.module.ts
@@ -1,4 +1,4 @@
- /********************************************************************************
+/********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
@@ -13,7 +13,7 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
-import { ComponentsModule } from '../components';
+import { ComponentsModule } from '../components/components.module';
import { LayoutContainerComponent } from './layout/layout.container';
import { LayoutSandbox } from './layout/layout.sandbox';
import { TranslateModule } from '@ngx-translate/core';
diff --git a/projects/grid-failure-information-app/src/app/shared/filters/index.module.ts b/projects/grid-failure-information-app/src/app/shared/filters/filters.module.ts
similarity index 100%
rename from projects/grid-failure-information-app/src/app/shared/filters/index.module.ts
rename to projects/grid-failure-information-app/src/app/shared/filters/filters.module.ts
diff --git a/projects/grid-failure-information-app/src/app/shared/guards/admin.guard.spec.ts b/projects/grid-failure-information-app/src/app/shared/guards/admin.guard.spec.ts
new file mode 100644
index 0000000..d7ccfe1
--- /dev/null
+++ b/projects/grid-failure-information-app/src/app/shared/guards/admin.guard.spec.ts
@@ -0,0 +1,57 @@
+/********************************************************************************
+ * Copyright (c) 2020 Contributors to the Eclipse Foundation
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ ********************************************************************************/
+
+import { AdminGuard } from '@grid-failure-information-app/shared/guards/admin.guard';
+import { of } from 'rxjs/observable/of';
+import { User } from '@grid-failure-information-app/shared/models/user';
+
+describe('AdminGuard', () => {
+ let component: AdminGuard;
+ let appState: any;
+ let router: any;
+
+ beforeEach(() => {
+ appState = {
+ pipe: () => of(1),
+ dispatch: () => {},
+ select: () => of(1),
+ };
+ router = {
+ navigate() {},
+ } as any;
+
+ component = new AdminGuard(router, appState);
+ });
+
+ it('should create the component', () => {
+ expect(component).toBeTruthy();
+ });
+
+ it('should call _checkAdminRight wehn calling canActivate', () => {
+ const spy = spyOn(component as any, '_checkAdminRight');
+ component.canActivate({} as any, {} as any);
+ expect(spy).toHaveBeenCalled();
+ });
+
+ it('should check if has admin right', () => {
+ const user: User = new User();
+ user.id = '123';
+ user.roles = ['admin', 'reader'];
+
+ const spy = spyOn(appState, 'select').and.returnValue(of(user));
+ const spy2 = spyOn(router, 'navigate');
+ (component as any)._checkAdminRight();
+ expect(spy).toHaveBeenCalled();
+ expect(spy2).toHaveBeenCalledWith(['/grid-failures']);
+ });
+});
diff --git a/projects/grid-failure-information-app/src/app/shared/guards/admin.guard.ts b/projects/grid-failure-information-app/src/app/shared/guards/admin.guard.ts
index 45d24b2..7b71527 100644
--- a/projects/grid-failure-information-app/src/app/shared/guards/admin.guard.ts
+++ b/projects/grid-failure-information-app/src/app/shared/guards/admin.guard.ts
@@ -33,7 +33,7 @@
.select(store.getUser)
.pipe(takeUntil(this._endSubscriptions$), take(1))
.map((user: User) => new PermissionsModel(user.roles).admin);
- isAdmin$.subscribe(isAdmin => !isAdmin && this._router.navigate(['/overview']));
+ isAdmin$.subscribe(isAdmin => !isAdmin && this._router.navigate(['/grid-failures']));
return isAdmin$.pipe(take(1));
}
}
diff --git a/projects/grid-failure-information-app/src/app/shared/pipes/index.ts b/projects/grid-failure-information-app/src/app/shared/pipes/pipes.module.ts
similarity index 100%
rename from projects/grid-failure-information-app/src/app/shared/pipes/index.ts
rename to projects/grid-failure-information-app/src/app/shared/pipes/pipes.module.ts