Commit d4dba726 authored by Maxime REYROLLE's avatar Maxime REYROLLE

Merge branch '17-dashboard-view' into 'develop'

Resolve "Dashboard view"

Closes #17

See merge request !42
parents f18bddc7 003c046e
Pipeline #1308 passed with stage
in 13 minutes and 8 seconds
......@@ -13,6 +13,7 @@ import {SubscriptionsModule} from './subscriptions/subscriptions.module';
import {AuthenticationModule} from './authentication/authentication.module';
import {AuthenticationService} from './authentication/shared/authentication.service';
import {AuthenticationGuard} from './authentication/guard/authentication.guard';
import {DashboardModule} from './dashboard/dashboard.module';
@NgModule({
declarations: [
......@@ -28,7 +29,8 @@ import {AuthenticationGuard} from './authentication/guard/authentication.guard';
LocalGovernmentsModule,
ConnectorsModule,
SubscriptionsModule,
AuthenticationModule
AuthenticationModule,
DashboardModule
],
providers: [
AuthenticationService,
......
import {NgModule} from '@angular/core';
import {Routes, RouterModule} from '@angular/router';
import {DashboardComponent} from './dashboard/dashboard.component';
import {AuthenticationGuard} from '../authentication/guard/authentication.guard';
const routes: Routes = [
{
path: 'dashboard',
canActivate: [AuthenticationGuard],
children: [
{
path: ':local_government_id',
component: DashboardComponent
},
],
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class DashboardRoutingModule {
}
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {DashboardRoutingModule} from './dashboard-routing.module';
import {DashboardComponent} from './dashboard/dashboard.component';
import {DashboardService} from './shared/dashboard.service';
@NgModule({
imports: [
CommonModule,
DashboardRoutingModule
],
declarations: [
DashboardComponent
],
providers: [
DashboardService
]
})
export class DashboardModule {
}
<ul *ngFor="let service of servicesData" class="services">
<li><a href="{{service.url}}">{{service.name}}</a>
<ul *ngFor="let data of service.data">
<li>
<a href="{{data.link}}">{{data.label}}</a>
</li>
</ul>
</li>
</ul>
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {ActivatedRoute} from '@angular/router';
import {Observable} from 'rxjs/Observable';
import {By} from '@angular/platform-browser';
import {DashboardComponent} from './dashboard.component';
import {DashboardService} from '../shared/dashboard.service';
import {DashboardServiceMock} from '../shared/dashboard.service.mock';
describe('DashboardComponent', () => {
let component: DashboardComponent;
let fixture: ComponentFixture<DashboardComponent>;
const mock = {
params: Observable.of({local_government_id: 1})
};
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
DashboardComponent
],
providers: [
{provide: DashboardService, useClass: DashboardServiceMock},
{provide: ActivatedRoute, useValue: mock}
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(DashboardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should return 2 services', () => {
fixture.detectChanges();
const services = fixture.debugElement.queryAll(By.css('.services'));
expect(services.length).toEqual(2);
});
it('should display labels of the first service data', () => {
fixture.detectChanges();
const services = fixture.debugElement.queryAll(By.css('.services'));
const serviceTextContent = services[0].nativeElement.textContent;
expect(serviceTextContent).toContain(DashboardServiceMock.SERVICE_1.data[0].label);
expect(serviceTextContent).toContain(DashboardServiceMock.SERVICE_1.data[1].label);
expect(serviceTextContent).toContain(DashboardServiceMock.SERVICE_1.data[2].label);
});
});
import {Component, OnInit} from '@angular/core';
import {DashboardService} from '../shared/dashboard.service';
import {ActivatedRoute} from '@angular/router';
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.css']
})
export class DashboardComponent implements OnInit {
servicesData;
constructor(private dashboardService: DashboardService, private route: ActivatedRoute) {
}
ngOnInit() {
this.route.params.subscribe(params => {
if (!params['local_government_id']) {
return;
}
this.dashboardService.getDataFromServices(params['local_government_id'])
.subscribe(servicesData => {
this.servicesData = servicesData.services;
});
});
}
}
import {Observable} from 'rxjs/Observable';
export class DashboardServiceMock {
static SERVICE_1 = {
'name': 'Actes',
'url': 'https://pastell.example.org',
'data': [
{
'label': '0 documents with TDT errors',
'link': 'https://pastell.example.org/document/list.php?type=actes-generique&id_e=1&filtre=erreur-verif-tdt'
},
{
'label': '1 pending document',
'link': 'https://pastell.example.org/document/list.php?type=actes-generique&id_e=1&filtre=modification'
},
{
'label': '0 documents with prefecture response',
'link': 'https://pastell.example.org/document/list.php?type=actes-generique&id_e=1&filtre=verif-reponse-tdt'
}
]
};
static SERVICE_2 = {
'name': 'Hélios',
'url': 'https://pastell.example.org',
'data': [
{
'label': '1 document with TDT error',
'link': 'https://pastell.example.org/document/list.php?type=helios-generique&id_e=1&filtre=tdt-error'
},
{
'label': '0 documents to be transmitted to the TDT',
'link': 'https://pastell.example.org/document/list.php?type=helios-generique&id_e=1&filtre=recu-iparapheur'
}
]
};
static services = [DashboardServiceMock.SERVICE_1, DashboardServiceMock.SERVICE_2];
getDataFromServices(local_government_id) {
return Observable.of({'services': DashboardServiceMock.services});
}
}
import {TestBed, inject, fakeAsync, tick} from '@angular/core/testing';
import {Http, BaseRequestOptions, RequestMethod, ResponseOptions, Response} from '@angular/http';
import {MockBackend} from '@angular/http/testing';
import {AuthHttp} from 'angular2-jwt';
import {DashboardService} from './dashboard.service';
describe('DashboardService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
DashboardService,
{
provide: Http,
useFactory: (mockBackend: MockBackend, requestOptions: BaseRequestOptions) => {
return new Http(mockBackend, requestOptions);
},
deps: [MockBackend, BaseRequestOptions]
},
MockBackend,
BaseRequestOptions,
{provide: AuthHttp, useExisting: Http, deps: [Http]},
]
});
});
it('should be created', inject([DashboardService], (service: DashboardService) => {
expect(service).toBeTruthy();
}));
describe('getDataFromServices()', () => {
it('should load data from services', inject([DashboardService, MockBackend],
fakeAsync((dashboardService: DashboardService, mockBackend: MockBackend) => {
const expectedBody = {
'services': [
{
'name': 'Actes',
'url': 'https://pastell.example.org',
'data': [
{
'label': '0 documents with TDT errors',
'link': 'https://pastell.example.org/document/list.php?type=actes-generique&id_e=1&filtre=erreur-verif-tdt'
},
{
'label': '1 pending document',
'link': 'https://pastell.example.org/document/list.php?type=actes-generique&id_e=1&filtre=modification'
},
{
'label': '0 documents with prefecture response',
'link': 'https://pastell.example.org/document/list.php?type=actes-generique&id_e=1&filtre=verif-reponse-tdt'
}
]
},
{
'name': 'Hélios',
'url': 'https://pastell.example.org',
'data': [
{
'label': '1 document with TDT error',
'link': 'https://pastell.example.org/document/list.php?type=helios-generique&id_e=1&filtre=tdt-error'
},
{
'label': '0 documents to be transmitted to the TDT',
'link': 'https://pastell.example.org/document/list.php?type=helios-generique&id_e=1&filtre=recu-iparapheur'
}
]
}
]
};
let result;
mockBackend.connections.subscribe(connection => {
expect(connection.request.method).toBe(RequestMethod.Get);
expect(connection.request.url).toBe('https://cake.test.adullact.org/api/v1/local_governments/3/services.json');
const options = new ResponseOptions({status: 200, body: expectedBody});
connection.mockRespond(new Response(options));
});
dashboardService.getDataFromServices(3).subscribe(data => {
result = data;
});
tick();
expect(result).toBe(expectedBody, 'should return the data from the services');
})));
});
});
import {Injectable} from '@angular/core';
import {AuthHttp} from 'angular2-jwt';
import {environment} from '../../../environments/environment';
@Injectable()
export class DashboardService {
private url = environment.apiUrl + '/local_governments';
constructor(private authHttp: AuthHttp) {
}
getDataFromServices(local_government_id) {
return this.authHttp.get(this.url + '/' + local_government_id + '/services.json')
.map(response => response.json());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment