Guest User

Untitled

a guest
Nov 6th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.97 KB | None | 0 0
  1. import { GdfaClientService } from '../../../service/gdfa-client.service';
  2. import { SharedclientService } from '../../../service/sharedclient.service';
  3. import { Client } from '../../model/client';
  4. import { RouteNavigator } from '../../util/route-navigator';
  5. import { Component, OnInit } from '@angular/core';
  6. import {MonitoringService} from '../../../service/monitoring.service';
  7. @Component({
  8. selector: 'app-queue-again',
  9. templateUrl: './queue-again.component.html',
  10. styleUrls: ['./queue-again.component.css'],
  11. })
  12. export class QueueAgainComponent implements OnInit {
  13.  
  14. //-- variables --//
  15. showError = false;
  16. queueChoices = [];
  17. selectedQueue;
  18. selectedReason;
  19. requestInProgress = false;
  20. client: Client;
  21. errorMessage: string;
  22. queues: any;
  23. bankNotAllowed: boolean = false;
  24.  
  25. constructor(private sharedclientService: SharedclientService, private gdfaClientService: GdfaClientService
  26. , private router: RouteNavigator, private monitoringService: MonitoringService) { }
  27.  
  28. ngOnInit() {
  29. this.client = this.sharedclientService.getShared360Client();
  30. this.getQueues();
  31. this.bankNotAllowed = this.sharedclientService.bankNotAllowed;
  32. }
  33.  
  34.  
  35. goToPrevious() {
  36. this.router.goToHomeAccordingToProfile();
  37. }
  38.  
  39. queueAgain() {
  40. let currentNd = "";
  41. let currentUniverse = "";
  42. let currentCuid = "";
  43. if (!this.selectedReason) {
  44. return;
  45. }
  46. this.requestInProgress = true;
  47.  
  48. let reg = {
  49. registrationId: this.client.registration.gdfaId,
  50. gdfaQueueId: this.selectedQueue.id,
  51. gdfaReasonId: this.selectedReason.id,
  52. firstProfile: (this.client.firstProfile ? true : false)
  53. };
  54.  
  55. this.gdfaClientService.queueAgain(reg).then(any => {
  56. currentCuid = this.client.clientIdentity.customerId;
  57.  
  58. if (this.client.fromAdvSearch == undefined || this.client.fromAdvSearch == false) {
  59.  
  60. currentNd = this.client.nd;
  61. if (currentNd != undefined && currentNd != "") {
  62. if (currentNd == "0000000000") {
  63. currentNd = "";
  64. currentUniverse = "";
  65. }
  66. if (currentNd.substring(0, 2) == "06" || currentNd.substring(0, 2) == "07") {
  67. currentUniverse = "Mobile";
  68. } else {
  69. currentUniverse = "Fixe";
  70. }
  71. }
  72. }
  73. this.trackReinsertClient(currentCuid, currentNd, currentUniverse);
  74. this.requestInProgress = false;
  75. this.showError = false;
  76. this.sharedclientService.setShared360Client(new Client());
  77. this.goToPrevious();
  78. })
  79. .catch(error => {
  80. this.requestInProgress = false;
  81. this.showError = true;
  82. switch (error.status) {
  83. case 403:
  84. this.errorMessage = "Erreur lors de la réinjection du client : utilisateur inconnu";
  85. console.log(this.errorMessage);
  86. break;
  87. case 500:
  88. this.errorMessage = "Réinscription impossible";
  89. console.log(this.errorMessage);
  90. break;
  91. default:
  92. this.errorMessage = "Erreur lors de la réinjection du client";
  93. console.log(this.errorMessage);
  94. }
  95. });
  96. };
  97.  
  98.  
  99. trackReinsertClient(cuid, nd, universe) {
  100. let uri = "/api/gdfa/client/registration/reinsert";
  101. let httpMethod = "PUT";
  102. let name = "réinjection d'un client dans la file d'attente";
  103. console.log('trackReinsertClient <' + cuid + '>');
  104. this.monitoringService.trackingAction(name, uri, httpMethod, null, cuid, nd, universe);
  105.  
  106. }
  107.  
  108. selectQueue(queue) {
  109. this.selectedQueue = queue;
  110. this.selectedReason = false;
  111. };
  112.  
  113. isSelectedQueue(queue) {
  114. return this.selectedQueue.shortName == queue.shortName;
  115. }
  116.  
  117. getQueues() {
  118. let queueList = this.client.registration.queueAgainChoices;
  119. // Search for residentiel queue and put it as selectedQueue
  120. let indexSAVSAUMobile = -1;
  121. let indexSAVSAUInternet = -1;
  122. for (let queue of queueList) {
  123. if (queue.shortName == 'RES')
  124. this.selectedQueue = queue;
  125. }
  126.  
  127. this.queues = queueList;
  128. return queueList;
  129. }
  130.  
  131. selectReason(reason) {
  132. this.selectedReason = reason;
  133.  
  134. }
  135.  
  136.  
  137. isSelectedReason(reason) {
  138. if (this.selectedReason) {
  139. return this.selectedReason.id == reason.id;
  140. }
  141. return null
  142. }
  143.  
  144. getReasons(queue) {
  145. let reasonList = this.selectedQueue.reasons;
  146. return reasonList;
  147. }
  148. }
  149.  
  150. <div>
  151. <div [hidden]="!requestInProgress" id="div-spinner">
  152. <img src="/assets/images/indicateur-attente-grand.gif"
  153. class="spinner-loader" />
  154. </div>
  155. <div class="row">
  156. <!-- fermeture de la recherche avancée -->
  157. <div class="col-xs-1 pull-right closeCross">
  158. <img id="ngClick_goToPreviousFromQueueAgain"
  159. src="/assets/images/asset_icon_close_popup_gray.png"
  160. class="pull-right mousePointer" (click)="goToPrevious()" />
  161. </div>
  162. </div>
  163. <div class="row">
  164. <div class="col-xs-10 col-xs-offset-1 error-message"
  165. *ngIf="showError">{{errorMessage}}</div>
  166. <div
  167. class="col-xs-10 col-xs-offset-1 col-sm-3 col-sm-offset-0 register-bloc">
  168. <div class="titre_bloc">File d'attente</div>
  169. <div id="files-bloc">
  170. <div id="ngClick_selectQueueAgain" class="file-cell "
  171. *ngFor="let queue of queues | orderBy : 'id'"
  172. [ngClass]="{ 'selected-shop-queue': isSelectedQueue(queue)}"
  173. (click)='selectQueue(queue)'>
  174. <div class="vertical-center horizontal-middle file_nom">
  175. <div>{{queue.name}}</div>
  176. </div>
  177. </div>
  178. </div>
  179. </div>
  180. <div
  181. class="col-xs-10 col-xs-offset-1 col-sm-6 col-sm-offset-0 register-bloc">
  182. <div class="titre_bloc">Motifs</div>
  183. <div id="motifs-bloc">
  184. <div id="ngClick_queueAgain" class="motif-cell"
  185. [ngClass]="{'motif-cell-pro': selectedQueue?.reasons?.length == 4, 'motif-cell-selected':isSelectedReason(reason),
  186. 'hide-class': (bankNotAllowed && reason.id === 12)}" [hidden]="bankNotAllowed && reason.id === 12"
  187. *ngFor="let reason of selectedQueue?.reasons | orderBy : 'motifOrder'"
  188. (click)='selectReason(reason)'>
  189. <div *ngIf="!bankNotAllowed || reason.id !== 12" class="mIcon">
  190. <img
  191. src="/bower_components/nomadis/images-no-cache/{{reason?.imageName}}"
  192. [ngClass]="{'motif-unique': client?.registration?.queue?.reasons?.length == 1}" />
  193. <span>{{reason.name}}</span>
  194. </div>
  195. </div>
  196. </div>
  197. <div class="col-sm-offset-4 col-sm-4 btn-validate-reinsert">
  198. <input id="validateReinsertBtn" type="submit" value="Valider"
  199. [ngClass]="{'queueAgain-disabled': !selectedReason}"
  200. class="btn btn-lg btn-primary btn-block"
  201. (click)='queueAgain()' />
  202. </div>
  203. </div>
  204. </div>
  205.  
  206. </div>
  207. <router-outlet></router-outlet>
  208.  
  209. import {async, ComponentFixture, TestBed, tick, fakeAsync} from '@angular/core/testing';
  210. import {QueueAgainComponent} from './queue-again.component';
  211. import {OrderByPipe} from 'app/home/pipe/order-by.pipe';
  212. import {SharedclientService} from 'app/service/sharedclient.service';
  213. import {GdfaClientService} from 'app/service/gdfa-client.service';
  214. import {AuthHttp, AuthConfig, AUTH_PROVIDERS, provideAuth} from 'angular2-jwt';
  215. import {HttpModule} from '@angular/http';
  216. import {EnvVarsService} from 'app/service/env-vars.service';
  217. import {RouteNavigator} from 'app/home/util/route-navigator';
  218. import {Router} from '@angular/router';
  219. import {Observable} from 'rxjs/Observable';
  220. import * as QueueAgainMocks from 'TU/mocks/queue-again-mocks';
  221. import {RouterTestingModule} from '@angular/router/testing';
  222. import { NO_ERRORS_SCHEMA } from '@angular/core';
  223.  
  224. describe('QueueAgainComponent', () => {
  225. let comp: QueueAgainComponent;
  226. let fixture: ComponentFixture<QueueAgainComponent>;
  227. let sharedclientService: SharedclientService;
  228. let gdfaClientService: GdfaClientService;
  229. let getShared360Client: jasmine.Spy;
  230. let queueAgain: jasmine.Spy;
  231. let client = QueueAgainMocks.CUSTOMER_MOCK;
  232. let selectedQueue = QueueAgainMocks.SELECTED_QUEUE_MOCK;
  233. let selectedReason = QueueAgainMocks.SELECTED_REASON;
  234. let mockRouter = {
  235. navigate: jasmine.createSpy('navigate')
  236. };
  237.  
  238. // TestBed preparation (async)
  239. beforeEach(async(() => {
  240. TestBed.configureTestingModule({
  241. imports: [HttpModule , RouterTestingModule],
  242. declarations: [QueueAgainComponent, OrderByPipe],
  243. providers: [SharedclientService, GdfaClientService, AuthHttp, EnvVarsService, RouteNavigator,
  244. {provide: Router, useValue: mockRouter},
  245. provideAuth({
  246. headerName: 'Authorization',
  247. headerPrefix: 'bearer',
  248. tokenName: 'token',
  249. tokenGetter: (() => localStorage.getItem('id_token')),
  250. globalHeaders: [{'Content-Type': 'application/json'}],
  251. noJwtError: true
  252. })
  253. ],
  254. schemas: [ NO_ERRORS_SCHEMA ]
  255. }).compileComponents();
  256. }));
  257.  
  258. // Fixture & Spies declarations
  259. beforeEach(() => {
  260. // Creation of the component fixture
  261. fixture = TestBed.createComponent(QueueAgainComponent);
  262. comp = fixture.componentInstance;
  263. fixture.detectChanges(); // this line will call components ngOnInit() method
  264.  
  265.  
  266. // Getting Services instances from fixture
  267. sharedclientService = fixture.debugElement.injector.get(SharedclientService);
  268. gdfaClientService = fixture.debugElement.injector.get(GdfaClientService);
  269.  
  270. // Call of fake methods of `sharedclientService` from the AlertServiceSpy
  271. getShared360Client = spyOn(sharedclientService, 'getShared360Client').and.returnValue(client);
  272. // Call of fake methods of `gdfaClientService` from the AlertServiceSpy
  273. queueAgain = spyOn(gdfaClientService, 'queueAgain').and.callFake((reg) => {
  274. return Observable.of('ok');
  275. });
  276.  
  277. comp.ngOnInit();
  278. });
  279. // Test case of component compilation
  280. it('should be defined', () => {
  281. expect(comp).toBeDefined();
  282. });
  283. });
  284.  
  285. TypeError: Cannot read property 'root' of undefined
  286.  
  287. at rootRoute (node_modules/@angular/router/bundles/router.umd.js:6110:30)
  288. at _callFactory (packages/core/src/view/ng_module.ts:185:1)
  289. at _createProviderInstance$1 (packages/core/src/view/ng_module.ts:124:1)
  290. at resolveNgModuleDep (node_modules/@angular/core/bundles/core.umd.js:9517:17)
  291. at _createClass (packages/core/src/view/ng_module.ts:158:1)
  292. at _createProviderInstance$1 (packages/core/src/view/ng_module.ts:121:1)
  293. at resolveNgModuleDep (node_modules/@angular/core/bundles/core.umd.js:9517:17)
  294. at NgModuleRef_.Object.<anonymous>.NgModuleRef_.get (node_modules/@angular/core/bundles/core.umd.js:10609:16)
  295. at resolveDep (node_modules/@angular/core/bundles/core.umd.js:11112:45)
  296. at createClass (node_modules/@angular/core/bundles/core.umd.js:10976:32)
  297. at createDirectiveInstance (node_modules/@angular/core/bundles/core.umd.js:10796:37)
  298. at createViewNodes (packages/core/src/view/view.ts:354:1)
  299. at createRootView (node_modules/@angular/core/bundles/core.umd.js:12139:5)
  300. at callWithDebugContext (packages/core/src/view/services.ts:815:1)
  301. at Object.debugCreateRootView [as createRootView] (node_modules/@angular/core/bundles/core.umd.js:12842:12)
  302. at ComponentFactory_.Object.<anonymous>.ComponentFactory_.create (node_modules/@angular/core/bundles/core.umd.js:9904:46)
  303. at initComponent (node_modules/@angular/core/bundles/core-testing.umd.js:924:49)
  304. at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (node_modules/zone.js/dist/zone-node.js:392:26)
  305. at ProxyZoneSpec.Object.<anonymous>.ProxyZoneSpec.onInvoke (node_modules/zone.js/dist/proxy.js:79:39)
  306. at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (node_modules/zone.js/dist/zone-node.js:391:32)
  307. at Object.onInvoke (node_modules/@angular/core/bundles/core.umd.js:3922:33)
  308. at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (node_modules/zone.js/dist/zone-node.js:391:32)
  309. at Zone.Object.<anonymous>.Zone.run (node_modules/zone.js/dist/zone-node.js:142:43)
  310. at NgZone.Object.<anonymous>.NgZone.run (node_modules/@angular/core/bundles/core.umd.js:3853:69)
  311. at TestBed.Object.<anonymous>.TestBed.createComponent (packages/core/testing/src/test_bed.ts:471:1)
  312. at Function.Object.<anonymous>.TestBed.createComponent (node_modules/@angular/core/bundles/core-testing.umd.js:691:29)
  313. at src/app/home/advisor/queue-again/queue-again.component.spec.ts:53:27
  314.  
  315. fixture = TestBed.createComponent(QueueAgainComponent);
  316.  
  317. @Directive({
  318. selector: '[routerLink]'
  319. })
  320. class RouterLinkDirective {}
  321.  
  322. declarations: [QueueAgainComponent, OrderByPipe, RouterLinkDirective ],
Add Comment
Please, Sign In to add comment