From d0c5298deeeb1bf667305026c0bc9b9eed630d36 Mon Sep 17 00:00:00 2001 From: Abigail Cabascango Date: Mon, 22 Aug 2022 13:12:35 -0500 Subject: [PATCH 01/17] TTA-115 implement a stable, slow or offline connection warning --- src/app/app.component.html | 12 +++ src/app/app.module.ts | 11 +++ .../connection.directive.ts | 29 ++++++ .../fast.directive.ts | 11 +++ .../offline.directive.ts | 11 +++ .../slow.directive.ts | 11 +++ .../internet-connection-status.component.html | 0 .../internet-connection-status.component.scss | 0 ...ternet-connection-status.component.spec.ts | 88 +++++++++++++++++++ .../internet-connection-status.component.ts | 85 ++++++++++++++++++ 10 files changed, 258 insertions(+) create mode 100644 src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts create mode 100644 src/app/modules/internet-connection-status/internet-connection-directives/fast.directive.ts create mode 100644 src/app/modules/internet-connection-status/internet-connection-directives/offline.directive.ts create mode 100644 src/app/modules/internet-connection-status/internet-connection-directives/slow.directive.ts create mode 100644 src/app/modules/internet-connection-status/internet-connection-status.component.html create mode 100644 src/app/modules/internet-connection-status/internet-connection-status.component.scss create mode 100644 src/app/modules/internet-connection-status/internet-connection-status.component.spec.ts create mode 100644 src/app/modules/internet-connection-status/internet-connection-status.component.ts diff --git a/src/app/app.component.html b/src/app/app.component.html index 0680b43f9..199f49375 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1 +1,13 @@ + + + + + + + + + + + + diff --git a/src/app/app.module.ts b/src/app/app.module.ts index d0c44bfbf..72f773d54 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -97,6 +97,12 @@ import { SearchUserComponent } from './modules/shared/components/search-user/sea import { TimeRangeCustomComponent } from './modules/reports/components/time-range-custom/time-range-custom.component'; import { TimeRangeHeaderComponent } from './modules/reports/components/time-range-custom/time-range-header/time-range-header.component'; import { TimeRangeOptionsComponent } from './modules/reports/components/time-range-custom/time-range-options/time-range-options.component'; +import { InternetConnectionStatusComponent } from './modules/internet-connection-status/internet-connection-status.component'; +import { FastDirective} from './modules/internet-connection-status/internet-connection-directives/fast.directive'; +import { SlowDirective} from './modules/internet-connection-status/internet-connection-directives/slow.directive'; +import { OfflineDirective} from './modules/internet-connection-status/internet-connection-directives/offline.directive'; +import { ConnectionDirective } from './modules/internet-connection-status/internet-connection-directives/connection.directive'; + const maskConfig: Partial = { validation: false, @@ -156,6 +162,11 @@ const maskConfig: Partial = { TimeRangeCustomComponent, TimeRangeHeaderComponent, TimeRangeOptionsComponent, + InternetConnectionStatusComponent, + SlowDirective, + FastDirective, + OfflineDirective, + ConnectionDirective ], imports: [ NgxMaskModule.forRoot(maskConfig), diff --git a/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts b/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts new file mode 100644 index 000000000..569540db1 --- /dev/null +++ b/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts @@ -0,0 +1,29 @@ +import { Directive, Attribute, ElementRef, OnInit } from '@angular/core'; + +@Directive({ + selector: '[appConnection]' +}) + +export class ConnectionDirective implements OnInit { + constructor( + @Attribute('slowSrc') private slowSrc, + @Attribute('fastSrc') private fastSrc, + @Attribute('offlineSrc') private offlineSrc, + private host: ElementRef + ) { + } + + ngOnInit() { + const { effectiveType } = navigator.connection; + let src; + if (/\fast-5g|3g|4g/.test(effectiveType)) { + src = this.fastSrc; + }else if (/\slow-2g|2g/.test(effectiveType)) { + src = this.slowSrc; + }else { + src = this.offlineSrc; + } + this.host.nativeElement.setAttribute('src', src); + } + +} diff --git a/src/app/modules/internet-connection-status/internet-connection-directives/fast.directive.ts b/src/app/modules/internet-connection-status/internet-connection-directives/fast.directive.ts new file mode 100644 index 000000000..50faa29a3 --- /dev/null +++ b/src/app/modules/internet-connection-status/internet-connection-directives/fast.directive.ts @@ -0,0 +1,11 @@ +import { Directive, TemplateRef } from '@angular/core'; + +@Directive({ + selector: '[appFast]' +}) + +export class FastDirective { + + constructor(public tpl: TemplateRef) { } + +} diff --git a/src/app/modules/internet-connection-status/internet-connection-directives/offline.directive.ts b/src/app/modules/internet-connection-status/internet-connection-directives/offline.directive.ts new file mode 100644 index 000000000..986c8542c --- /dev/null +++ b/src/app/modules/internet-connection-status/internet-connection-directives/offline.directive.ts @@ -0,0 +1,11 @@ +import { Directive, TemplateRef } from '@angular/core'; + +@Directive({ + selector: '[appOffline]' +}) + +export class OfflineDirective { + + constructor(public tpl: TemplateRef) { } + +} diff --git a/src/app/modules/internet-connection-status/internet-connection-directives/slow.directive.ts b/src/app/modules/internet-connection-status/internet-connection-directives/slow.directive.ts new file mode 100644 index 000000000..9095e34a1 --- /dev/null +++ b/src/app/modules/internet-connection-status/internet-connection-directives/slow.directive.ts @@ -0,0 +1,11 @@ +import { Directive, TemplateRef } from '@angular/core'; + +@Directive({ + selector: '[appSlow]' +}) + +export class SlowDirective { + + constructor(public tpl: TemplateRef) { } + +} diff --git a/src/app/modules/internet-connection-status/internet-connection-status.component.html b/src/app/modules/internet-connection-status/internet-connection-status.component.html new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/modules/internet-connection-status/internet-connection-status.component.scss b/src/app/modules/internet-connection-status/internet-connection-status.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/modules/internet-connection-status/internet-connection-status.component.spec.ts b/src/app/modules/internet-connection-status/internet-connection-status.component.spec.ts new file mode 100644 index 000000000..fb212617c --- /dev/null +++ b/src/app/modules/internet-connection-status/internet-connection-status.component.spec.ts @@ -0,0 +1,88 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { InternetConnectionStatusComponent } from './internet-connection-status.component'; +import { ToastrService } from 'ngx-toastr'; +import { of } from 'rxjs'; + +describe('InternetConnectionStatusComponent', () => { + let component: InternetConnectionStatusComponent; + let fixture: ComponentFixture; + const toastrServiceStub = { + error: () => { + return 'test error'; + }, + warning: () => { + return 'warning error'; + }, + success: () => { + return 'success error'; + } + }; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ InternetConnectionStatusComponent ], + providers: [{ provide: ToastrService, useValue: toastrServiceStub }] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(InternetConnectionStatusComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should show a stable connection warning', () => { + component.connection$ = of('4g'); + fixture.detectChanges(); + component.ngOnInit(); + expect(component.isFast).toBe(true); + }); + + it('should show a slow connection warning', () => { + component.connection$ = of('2g'); + fixture.detectChanges(); + component.ngOnInit(); + expect(component.isFast).toBe(false); + }); + + it('should show offline warning', () => { + component.connection$ = of('Offline'); + fixture.detectChanges(); + component.ngOnInit(); + expect(component.isFast).toBe(false); + }); + + it('should change the network type', () => { + component.connection$ = of('5g'); + fixture.detectChanges(); + component.ngOnInit(); + component.connection$.subscribe((networkType: string) => { + expect(networkType).toEqual('5g'); + }); + + jasmine.clock().install(); + jasmine.clock().tick(300); + + component.connection$ = of('2g'); + fixture.detectChanges(); + console.log(window.navigator); + component.connection$.subscribe((networkType: string) => { + expect(networkType).toEqual('2g'); + }); + + jasmine.clock().uninstall(); + }); + + it('should return when window.navigator.connection is undefined', () => { + const attributeCustome = '__defineGetter__'; + window.navigator[attributeCustome]('connection', () => { + return undefined; + }); + fixture = TestBed.createComponent(InternetConnectionStatusComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + const statusInit = component.ngOnInit(); + expect(statusInit).toEqual(undefined); + }); +}); diff --git a/src/app/modules/internet-connection-status/internet-connection-status.component.ts b/src/app/modules/internet-connection-status/internet-connection-status.component.ts new file mode 100644 index 000000000..df29a9b1d --- /dev/null +++ b/src/app/modules/internet-connection-status/internet-connection-status.component.ts @@ -0,0 +1,85 @@ +import { Component, OnInit, ContentChild, Attribute, OnDestroy} from '@angular/core'; +import { FastDirective} from '../../modules/internet-connection-status/internet-connection-directives/fast.directive'; +import { SlowDirective} from '../../modules/internet-connection-status/internet-connection-directives/slow.directive'; +import { OfflineDirective} from '../../modules/internet-connection-status/internet-connection-directives/offline.directive'; +import { Observable, of, Subscription } from 'rxjs'; +import { take, map } from 'rxjs/operators'; +import { ToastrService } from 'ngx-toastr'; + +type Connection = { + effectiveType: string; +}; + +declare global { + interface Navigator { + connection: { + effectiveType: string; + addEventListener: (a: any, b: any) => {}; + removeEventListener: (a: any, b: any) => {}; + }; + } +} + + +@Component({ + selector: 'app-internet-connection-status', + templateUrl: './internet-connection-status.component.html', + styleUrls: ['./internet-connection-status.component.scss'] +}) +export class InternetConnectionStatusComponent implements OnInit { + isFast = true; + connectionType: string; + networkType: string; + @ContentChild(FastDirective) fast: FastDirective; + @ContentChild(SlowDirective) slow: SlowDirective; + @ContentChild(OfflineDirective) offline: OfflineDirective; + + private subscription: Subscription; + + constructor(@Attribute('listen') private withChanges: boolean, private toastrService: ToastrService) { + } + + connection$ = new Observable((observer) => { + const { effectiveType } = navigator.connection; + observer.next(effectiveType); + + const onConnectionChange = () => { + this.networkType = navigator.connection.effectiveType; + observer.next(this.networkType); + }; + + navigator.connection.addEventListener('change', onConnectionChange); + + return () => { + navigator.connection.removeEventListener('change', onConnectionChange); + observer.complete(); + }; + }); + + ngOnInit() { + const connection = navigator.connection; + console.log('navigator component', connection); + if (!connection || !connection.effectiveType) { + return; + } + + this.subscription = this.connection$ + .pipe(take(this.withChanges ? Number.POSITIVE_INFINITY : 1)) + .subscribe((effectiveType: string) => { + + this.connectionType = effectiveType; + + if (/\fast-5g|3g|4g/.test(effectiveType)){ + this.toastrService.success('You have a good connection'); + this.isFast = true; + }else if (/\slow-2g|2g/.test(effectiveType)) { + this.toastrService.warning('Caution your connection is slow'); + this.isFast = false; + } else { + this.toastrService.error('You are offline'); + this.isFast = false; + } + }); + } + +} From e04763fa4bd81a97009009b4388fa7cce91fc1ad Mon Sep 17 00:00:00 2001 From: Abigail Cabascango Date: Mon, 22 Aug 2022 13:12:35 -0500 Subject: [PATCH 02/17] TTA-115 implement a stable, slow or offline connection warning --- src/app/app.component.html | 12 +++ src/app/app.module.ts | 11 +++ .../connection.directive.ts | 29 ++++++ .../fast.directive.ts | 11 +++ .../offline.directive.ts | 11 +++ .../slow.directive.ts | 11 +++ .../internet-connection-status.component.html | 0 .../internet-connection-status.component.scss | 0 ...ternet-connection-status.component.spec.ts | 88 +++++++++++++++++++ .../internet-connection-status.component.ts | 85 ++++++++++++++++++ 10 files changed, 258 insertions(+) create mode 100644 src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts create mode 100644 src/app/modules/internet-connection-status/internet-connection-directives/fast.directive.ts create mode 100644 src/app/modules/internet-connection-status/internet-connection-directives/offline.directive.ts create mode 100644 src/app/modules/internet-connection-status/internet-connection-directives/slow.directive.ts create mode 100644 src/app/modules/internet-connection-status/internet-connection-status.component.html create mode 100644 src/app/modules/internet-connection-status/internet-connection-status.component.scss create mode 100644 src/app/modules/internet-connection-status/internet-connection-status.component.spec.ts create mode 100644 src/app/modules/internet-connection-status/internet-connection-status.component.ts diff --git a/src/app/app.component.html b/src/app/app.component.html index 0680b43f9..199f49375 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1 +1,13 @@ + + + + + + + + + + + + diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 391675003..b97b68920 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -95,6 +95,12 @@ import { SearchUserComponent } from './modules/shared/components/search-user/sea import { TimeRangeCustomComponent } from './modules/reports/components/time-range-custom/time-range-custom.component'; import { TimeRangeHeaderComponent } from './modules/reports/components/time-range-custom/time-range-header/time-range-header.component'; import { TimeRangeOptionsComponent } from './modules/reports/components/time-range-custom/time-range-options/time-range-options.component'; +import { InternetConnectionStatusComponent } from './modules/internet-connection-status/internet-connection-status.component'; +import { FastDirective} from './modules/internet-connection-status/internet-connection-directives/fast.directive'; +import { SlowDirective} from './modules/internet-connection-status/internet-connection-directives/slow.directive'; +import { OfflineDirective} from './modules/internet-connection-status/internet-connection-directives/offline.directive'; +import { ConnectionDirective } from './modules/internet-connection-status/internet-connection-directives/connection.directive'; + const maskConfig: Partial = { validation: false, @@ -154,6 +160,11 @@ const maskConfig: Partial = { TimeRangeCustomComponent, TimeRangeHeaderComponent, TimeRangeOptionsComponent, + InternetConnectionStatusComponent, + SlowDirective, + FastDirective, + OfflineDirective, + ConnectionDirective ], imports: [ NgxMaskModule.forRoot(maskConfig), diff --git a/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts b/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts new file mode 100644 index 000000000..569540db1 --- /dev/null +++ b/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts @@ -0,0 +1,29 @@ +import { Directive, Attribute, ElementRef, OnInit } from '@angular/core'; + +@Directive({ + selector: '[appConnection]' +}) + +export class ConnectionDirective implements OnInit { + constructor( + @Attribute('slowSrc') private slowSrc, + @Attribute('fastSrc') private fastSrc, + @Attribute('offlineSrc') private offlineSrc, + private host: ElementRef + ) { + } + + ngOnInit() { + const { effectiveType } = navigator.connection; + let src; + if (/\fast-5g|3g|4g/.test(effectiveType)) { + src = this.fastSrc; + }else if (/\slow-2g|2g/.test(effectiveType)) { + src = this.slowSrc; + }else { + src = this.offlineSrc; + } + this.host.nativeElement.setAttribute('src', src); + } + +} diff --git a/src/app/modules/internet-connection-status/internet-connection-directives/fast.directive.ts b/src/app/modules/internet-connection-status/internet-connection-directives/fast.directive.ts new file mode 100644 index 000000000..50faa29a3 --- /dev/null +++ b/src/app/modules/internet-connection-status/internet-connection-directives/fast.directive.ts @@ -0,0 +1,11 @@ +import { Directive, TemplateRef } from '@angular/core'; + +@Directive({ + selector: '[appFast]' +}) + +export class FastDirective { + + constructor(public tpl: TemplateRef) { } + +} diff --git a/src/app/modules/internet-connection-status/internet-connection-directives/offline.directive.ts b/src/app/modules/internet-connection-status/internet-connection-directives/offline.directive.ts new file mode 100644 index 000000000..986c8542c --- /dev/null +++ b/src/app/modules/internet-connection-status/internet-connection-directives/offline.directive.ts @@ -0,0 +1,11 @@ +import { Directive, TemplateRef } from '@angular/core'; + +@Directive({ + selector: '[appOffline]' +}) + +export class OfflineDirective { + + constructor(public tpl: TemplateRef) { } + +} diff --git a/src/app/modules/internet-connection-status/internet-connection-directives/slow.directive.ts b/src/app/modules/internet-connection-status/internet-connection-directives/slow.directive.ts new file mode 100644 index 000000000..9095e34a1 --- /dev/null +++ b/src/app/modules/internet-connection-status/internet-connection-directives/slow.directive.ts @@ -0,0 +1,11 @@ +import { Directive, TemplateRef } from '@angular/core'; + +@Directive({ + selector: '[appSlow]' +}) + +export class SlowDirective { + + constructor(public tpl: TemplateRef) { } + +} diff --git a/src/app/modules/internet-connection-status/internet-connection-status.component.html b/src/app/modules/internet-connection-status/internet-connection-status.component.html new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/modules/internet-connection-status/internet-connection-status.component.scss b/src/app/modules/internet-connection-status/internet-connection-status.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/modules/internet-connection-status/internet-connection-status.component.spec.ts b/src/app/modules/internet-connection-status/internet-connection-status.component.spec.ts new file mode 100644 index 000000000..fb212617c --- /dev/null +++ b/src/app/modules/internet-connection-status/internet-connection-status.component.spec.ts @@ -0,0 +1,88 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { InternetConnectionStatusComponent } from './internet-connection-status.component'; +import { ToastrService } from 'ngx-toastr'; +import { of } from 'rxjs'; + +describe('InternetConnectionStatusComponent', () => { + let component: InternetConnectionStatusComponent; + let fixture: ComponentFixture; + const toastrServiceStub = { + error: () => { + return 'test error'; + }, + warning: () => { + return 'warning error'; + }, + success: () => { + return 'success error'; + } + }; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ InternetConnectionStatusComponent ], + providers: [{ provide: ToastrService, useValue: toastrServiceStub }] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(InternetConnectionStatusComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should show a stable connection warning', () => { + component.connection$ = of('4g'); + fixture.detectChanges(); + component.ngOnInit(); + expect(component.isFast).toBe(true); + }); + + it('should show a slow connection warning', () => { + component.connection$ = of('2g'); + fixture.detectChanges(); + component.ngOnInit(); + expect(component.isFast).toBe(false); + }); + + it('should show offline warning', () => { + component.connection$ = of('Offline'); + fixture.detectChanges(); + component.ngOnInit(); + expect(component.isFast).toBe(false); + }); + + it('should change the network type', () => { + component.connection$ = of('5g'); + fixture.detectChanges(); + component.ngOnInit(); + component.connection$.subscribe((networkType: string) => { + expect(networkType).toEqual('5g'); + }); + + jasmine.clock().install(); + jasmine.clock().tick(300); + + component.connection$ = of('2g'); + fixture.detectChanges(); + console.log(window.navigator); + component.connection$.subscribe((networkType: string) => { + expect(networkType).toEqual('2g'); + }); + + jasmine.clock().uninstall(); + }); + + it('should return when window.navigator.connection is undefined', () => { + const attributeCustome = '__defineGetter__'; + window.navigator[attributeCustome]('connection', () => { + return undefined; + }); + fixture = TestBed.createComponent(InternetConnectionStatusComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + const statusInit = component.ngOnInit(); + expect(statusInit).toEqual(undefined); + }); +}); diff --git a/src/app/modules/internet-connection-status/internet-connection-status.component.ts b/src/app/modules/internet-connection-status/internet-connection-status.component.ts new file mode 100644 index 000000000..df29a9b1d --- /dev/null +++ b/src/app/modules/internet-connection-status/internet-connection-status.component.ts @@ -0,0 +1,85 @@ +import { Component, OnInit, ContentChild, Attribute, OnDestroy} from '@angular/core'; +import { FastDirective} from '../../modules/internet-connection-status/internet-connection-directives/fast.directive'; +import { SlowDirective} from '../../modules/internet-connection-status/internet-connection-directives/slow.directive'; +import { OfflineDirective} from '../../modules/internet-connection-status/internet-connection-directives/offline.directive'; +import { Observable, of, Subscription } from 'rxjs'; +import { take, map } from 'rxjs/operators'; +import { ToastrService } from 'ngx-toastr'; + +type Connection = { + effectiveType: string; +}; + +declare global { + interface Navigator { + connection: { + effectiveType: string; + addEventListener: (a: any, b: any) => {}; + removeEventListener: (a: any, b: any) => {}; + }; + } +} + + +@Component({ + selector: 'app-internet-connection-status', + templateUrl: './internet-connection-status.component.html', + styleUrls: ['./internet-connection-status.component.scss'] +}) +export class InternetConnectionStatusComponent implements OnInit { + isFast = true; + connectionType: string; + networkType: string; + @ContentChild(FastDirective) fast: FastDirective; + @ContentChild(SlowDirective) slow: SlowDirective; + @ContentChild(OfflineDirective) offline: OfflineDirective; + + private subscription: Subscription; + + constructor(@Attribute('listen') private withChanges: boolean, private toastrService: ToastrService) { + } + + connection$ = new Observable((observer) => { + const { effectiveType } = navigator.connection; + observer.next(effectiveType); + + const onConnectionChange = () => { + this.networkType = navigator.connection.effectiveType; + observer.next(this.networkType); + }; + + navigator.connection.addEventListener('change', onConnectionChange); + + return () => { + navigator.connection.removeEventListener('change', onConnectionChange); + observer.complete(); + }; + }); + + ngOnInit() { + const connection = navigator.connection; + console.log('navigator component', connection); + if (!connection || !connection.effectiveType) { + return; + } + + this.subscription = this.connection$ + .pipe(take(this.withChanges ? Number.POSITIVE_INFINITY : 1)) + .subscribe((effectiveType: string) => { + + this.connectionType = effectiveType; + + if (/\fast-5g|3g|4g/.test(effectiveType)){ + this.toastrService.success('You have a good connection'); + this.isFast = true; + }else if (/\slow-2g|2g/.test(effectiveType)) { + this.toastrService.warning('Caution your connection is slow'); + this.isFast = false; + } else { + this.toastrService.error('You are offline'); + this.isFast = false; + } + }); + } + +} From 84bde1c347673ad53ce11563ac80744b29f7c171 Mon Sep 17 00:00:00 2001 From: Abigail Cabascango Date: Tue, 6 Sep 2022 11:08:40 -0500 Subject: [PATCH 03/17] TTA-115 Refactor end points --- .../projects-type/services/project-type.service.ts | 9 ++++++--- .../internet-connection-status.component.ts | 7 +++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/app/modules/customer-management/components/projects-type/services/project-type.service.ts b/src/app/modules/customer-management/components/projects-type/services/project-type.service.ts index 6d9e672c2..b9240776b 100644 --- a/src/app/modules/customer-management/components/projects-type/services/project-type.service.ts +++ b/src/app/modules/customer-management/components/projects-type/services/project-type.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs'; - +import { map, catchError } from 'rxjs/operators'; import { environment } from '../../../../../../environments/environment'; import { ProjectType } from '../../../../shared/models'; @@ -15,7 +15,10 @@ export class ProjectTypeService { getProjectTypes(customerId: any): Observable { const params = new HttpParams().set('customer_id', customerId.customerId); - return this.http.get(this.baseUrl, { params }); + return this.http.get(this.baseUrl, { params }).pipe(map((data: { status: any; }) => { + console.log("Here will be return response code Ex :200", data.status) + return data.status + })); } createProjectType(projectTypeData): Observable { @@ -29,6 +32,6 @@ export class ProjectTypeService { updateProjectType(projectTypeData): Observable { const url = `${this.baseUrl}/${projectTypeData.id}`; - return this.http.put(url, projectTypeData); + return this.http.put(url, projectTypeData) } } diff --git a/src/app/modules/internet-connection-status/internet-connection-status.component.ts b/src/app/modules/internet-connection-status/internet-connection-status.component.ts index df29a9b1d..e1968b0eb 100644 --- a/src/app/modules/internet-connection-status/internet-connection-status.component.ts +++ b/src/app/modules/internet-connection-status/internet-connection-status.component.ts @@ -56,7 +56,11 @@ export class InternetConnectionStatusComponent implements OnInit { }; }); - ngOnInit() { + ngOnInit(){ + // $scope, $http + // $scope.isLoading = function () { + // return $http.pendingRequests.length !== 0; + // }; const connection = navigator.connection; console.log('navigator component', connection); if (!connection || !connection.effectiveType) { @@ -70,7 +74,6 @@ export class InternetConnectionStatusComponent implements OnInit { this.connectionType = effectiveType; if (/\fast-5g|3g|4g/.test(effectiveType)){ - this.toastrService.success('You have a good connection'); this.isFast = true; }else if (/\slow-2g|2g/.test(effectiveType)) { this.toastrService.warning('Caution your connection is slow'); From da0522a8500fa738b7581811236756b6f00e2930 Mon Sep 17 00:00:00 2001 From: Abigail Cabascango Date: Mon, 12 Sep 2022 10:07:52 -0500 Subject: [PATCH 04/17] feat: TTA-115 implement notification when the endpoint fails for a slow connection --- .../store/activity-management.effects.ts | 14 ++++---- .../services/project-type.service.ts | 5 +-- .../store/project-type.effects.ts | 12 ++++--- .../components/store/project.effects.ts | 18 +++++----- .../store/customer-management.effects.ts | 14 ++++---- .../internet-connection-status.component.ts | 7 +--- .../services/status-network.service.spec.ts | 16 +++++++++ .../shared/services/status-network.service.ts | 33 +++++++++++++++++++ .../modules/time-clock/store/entry.effects.ts | 31 +++++++++-------- src/app/modules/users/store/user.effects.ts | 23 +++++++++---- 10 files changed, 119 insertions(+), 54 deletions(-) create mode 100644 src/app/modules/shared/services/status-network.service.spec.ts create mode 100644 src/app/modules/shared/services/status-network.service.ts diff --git a/src/app/modules/activities-management/store/activity-management.effects.ts b/src/app/modules/activities-management/store/activity-management.effects.ts index 3b16dd15d..df7992fc4 100644 --- a/src/app/modules/activities-management/store/activity-management.effects.ts +++ b/src/app/modules/activities-management/store/activity-management.effects.ts @@ -9,13 +9,15 @@ import { ToastrService } from 'ngx-toastr'; import * as actions from './activity-management.actions'; import { Activity, ActivityStatus } from './../../shared/models/activity.model'; import { ActivityService } from './../services/activity.service'; +import { StatusNetworkService } from '../../shared/services/status-network.service'; @Injectable() export class ActivityEffects { constructor( private actions$: Actions, private activityService: ActivityService, - private toastrService: ToastrService + private toastrService: ToastrService, + private statusNetworkService: StatusNetworkService ) { } @Effect() @@ -27,7 +29,7 @@ export class ActivityEffects { return new actions.LoadActivitiesSuccess(activities); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.LoadActivitiesFail(error)); }) ) @@ -45,7 +47,7 @@ export class ActivityEffects { return new actions.CreateActivitySuccess(activityData); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.CreateActivityFail(error)); }) ) @@ -66,7 +68,7 @@ export class ActivityEffects { return new actions.ArchiveActivitySuccess(activity); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.ArchiveActivityFail(error)); }) ) @@ -84,7 +86,7 @@ export class ActivityEffects { return new actions.UpdateActivitySuccess(activityData); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.UpdateActivityFail(error)); }) ) @@ -106,7 +108,7 @@ export class ActivityEffects { return new actions.UnarchiveActivitySuccess(activityData); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.UnarchiveActivityFail(error)); }) ) diff --git a/src/app/modules/customer-management/components/projects-type/services/project-type.service.ts b/src/app/modules/customer-management/components/projects-type/services/project-type.service.ts index b9240776b..4031fe213 100644 --- a/src/app/modules/customer-management/components/projects-type/services/project-type.service.ts +++ b/src/app/modules/customer-management/components/projects-type/services/project-type.service.ts @@ -15,10 +15,7 @@ export class ProjectTypeService { getProjectTypes(customerId: any): Observable { const params = new HttpParams().set('customer_id', customerId.customerId); - return this.http.get(this.baseUrl, { params }).pipe(map((data: { status: any; }) => { - console.log("Here will be return response code Ex :200", data.status) - return data.status - })); + return this.http.get(this.baseUrl, { params }); } createProjectType(projectTypeData): Observable { diff --git a/src/app/modules/customer-management/components/projects-type/store/project-type.effects.ts b/src/app/modules/customer-management/components/projects-type/store/project-type.effects.ts index d11294c8a..b9afd3710 100644 --- a/src/app/modules/customer-management/components/projects-type/store/project-type.effects.ts +++ b/src/app/modules/customer-management/components/projects-type/store/project-type.effects.ts @@ -9,13 +9,15 @@ import * as actions from './project-type.actions'; import { ProjectType } from '../../../../shared/models'; import { ProjectTypeService } from '../services/project-type.service'; import { ToastrService } from 'ngx-toastr'; +import { StatusNetworkService } from '../../../../shared/services/status-network.service'; @Injectable() export class ProjectTypeEffects { constructor( private actions$: Actions, private projectTypeService: ProjectTypeService, - private toastrService: ToastrService + private toastrService: ToastrService, + private statusNetworkService: StatusNetworkService ) { } @Effect() @@ -27,7 +29,7 @@ export class ProjectTypeEffects { return new actions.LoadProjectTypesSuccess(projectTypes); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.LoadProjectTypesFail(error)); }) ) @@ -45,7 +47,7 @@ export class ProjectTypeEffects { return new actions.CreateProjectTypeSuccess(projectTypeData); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.CreateProjectTypeFail(error)); }) ) @@ -63,7 +65,7 @@ export class ProjectTypeEffects { return new actions.DeleteProjectTypeSuccess(protectTypeId); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.DeleteProjectTypeFail(error)); }) ) @@ -81,7 +83,7 @@ export class ProjectTypeEffects { return new actions.UpdateProjectTypeSuccess(projectTypeData); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.UpdateProjectTypeFail(error)); }) ) diff --git a/src/app/modules/customer-management/components/projects/components/store/project.effects.ts b/src/app/modules/customer-management/components/projects/components/store/project.effects.ts index 5067b1b85..d9900617a 100644 --- a/src/app/modules/customer-management/components/projects/components/store/project.effects.ts +++ b/src/app/modules/customer-management/components/projects/components/store/project.effects.ts @@ -8,13 +8,15 @@ import { ProjectService } from '../services/project.service'; import * as actions from './project.actions'; import { ToastrService } from 'ngx-toastr'; import { Status } from 'src/app/modules/shared/models'; +import { StatusNetworkService } from '../../../../../shared/services/status-network.service'; @Injectable() export class ProjectEffects { constructor( private actions$: Actions, private projectService: ProjectService, - private toastrService: ToastrService + private toastrService: ToastrService, + private statusNetworkService: StatusNetworkService ) { } @Effect() @@ -26,7 +28,7 @@ export class ProjectEffects { return new actions.LoadProjectsSuccess(projects); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.LoadProjectsFail(error)); }) ) @@ -42,7 +44,7 @@ export class ProjectEffects { return new actions.LoadCustomerProjectsSuccess(project); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.LoadCustomerProjectsFail(error)); }) ) @@ -58,7 +60,7 @@ export class ProjectEffects { return new actions.LoadRecentProjectsSuccess(projects); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.LoadRecentProjectsFail(error)); }) ) @@ -76,7 +78,7 @@ export class ProjectEffects { return new actions.CreateProjectSuccess(projectData); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.CreateProjectFail(error)); }) ) @@ -94,7 +96,7 @@ export class ProjectEffects { return new actions.UpdateProjectSuccess(projectData); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.UpdateProjectFail(error)); }) ) @@ -112,7 +114,7 @@ export class ProjectEffects { return new actions.DeleteProjectSuccess(projectId); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.DeleteProjectFail(error)); }) ) @@ -133,7 +135,7 @@ export class ProjectEffects { return new actions.UnarchiveProjectSuccess(projectData); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.UnarchiveProjectFail(error)); }) ) diff --git a/src/app/modules/customer-management/store/customer-management.effects.ts b/src/app/modules/customer-management/store/customer-management.effects.ts index 7485396b7..6635b9bbb 100644 --- a/src/app/modules/customer-management/store/customer-management.effects.ts +++ b/src/app/modules/customer-management/store/customer-management.effects.ts @@ -9,13 +9,15 @@ import { ToastrService } from 'ngx-toastr'; import { CustomerService } from '../services/customer.service'; import * as actions from './customer-management.actions'; import { Status } from '../../shared/models/customer.model'; +import { StatusNetworkService } from '../../shared/services/status-network.service'; @Injectable() export class CustomerEffects { constructor( private actions$: Actions, private customerService: CustomerService, - private toastrService: ToastrService + private toastrService: ToastrService, + private statusNetworkService: StatusNetworkService ) { } @Effect() @@ -27,7 +29,7 @@ export class CustomerEffects { return new actions.LoadCustomersSuccess(customers); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.LoadCustomersFail(error)); } ) @@ -46,7 +48,7 @@ export class CustomerEffects { return new actions.CreateCustomerSuccess(customerData); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.CreateCustomerFail(error)); }) ) @@ -64,7 +66,7 @@ export class CustomerEffects { return new actions.DeleteCustomerSuccesss(customerId); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.DeleteCustomerFail(error)); }) ) @@ -82,7 +84,7 @@ export class CustomerEffects { return new actions.UpdateCustomerSuccess(customerData); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.UpdateCustomerFail(error)); }) ) @@ -104,7 +106,7 @@ export class CustomerEffects { return new actions.UpdateCustomerSuccess(customerData); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.UpdateCustomerFail(error)); }) ) diff --git a/src/app/modules/internet-connection-status/internet-connection-status.component.ts b/src/app/modules/internet-connection-status/internet-connection-status.component.ts index e1968b0eb..cdc7a6c74 100644 --- a/src/app/modules/internet-connection-status/internet-connection-status.component.ts +++ b/src/app/modules/internet-connection-status/internet-connection-status.component.ts @@ -57,10 +57,6 @@ export class InternetConnectionStatusComponent implements OnInit { }); ngOnInit(){ - // $scope, $http - // $scope.isLoading = function () { - // return $http.pendingRequests.length !== 0; - // }; const connection = navigator.connection; console.log('navigator component', connection); if (!connection || !connection.effectiveType) { @@ -79,10 +75,9 @@ export class InternetConnectionStatusComponent implements OnInit { this.toastrService.warning('Caution your connection is slow'); this.isFast = false; } else { - this.toastrService.error('You are offline'); + this.toastrService.error('Your request was not completed, you are offline'); this.isFast = false; } }); } - } diff --git a/src/app/modules/shared/services/status-network.service.spec.ts b/src/app/modules/shared/services/status-network.service.spec.ts new file mode 100644 index 000000000..3918ba401 --- /dev/null +++ b/src/app/modules/shared/services/status-network.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { StatusNetworkService } from './status-network.service'; + +describe('StatusNetworkService', () => { + let service: StatusNetworkService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(StatusNetworkService); + }); + + fit('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/modules/shared/services/status-network.service.ts b/src/app/modules/shared/services/status-network.service.ts new file mode 100644 index 000000000..0297375d9 --- /dev/null +++ b/src/app/modules/shared/services/status-network.service.ts @@ -0,0 +1,33 @@ +import { Injectable } from '@angular/core'; +import { ToastrService } from 'ngx-toastr'; + +export interface ErrorType { + error: any; + message?: string; + isError?: boolean; +} + +@Injectable({ + providedIn: 'root' +}) +export class StatusNetworkService { + + constructor( + private toastrService: ToastrService + ) { } + + checkTypeError(dataError: ErrorType){ + const { isError = false, message = 'The server is disconnected', error} = dataError; + const effectiveTypenetwork = navigator.connection; + if(effectiveTypenetwork.effectiveType === '2g'){ + this.toastrService.warning('Your request was not completed, your connection is slow'); + }else{ + if(isError){ + const errorMessa = error.error && error.error.message? error.error.message: 'There is an error with the server, your request have not be completed'; + this.toastrService.error(errorMessa); + }else{ + this.toastrService.warning(message); + } + } + } +} diff --git a/src/app/modules/time-clock/store/entry.effects.ts b/src/app/modules/time-clock/store/entry.effects.ts index 40c1cb1c9..b83dba6da 100644 --- a/src/app/modules/time-clock/store/entry.effects.ts +++ b/src/app/modules/time-clock/store/entry.effects.ts @@ -8,11 +8,16 @@ import { catchError, map, mergeMap, switchMap } from 'rxjs/operators'; import { EntryService } from '../services/entry.service'; import * as actions from './entry.actions'; import * as moment from 'moment'; +import { StatusNetworkService } from '../../shared/services/status-network.service'; @Injectable() export class EntryEffects { - constructor(private actions$: Actions, private entryService: EntryService, private toastrService: ToastrService) { - } + constructor( + private actions$: Actions, + private entryService: EntryService, + private toastrService: ToastrService, + private statusNetworkService: StatusNetworkService + ) { } @Effect() switchEntryRunning$: Observable = this.actions$.pipe( @@ -32,7 +37,7 @@ export class EntryEffects { return new actions.ClockIn(entry); }), catchError((error) => { - this.toastrService.warning('We could not perform this operation, try again later'); + this.statusNetworkService.checkTypeError({error, message: 'We could not perform this operation, try again later', isError: false}); return of(new actions.StopTimeEntryRunningFail(error)); }) ) @@ -48,7 +53,7 @@ export class EntryEffects { return new actions.LoadEntriesSummarySuccess(response); }), catchError((error) => { - this.toastrService.warning('Your summary information could not be loaded'); + this.statusNetworkService.checkTypeError({error, message: 'Your summary information could not be loaded', isError: false}); return of(new actions.LoadEntriesSummaryFail()); }) ) @@ -93,7 +98,7 @@ export class EntryEffects { this.entryService.loadEntries({ month: date.month, year: date.year }).pipe( map((entries) => new actions.LoadEntriesSuccess(entries)), catchError((error) => { - this.toastrService.warning(`The data could not be loaded`); + this.statusNetworkService.checkTypeError({error, message: 'The data could not be loaded', isError: false}); return of(new actions.LoadEntriesFail(error)); }) ) @@ -115,7 +120,7 @@ export class EntryEffects { return new actions.CreateEntrySuccess(entryData); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.CreateEntryFail(error.error.message)); }) ) @@ -143,7 +148,7 @@ export class EntryEffects { if (error.status === 404) { return of(new actions.CreateEntry(entry)); } else { - this.toastrService.error('We could not clock you in, try again later.'); + this.statusNetworkService.checkTypeError({error, message: 'We could not clock you in, try again later.', isError: true}); return of(new actions.CreateEntryFail('Error')); } }) @@ -162,7 +167,7 @@ export class EntryEffects { return new actions.DeleteEntrySuccess(entryId); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.DeleteEntryFail(error)); }) ) @@ -180,7 +185,7 @@ export class EntryEffects { return new actions.UpdateEntrySuccess(entryResponse); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.UpdateEntryFail(error)); }) ) @@ -198,7 +203,7 @@ export class EntryEffects { return new actions.UpdateEntrySuccess(entryResponse); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.UpdateEntryFail(error)); }) ) @@ -216,7 +221,7 @@ export class EntryEffects { return new actions.StopTimeEntryRunningSuccess(response); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.StopTimeEntryRunningFail(error.error.message)); }) ) @@ -243,7 +248,7 @@ export class EntryEffects { } }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); return of(new actions.UpdateCurrentOrLastEntryFail('error')); }) ) @@ -276,7 +281,7 @@ export class EntryEffects { return new actions.RestartEntrySuccess(entryResponse); }), catchError((error) => { - this.toastrService.error(error.error.message, 'This entry could not be restarted'); + this.statusNetworkService.checkTypeError({error, message: 'This entry could not be restarted', isError: true}); return of(new actions.RestartEntryFail(error)); }) ) diff --git a/src/app/modules/users/store/user.effects.ts b/src/app/modules/users/store/user.effects.ts index 87f97eaef..c6ea1ccd9 100644 --- a/src/app/modules/users/store/user.effects.ts +++ b/src/app/modules/users/store/user.effects.ts @@ -7,10 +7,16 @@ import { map, catchError, mergeMap } from 'rxjs/operators'; import { ToastrService } from 'ngx-toastr'; import { UsersService } from '../services/users.service'; import * as actions from './user.actions'; +import { StatusNetworkService } from '../../shared/services/status-network.service'; @Injectable() export class UserEffects { - constructor(private actions$: Actions, private userService: UsersService, private toastrService: ToastrService) {} + constructor( + private actions$: Actions, + private userService: UsersService, + private toastrService: ToastrService, + private statusNetworkService: StatusNetworkService + ) {} @Effect() loadUsers$: Observable = this.actions$.pipe( @@ -21,7 +27,8 @@ export class UserEffects { return new actions.LoadUsersSuccess(users); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); + //this.toastrService.error(error.error.message); return of(new actions.LoadUsersFail(error)); }) ) @@ -39,7 +46,8 @@ export class UserEffects { return new actions.AddUserToGroupSuccess(response); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); + //this.toastrService.error(error.error.message); return of(new actions.AddUserToGroupFail(error)); }) ) @@ -57,7 +65,8 @@ export class UserEffects { return new actions.RemoveUserFromGroupSuccess(response); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); + //this.toastrService.error(error.error.message); return of(new actions.RemoveUserFromGroupFail(error)); }) ) @@ -75,7 +84,8 @@ export class UserEffects { return new actions.GrantUserRoleSuccess(response); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); + //this.toastrService.error(error.error.message); return of(new actions.GrantUserRoleFail(error)); }) ) @@ -93,7 +103,8 @@ export class UserEffects { return new actions.RevokeUserRoleSuccess(response); }), catchError((error) => { - this.toastrService.error(error.error.message); + this.statusNetworkService.checkTypeError({error, isError: true}); + //this.toastrService.error(error.error.message); return of(new actions.RevokeUserRoleFail(error)); }) ) From 4665966aed4e4893628f7a4642573bbc6639c739 Mon Sep 17 00:00:00 2001 From: Abigail Cabascango Date: Wed, 5 Oct 2022 12:22:40 -0500 Subject: [PATCH 05/17] refactor: TTA-115 the if clausses in status network service and connection directive and their component --- .../connection.directive.ts | 20 ++++++++++++------- .../internet-connection-status.component.ts | 12 +++++++---- .../services/status-network.service.spec.ts | 12 +++++++++-- .../shared/services/status-network.service.ts | 13 +++++++----- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts b/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts index 569540db1..0e05f1baf 100644 --- a/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts +++ b/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts @@ -15,15 +15,21 @@ export class ConnectionDirective implements OnInit { ngOnInit() { const { effectiveType } = navigator.connection; - let src; + let networkSatus; + if (!(/\fast-5g|3g|4g/.test(effectiveType)) || !(/\slow-2g|2g/.test(effectiveType))){ + networkSatus = this.offlineSrc; + return + } + if (/\fast-5g|3g|4g/.test(effectiveType)) { - src = this.fastSrc; - }else if (/\slow-2g|2g/.test(effectiveType)) { - src = this.slowSrc; - }else { - src = this.offlineSrc; + networkSatus = this.fastSrc; } - this.host.nativeElement.setAttribute('src', src); + + if (/\slow-2g|2g/.test(effectiveType)) { + networkSatus = this.slowSrc; + } + + this.host.nativeElement.setAttribute('src', networkSatus); } } diff --git a/src/app/modules/internet-connection-status/internet-connection-status.component.ts b/src/app/modules/internet-connection-status/internet-connection-status.component.ts index cdc7a6c74..1e3a70425 100644 --- a/src/app/modules/internet-connection-status/internet-connection-status.component.ts +++ b/src/app/modules/internet-connection-status/internet-connection-status.component.ts @@ -68,15 +68,19 @@ export class InternetConnectionStatusComponent implements OnInit { .subscribe((effectiveType: string) => { this.connectionType = effectiveType; + + if (!(/\fast-5g|3g|4g/.test(effectiveType)) || !(/\slow-2g|2g/.test(effectiveType))){ + this.toastrService.error('Your request was not completed, you are offline'); + this.isFast = false; + } if (/\fast-5g|3g|4g/.test(effectiveType)){ this.isFast = true; - }else if (/\slow-2g|2g/.test(effectiveType)) { + } + + if (/\slow-2g|2g/.test(effectiveType)) { this.toastrService.warning('Caution your connection is slow'); this.isFast = false; - } else { - this.toastrService.error('Your request was not completed, you are offline'); - this.isFast = false; } }); } diff --git a/src/app/modules/shared/services/status-network.service.spec.ts b/src/app/modules/shared/services/status-network.service.spec.ts index 3918ba401..7179d82eb 100644 --- a/src/app/modules/shared/services/status-network.service.spec.ts +++ b/src/app/modules/shared/services/status-network.service.spec.ts @@ -1,16 +1,24 @@ import { TestBed } from '@angular/core/testing'; +import * as assert from 'assert'; +import { catchError, map, mergeMap } from 'rxjs/operators'; import { StatusNetworkService } from './status-network.service'; +export interface ErrorType { + error: any; + message?: string; + isError?: boolean; +} describe('StatusNetworkService', () => { let service: StatusNetworkService; + const errorType: ErrorType = {error: catchError, message: 'javascript', isError: false}; beforeEach(() => { TestBed.configureTestingModule({}); service = TestBed.inject(StatusNetworkService); }); - fit('should be created', () => { - expect(service).toBeTruthy(); + fit('checkTypeError is warning', () => { + assert(service.checkTypeError(errorType) == 'is warning'); }); }); diff --git a/src/app/modules/shared/services/status-network.service.ts b/src/app/modules/shared/services/status-network.service.ts index 0297375d9..5b8ee773f 100644 --- a/src/app/modules/shared/services/status-network.service.ts +++ b/src/app/modules/shared/services/status-network.service.ts @@ -19,15 +19,18 @@ export class StatusNetworkService { checkTypeError(dataError: ErrorType){ const { isError = false, message = 'The server is disconnected', error} = dataError; const effectiveTypenetwork = navigator.connection; - if(effectiveTypenetwork.effectiveType === '2g'){ - this.toastrService.warning('Your request was not completed, your connection is slow'); - }else{ + if ((effectiveTypenetwork.effectiveType != '2g')){ + if(!isError){ + this.toastrService.warning(message); + return 'is warning'; + } if(isError){ const errorMessa = error.error && error.error.message? error.error.message: 'There is an error with the server, your request have not be completed'; this.toastrService.error(errorMessa); - }else{ - this.toastrService.warning(message); + return 'is error'; } } + this.toastrService.warning('Your request was not completed, your connection is slow'); + return 'is warning'; } } From 07809f536fb5c715c24ec510a8e25994605ac0d3 Mon Sep 17 00:00:00 2001 From: Abigail Cabascango Date: Thu, 6 Oct 2022 12:27:35 -0500 Subject: [PATCH 06/17] refactor: TTA-115 create unit test for function checkTypeError in status network service --- src/app/app.module.ts | 3 ++- .../services/status-network.service.spec.ts | 25 ++++++++++++++++--- .../shared/services/status-network.service.ts | 5 +--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index b97b68920..89d6559c1 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -100,7 +100,7 @@ import { FastDirective} from './modules/internet-connection-status/internet-conn import { SlowDirective} from './modules/internet-connection-status/internet-connection-directives/slow.directive'; import { OfflineDirective} from './modules/internet-connection-status/internet-connection-directives/offline.directive'; import { ConnectionDirective } from './modules/internet-connection-status/internet-connection-directives/connection.directive'; - +import { ToastrService } from 'ngx-toastr'; const maskConfig: Partial = { validation: false, @@ -219,6 +219,7 @@ const maskConfig: Partial = { }, DatePipe, CookieService, + ToastrService, {provide: Window, useValue: window} ], bootstrap: [AppComponent], diff --git a/src/app/modules/shared/services/status-network.service.spec.ts b/src/app/modules/shared/services/status-network.service.spec.ts index 7179d82eb..2f1bb818c 100644 --- a/src/app/modules/shared/services/status-network.service.spec.ts +++ b/src/app/modules/shared/services/status-network.service.spec.ts @@ -1,7 +1,7 @@ import { TestBed } from '@angular/core/testing'; import * as assert from 'assert'; import { catchError, map, mergeMap } from 'rxjs/operators'; - +import { IndividualConfig, ToastrService } from 'ngx-toastr'; import { StatusNetworkService } from './status-network.service'; export interface ErrorType { @@ -11,14 +11,31 @@ export interface ErrorType { } describe('StatusNetworkService', () => { let service: StatusNetworkService; - const errorType: ErrorType = {error: catchError, message: 'javascript', isError: false}; + const toastrServiceStub = { + error: (message?: string, title?: string, override?: Partial) => { }, + warning: (message?: string, title?: string, override?: Partial) => { } + }; beforeEach(() => { - TestBed.configureTestingModule({}); + TestBed.configureTestingModule({ + providers: [ToastrService, { + provide: ToastrService, useValue: toastrServiceStub + }] + }); service = TestBed.inject(StatusNetworkService); }); + fit('checkTypeError is error', () => { + const errorType: ErrorType = {error: catchError, message: 'javascript', isError: true}; + spyOn(toastrServiceStub, 'error'); + service.checkTypeError(errorType) + expect(toastrServiceStub.error).toHaveBeenCalled(); + }); + fit('checkTypeError is warning', () => { - assert(service.checkTypeError(errorType) == 'is warning'); + const errorType: ErrorType = {error: catchError, message: 'javascript', isError: false}; + spyOn(toastrServiceStub, 'warning'); + service.checkTypeError(errorType) + expect(toastrServiceStub.warning).toHaveBeenCalled(); }); }); diff --git a/src/app/modules/shared/services/status-network.service.ts b/src/app/modules/shared/services/status-network.service.ts index 5b8ee773f..aba6569c9 100644 --- a/src/app/modules/shared/services/status-network.service.ts +++ b/src/app/modules/shared/services/status-network.service.ts @@ -22,15 +22,12 @@ export class StatusNetworkService { if ((effectiveTypenetwork.effectiveType != '2g')){ if(!isError){ this.toastrService.warning(message); - return 'is warning'; } if(isError){ - const errorMessa = error.error && error.error.message? error.error.message: 'There is an error with the server, your request have not be completed'; + const errorMessa = error.error && error.error.message? error.error.message: 'There is an error with the server, your request have not be completed'; this.toastrService.error(errorMessa); - return 'is error'; } } this.toastrService.warning('Your request was not completed, your connection is slow'); - return 'is warning'; } } From fe5b0551edf7025403d7f39170f18d4e1ea3d4a5 Mon Sep 17 00:00:00 2001 From: Abigail Cabascango Date: Thu, 6 Oct 2022 12:30:40 -0500 Subject: [PATCH 07/17] refactor: TTA-115 unit test for function checkTypeError in status network service --- .../services/status-network.service.spec.ts | 8 +++---- .../shared/services/status-network.service.ts | 22 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/app/modules/shared/services/status-network.service.spec.ts b/src/app/modules/shared/services/status-network.service.spec.ts index 2f1bb818c..a5afb5c6c 100644 --- a/src/app/modules/shared/services/status-network.service.spec.ts +++ b/src/app/modules/shared/services/status-network.service.spec.ts @@ -25,17 +25,17 @@ describe('StatusNetworkService', () => { service = TestBed.inject(StatusNetworkService); }); - fit('checkTypeError is error', () => { + it('checkTypeError is error', () => { const errorType: ErrorType = {error: catchError, message: 'javascript', isError: true}; spyOn(toastrServiceStub, 'error'); - service.checkTypeError(errorType) + service.checkTypeError(errorType); expect(toastrServiceStub.error).toHaveBeenCalled(); }); - fit('checkTypeError is warning', () => { + it('checkTypeError is warning', () => { const errorType: ErrorType = {error: catchError, message: 'javascript', isError: false}; spyOn(toastrServiceStub, 'warning'); - service.checkTypeError(errorType) + service.checkTypeError(errorType); expect(toastrServiceStub.warning).toHaveBeenCalled(); }); }); diff --git a/src/app/modules/shared/services/status-network.service.ts b/src/app/modules/shared/services/status-network.service.ts index aba6569c9..b726f3cf9 100644 --- a/src/app/modules/shared/services/status-network.service.ts +++ b/src/app/modules/shared/services/status-network.service.ts @@ -17,17 +17,17 @@ export class StatusNetworkService { ) { } checkTypeError(dataError: ErrorType){ - const { isError = false, message = 'The server is disconnected', error} = dataError; - const effectiveTypenetwork = navigator.connection; - if ((effectiveTypenetwork.effectiveType != '2g')){ - if(!isError){ - this.toastrService.warning(message); - } - if(isError){ - const errorMessa = error.error && error.error.message? error.error.message: 'There is an error with the server, your request have not be completed'; - this.toastrService.error(errorMessa); - } + const { isError = false, message = 'The server is disconnected', error} = dataError; + const effectiveTypenetwork = navigator.connection; + if ((effectiveTypenetwork.effectiveType !== '2g')){ + if (!isError){ + this.toastrService.warning(message); } - this.toastrService.warning('Your request was not completed, your connection is slow'); + if (isError){ + const errorMessa = error.error && error.error.message ? error.error.message : 'There is an error with the server, your request have not be completed'; + this.toastrService.error(errorMessa); + } + } + this.toastrService.warning('Your request was not completed, your connection is slow'); } } From 1d40b7d7e1948ea6dec8bfaff7d53fb8728bff57 Mon Sep 17 00:00:00 2001 From: Abigail Cabascango Date: Thu, 6 Oct 2022 12:35:40 -0500 Subject: [PATCH 08/17] refactor: TTA-115 fix linters errors --- .../internet-connection-directives/connection.directive.ts | 3 +-- .../internet-connection-status.component.ts | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts b/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts index 0e05f1baf..3abf5c366 100644 --- a/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts +++ b/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts @@ -18,13 +18,12 @@ export class ConnectionDirective implements OnInit { let networkSatus; if (!(/\fast-5g|3g|4g/.test(effectiveType)) || !(/\slow-2g|2g/.test(effectiveType))){ networkSatus = this.offlineSrc; - return } if (/\fast-5g|3g|4g/.test(effectiveType)) { networkSatus = this.fastSrc; } - + if (/\slow-2g|2g/.test(effectiveType)) { networkSatus = this.slowSrc; } diff --git a/src/app/modules/internet-connection-status/internet-connection-status.component.ts b/src/app/modules/internet-connection-status/internet-connection-status.component.ts index 1e3a70425..cb0111f4f 100644 --- a/src/app/modules/internet-connection-status/internet-connection-status.component.ts +++ b/src/app/modules/internet-connection-status/internet-connection-status.component.ts @@ -68,7 +68,7 @@ export class InternetConnectionStatusComponent implements OnInit { .subscribe((effectiveType: string) => { this.connectionType = effectiveType; - + if (!(/\fast-5g|3g|4g/.test(effectiveType)) || !(/\slow-2g|2g/.test(effectiveType))){ this.toastrService.error('Your request was not completed, you are offline'); this.isFast = false; From 5f65148a67358dc62fa2ae39d7b469c909853ff9 Mon Sep 17 00:00:00 2001 From: Abigail Cabascango Date: Thu, 6 Oct 2022 15:44:10 -0500 Subject: [PATCH 09/17] refactor: TTA-115 increase test coverage in status network service --- .../shared/services/status-network.service.spec.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/app/modules/shared/services/status-network.service.spec.ts b/src/app/modules/shared/services/status-network.service.spec.ts index a5afb5c6c..5fa7aad97 100644 --- a/src/app/modules/shared/services/status-network.service.spec.ts +++ b/src/app/modules/shared/services/status-network.service.spec.ts @@ -26,14 +26,21 @@ describe('StatusNetworkService', () => { }); it('checkTypeError is error', () => { - const errorType: ErrorType = {error: catchError, message: 'javascript', isError: true}; + const errorType: ErrorType = {error: catchError, message: 'The server is disconnected', isError: true}; spyOn(toastrServiceStub, 'error'); service.checkTypeError(errorType); expect(toastrServiceStub.error).toHaveBeenCalled(); }); - it('checkTypeError is warning', () => { - const errorType: ErrorType = {error: catchError, message: 'javascript', isError: false}; + it('checkTypeError is warning with message', () => { + const errorType: ErrorType = {error: catchError, message: 'The server is disconnected', isError: false}; + spyOn(toastrServiceStub, 'warning'); + service.checkTypeError(errorType); + expect(toastrServiceStub.warning).toHaveBeenCalled(); + }); + + it('checkTypeError is warning without message', () => { + const errorType: ErrorType = {error: catchError, isError: false}; spyOn(toastrServiceStub, 'warning'); service.checkTypeError(errorType); expect(toastrServiceStub.warning).toHaveBeenCalled(); From a912865b56d66d5c226a234fea646ecf4affa623 Mon Sep 17 00:00:00 2001 From: Abigail Cabascango Date: Thu, 6 Oct 2022 17:16:13 -0500 Subject: [PATCH 10/17] refactor: TTA-115 increase test coverage in directives --- .../services/project-type.service.ts | 1 - .../connection.directive.spec.ts | 15 +++++++++++++++ .../fast.directive.spec.ts | 14 ++++++++++++++ .../offline.directive.spec.ts | 14 ++++++++++++++ .../slow.directive.spec.ts | 14 ++++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.spec.ts create mode 100644 src/app/modules/internet-connection-status/internet-connection-directives/fast.directive.spec.ts create mode 100644 src/app/modules/internet-connection-status/internet-connection-directives/offline.directive.spec.ts create mode 100644 src/app/modules/internet-connection-status/internet-connection-directives/slow.directive.spec.ts diff --git a/src/app/modules/customer-management/components/projects-type/services/project-type.service.ts b/src/app/modules/customer-management/components/projects-type/services/project-type.service.ts index 4031fe213..e989d5ed3 100644 --- a/src/app/modules/customer-management/components/projects-type/services/project-type.service.ts +++ b/src/app/modules/customer-management/components/projects-type/services/project-type.service.ts @@ -1,7 +1,6 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs'; -import { map, catchError } from 'rxjs/operators'; import { environment } from '../../../../../../environments/environment'; import { ProjectType } from '../../../../shared/models'; diff --git a/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.spec.ts b/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.spec.ts new file mode 100644 index 000000000..7f0ff2649 --- /dev/null +++ b/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.spec.ts @@ -0,0 +1,15 @@ +import { TestBed } from '@angular/core/testing'; +import { ConnectionDirective } from './connection.directive'; + +describe('ConnectionDirective', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ConnectionDirective] + }); + }); + + it('should create an instance', () => { + const directive = new ConnectionDirective('slowSrc', 'fastSrc', 'offlineSrc', undefined); + expect(directive).toBeTruthy(); + }); +}); diff --git a/src/app/modules/internet-connection-status/internet-connection-directives/fast.directive.spec.ts b/src/app/modules/internet-connection-status/internet-connection-directives/fast.directive.spec.ts new file mode 100644 index 000000000..f738749a3 --- /dev/null +++ b/src/app/modules/internet-connection-status/internet-connection-directives/fast.directive.spec.ts @@ -0,0 +1,14 @@ +import { TestBed } from '@angular/core/testing'; +import { FastDirective } from './fast.directive'; + +describe('FastDirective', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [FastDirective] + }); + }); + it('should create an instance', () => { + const directive = new FastDirective(undefined); + expect(directive).toBeTruthy(); + }); +}); diff --git a/src/app/modules/internet-connection-status/internet-connection-directives/offline.directive.spec.ts b/src/app/modules/internet-connection-status/internet-connection-directives/offline.directive.spec.ts new file mode 100644 index 000000000..bf6960c45 --- /dev/null +++ b/src/app/modules/internet-connection-status/internet-connection-directives/offline.directive.spec.ts @@ -0,0 +1,14 @@ +import { TestBed } from '@angular/core/testing'; +import { OfflineDirective } from './offline.directive'; + +describe('FastDirective', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [OfflineDirective] + }); + }); + it('should create an instance', () => { + const directive = new OfflineDirective(undefined); + expect(directive).toBeTruthy(); + }); +}); diff --git a/src/app/modules/internet-connection-status/internet-connection-directives/slow.directive.spec.ts b/src/app/modules/internet-connection-status/internet-connection-directives/slow.directive.spec.ts new file mode 100644 index 000000000..84f98f526 --- /dev/null +++ b/src/app/modules/internet-connection-status/internet-connection-directives/slow.directive.spec.ts @@ -0,0 +1,14 @@ +import { TestBed } from '@angular/core/testing'; +import { SlowDirective } from './slow.directive'; + +describe('FastDirective', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [SlowDirective] + }); + }); + it('should create an instance', () => { + const directive = new SlowDirective(undefined); + expect(directive).toBeTruthy(); + }); +}); From 940f4b87b92cf067e8e2502ea9008095130af89f Mon Sep 17 00:00:00 2001 From: Abigail Cabascango Date: Thu, 6 Oct 2022 17:20:20 -0500 Subject: [PATCH 11/17] refactor: TTA-115 solve github comment --- .../components/projects-type/services/project-type.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/modules/customer-management/components/projects-type/services/project-type.service.ts b/src/app/modules/customer-management/components/projects-type/services/project-type.service.ts index e989d5ed3..685c5d0df 100644 --- a/src/app/modules/customer-management/components/projects-type/services/project-type.service.ts +++ b/src/app/modules/customer-management/components/projects-type/services/project-type.service.ts @@ -28,6 +28,6 @@ export class ProjectTypeService { updateProjectType(projectTypeData): Observable { const url = `${this.baseUrl}/${projectTypeData.id}`; - return this.http.put(url, projectTypeData) + return this.http.put(url, projectTypeData); } } From 2e9e2cb40088a45c0061e0754f98c8c2aff87da1 Mon Sep 17 00:00:00 2001 From: Abigail Cabascango Date: Thu, 6 Oct 2022 18:36:20 -0500 Subject: [PATCH 12/17] fix: TTA-115 fix code smells --- src/app/app.module.ts | 2 -- .../internet-connection-status.component.scss | 0 .../internet-connection-status.component.ts | 9 ++++----- .../shared/services/status-network.service.spec.ts | 3 +-- src/app/modules/users/store/user.effects.ts | 5 ----- src/environments/environment.prodlegacy.ts | 3 ++- 6 files changed, 7 insertions(+), 15 deletions(-) delete mode 100644 src/app/modules/internet-connection-status/internet-connection-status.component.scss diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 89d6559c1..ccb2e143c 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -100,7 +100,6 @@ import { FastDirective} from './modules/internet-connection-status/internet-conn import { SlowDirective} from './modules/internet-connection-status/internet-connection-directives/slow.directive'; import { OfflineDirective} from './modules/internet-connection-status/internet-connection-directives/offline.directive'; import { ConnectionDirective } from './modules/internet-connection-status/internet-connection-directives/connection.directive'; -import { ToastrService } from 'ngx-toastr'; const maskConfig: Partial = { validation: false, @@ -219,7 +218,6 @@ const maskConfig: Partial = { }, DatePipe, CookieService, - ToastrService, {provide: Window, useValue: window} ], bootstrap: [AppComponent], diff --git a/src/app/modules/internet-connection-status/internet-connection-status.component.scss b/src/app/modules/internet-connection-status/internet-connection-status.component.scss deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/app/modules/internet-connection-status/internet-connection-status.component.ts b/src/app/modules/internet-connection-status/internet-connection-status.component.ts index cb0111f4f..d3cc7bada 100644 --- a/src/app/modules/internet-connection-status/internet-connection-status.component.ts +++ b/src/app/modules/internet-connection-status/internet-connection-status.component.ts @@ -1,9 +1,9 @@ -import { Component, OnInit, ContentChild, Attribute, OnDestroy} from '@angular/core'; +import { Component, OnInit, ContentChild, Attribute} from '@angular/core'; import { FastDirective} from '../../modules/internet-connection-status/internet-connection-directives/fast.directive'; import { SlowDirective} from '../../modules/internet-connection-status/internet-connection-directives/slow.directive'; import { OfflineDirective} from '../../modules/internet-connection-status/internet-connection-directives/offline.directive'; -import { Observable, of, Subscription } from 'rxjs'; -import { take, map } from 'rxjs/operators'; +import { Observable, Subscription } from 'rxjs'; +import { take } from 'rxjs/operators'; import { ToastrService } from 'ngx-toastr'; type Connection = { @@ -23,8 +23,7 @@ declare global { @Component({ selector: 'app-internet-connection-status', - templateUrl: './internet-connection-status.component.html', - styleUrls: ['./internet-connection-status.component.scss'] + templateUrl: './internet-connection-status.component.html' }) export class InternetConnectionStatusComponent implements OnInit { isFast = true; diff --git a/src/app/modules/shared/services/status-network.service.spec.ts b/src/app/modules/shared/services/status-network.service.spec.ts index 5fa7aad97..d78795ed4 100644 --- a/src/app/modules/shared/services/status-network.service.spec.ts +++ b/src/app/modules/shared/services/status-network.service.spec.ts @@ -1,6 +1,5 @@ import { TestBed } from '@angular/core/testing'; -import * as assert from 'assert'; -import { catchError, map, mergeMap } from 'rxjs/operators'; +import { catchError } from 'rxjs/operators'; import { IndividualConfig, ToastrService } from 'ngx-toastr'; import { StatusNetworkService } from './status-network.service'; diff --git a/src/app/modules/users/store/user.effects.ts b/src/app/modules/users/store/user.effects.ts index c6ea1ccd9..bb9718391 100644 --- a/src/app/modules/users/store/user.effects.ts +++ b/src/app/modules/users/store/user.effects.ts @@ -28,7 +28,6 @@ export class UserEffects { }), catchError((error) => { this.statusNetworkService.checkTypeError({error, isError: true}); - //this.toastrService.error(error.error.message); return of(new actions.LoadUsersFail(error)); }) ) @@ -47,7 +46,6 @@ export class UserEffects { }), catchError((error) => { this.statusNetworkService.checkTypeError({error, isError: true}); - //this.toastrService.error(error.error.message); return of(new actions.AddUserToGroupFail(error)); }) ) @@ -66,7 +64,6 @@ export class UserEffects { }), catchError((error) => { this.statusNetworkService.checkTypeError({error, isError: true}); - //this.toastrService.error(error.error.message); return of(new actions.RemoveUserFromGroupFail(error)); }) ) @@ -85,7 +82,6 @@ export class UserEffects { }), catchError((error) => { this.statusNetworkService.checkTypeError({error, isError: true}); - //this.toastrService.error(error.error.message); return of(new actions.GrantUserRoleFail(error)); }) ) @@ -104,7 +100,6 @@ export class UserEffects { }), catchError((error) => { this.statusNetworkService.checkTypeError({error, isError: true}); - //this.toastrService.error(error.error.message); return of(new actions.RevokeUserRoleFail(error)); }) ) diff --git a/src/environments/environment.prodlegacy.ts b/src/environments/environment.prodlegacy.ts index 2ff198b90..c7714e8fc 100644 --- a/src/environments/environment.prodlegacy.ts +++ b/src/environments/environment.prodlegacy.ts @@ -2,7 +2,8 @@ import { EnvironmentType } from './enum'; export const environment = { production: EnvironmentType.TT_PROD_LEGACY, - timeTrackerApiUrl: process.env["API_URL"], + //timeTrackerApiUrl: process.env["API_URL"], + timeTrackerApiUrl:'https://a9e7-190-231-230-97.sa.ngrok.io', stackexchangeApiUrl: 'https://api.stackexchange.com', }; From e88247cfd8b86f0482f5ba1449d651fcba799b0c Mon Sep 17 00:00:00 2001 From: Abigail Cabascango Date: Thu, 6 Oct 2022 18:54:54 -0500 Subject: [PATCH 13/17] fix: change API URL in prod :'v --- src/environments/environment.prodlegacy.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/environments/environment.prodlegacy.ts b/src/environments/environment.prodlegacy.ts index c7714e8fc..2ff198b90 100644 --- a/src/environments/environment.prodlegacy.ts +++ b/src/environments/environment.prodlegacy.ts @@ -2,8 +2,7 @@ import { EnvironmentType } from './enum'; export const environment = { production: EnvironmentType.TT_PROD_LEGACY, - //timeTrackerApiUrl: process.env["API_URL"], - timeTrackerApiUrl:'https://a9e7-190-231-230-97.sa.ngrok.io', + timeTrackerApiUrl: process.env["API_URL"], stackexchangeApiUrl: 'https://api.stackexchange.com', }; From 37cec9b05c013d61b07ad4067237e042f00bc1f8 Mon Sep 17 00:00:00 2001 From: Yalian Garcia Date: Fri, 7 Oct 2022 15:23:41 -0500 Subject: [PATCH 14/17] Update src/app/modules/internet-connection-status/internet-connection-directives/slow.directive.spec.ts Co-authored-by: mmaquina --- .../internet-connection-directives/slow.directive.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/modules/internet-connection-status/internet-connection-directives/slow.directive.spec.ts b/src/app/modules/internet-connection-status/internet-connection-directives/slow.directive.spec.ts index 84f98f526..59287917a 100644 --- a/src/app/modules/internet-connection-status/internet-connection-directives/slow.directive.spec.ts +++ b/src/app/modules/internet-connection-status/internet-connection-directives/slow.directive.spec.ts @@ -8,7 +8,7 @@ describe('FastDirective', () => { }); }); it('should create an instance', () => { - const directive = new SlowDirective(undefined); - expect(directive).toBeTruthy(); + const directive = new SlowDirective(undefined); + expect(directive).toBeTruthy(); }); }); From 8e724879a1f4741071a02d43b2a5afd1327ec374 Mon Sep 17 00:00:00 2001 From: Abigail Cabascango Date: Fri, 7 Oct 2022 16:40:09 -0500 Subject: [PATCH 15/17] refactor: TTA-115 solve review comments --- .../store/activity-management.effects.ts | 10 +++---- .../store/project-type.effects.ts | 8 ++--- .../components/store/project.effects.ts | 14 ++++----- .../store/customer-management.effects.ts | 10 +++---- .../connection.directive.ts | 9 ++---- .../internet-connection-status.component.ts | 12 ++++---- .../services/status-network.service.spec.ts | 12 ++++---- .../shared/services/status-network.service.ts | 30 +++++++++++-------- .../modules/time-clock/store/entry.effects.ts | 22 +++++++------- src/app/modules/users/store/user.effects.ts | 10 +++---- 10 files changed, 68 insertions(+), 69 deletions(-) diff --git a/src/app/modules/activities-management/store/activity-management.effects.ts b/src/app/modules/activities-management/store/activity-management.effects.ts index df7992fc4..08d08e11c 100644 --- a/src/app/modules/activities-management/store/activity-management.effects.ts +++ b/src/app/modules/activities-management/store/activity-management.effects.ts @@ -29,7 +29,7 @@ export class ActivityEffects { return new actions.LoadActivitiesSuccess(activities); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.LoadActivitiesFail(error)); }) ) @@ -47,7 +47,7 @@ export class ActivityEffects { return new actions.CreateActivitySuccess(activityData); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.CreateActivityFail(error)); }) ) @@ -68,7 +68,7 @@ export class ActivityEffects { return new actions.ArchiveActivitySuccess(activity); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.ArchiveActivityFail(error)); }) ) @@ -86,7 +86,7 @@ export class ActivityEffects { return new actions.UpdateActivitySuccess(activityData); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.UpdateActivityFail(error)); }) ) @@ -108,7 +108,7 @@ export class ActivityEffects { return new actions.UnarchiveActivitySuccess(activityData); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.UnarchiveActivityFail(error)); }) ) diff --git a/src/app/modules/customer-management/components/projects-type/store/project-type.effects.ts b/src/app/modules/customer-management/components/projects-type/store/project-type.effects.ts index b9afd3710..2646dc762 100644 --- a/src/app/modules/customer-management/components/projects-type/store/project-type.effects.ts +++ b/src/app/modules/customer-management/components/projects-type/store/project-type.effects.ts @@ -29,7 +29,7 @@ export class ProjectTypeEffects { return new actions.LoadProjectTypesSuccess(projectTypes); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.LoadProjectTypesFail(error)); }) ) @@ -47,7 +47,7 @@ export class ProjectTypeEffects { return new actions.CreateProjectTypeSuccess(projectTypeData); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.CreateProjectTypeFail(error)); }) ) @@ -65,7 +65,7 @@ export class ProjectTypeEffects { return new actions.DeleteProjectTypeSuccess(protectTypeId); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.DeleteProjectTypeFail(error)); }) ) @@ -83,7 +83,7 @@ export class ProjectTypeEffects { return new actions.UpdateProjectTypeSuccess(projectTypeData); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.UpdateProjectTypeFail(error)); }) ) diff --git a/src/app/modules/customer-management/components/projects/components/store/project.effects.ts b/src/app/modules/customer-management/components/projects/components/store/project.effects.ts index d9900617a..a80d12d29 100644 --- a/src/app/modules/customer-management/components/projects/components/store/project.effects.ts +++ b/src/app/modules/customer-management/components/projects/components/store/project.effects.ts @@ -28,7 +28,7 @@ export class ProjectEffects { return new actions.LoadProjectsSuccess(projects); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.LoadProjectsFail(error)); }) ) @@ -44,7 +44,7 @@ export class ProjectEffects { return new actions.LoadCustomerProjectsSuccess(project); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.LoadCustomerProjectsFail(error)); }) ) @@ -60,7 +60,7 @@ export class ProjectEffects { return new actions.LoadRecentProjectsSuccess(projects); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.LoadRecentProjectsFail(error)); }) ) @@ -78,7 +78,7 @@ export class ProjectEffects { return new actions.CreateProjectSuccess(projectData); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.CreateProjectFail(error)); }) ) @@ -96,7 +96,7 @@ export class ProjectEffects { return new actions.UpdateProjectSuccess(projectData); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.UpdateProjectFail(error)); }) ) @@ -114,7 +114,7 @@ export class ProjectEffects { return new actions.DeleteProjectSuccess(projectId); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.DeleteProjectFail(error)); }) ) @@ -135,7 +135,7 @@ export class ProjectEffects { return new actions.UnarchiveProjectSuccess(projectData); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.UnarchiveProjectFail(error)); }) ) diff --git a/src/app/modules/customer-management/store/customer-management.effects.ts b/src/app/modules/customer-management/store/customer-management.effects.ts index 6635b9bbb..7c5e7030f 100644 --- a/src/app/modules/customer-management/store/customer-management.effects.ts +++ b/src/app/modules/customer-management/store/customer-management.effects.ts @@ -29,7 +29,7 @@ export class CustomerEffects { return new actions.LoadCustomersSuccess(customers); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.LoadCustomersFail(error)); } ) @@ -48,7 +48,7 @@ export class CustomerEffects { return new actions.CreateCustomerSuccess(customerData); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.CreateCustomerFail(error)); }) ) @@ -66,7 +66,7 @@ export class CustomerEffects { return new actions.DeleteCustomerSuccesss(customerId); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.DeleteCustomerFail(error)); }) ) @@ -84,7 +84,7 @@ export class CustomerEffects { return new actions.UpdateCustomerSuccess(customerData); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.UpdateCustomerFail(error)); }) ) @@ -106,7 +106,7 @@ export class CustomerEffects { return new actions.UpdateCustomerSuccess(customerData); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.UpdateCustomerFail(error)); }) ) diff --git a/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts b/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts index 3abf5c366..72c5cd47d 100644 --- a/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts +++ b/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts @@ -16,19 +16,16 @@ export class ConnectionDirective implements OnInit { ngOnInit() { const { effectiveType } = navigator.connection; let networkSatus; - if (!(/\fast-5g|3g|4g/.test(effectiveType)) || !(/\slow-2g|2g/.test(effectiveType))){ - networkSatus = this.offlineSrc; - } - if (/\fast-5g|3g|4g/.test(effectiveType)) { networkSatus = this.fastSrc; + return } - if (/\slow-2g|2g/.test(effectiveType)) { networkSatus = this.slowSrc; + return } + networkSatus = this.offlineSrc; this.host.nativeElement.setAttribute('src', networkSatus); } - } diff --git a/src/app/modules/internet-connection-status/internet-connection-status.component.ts b/src/app/modules/internet-connection-status/internet-connection-status.component.ts index d3cc7bada..0dd0e52ae 100644 --- a/src/app/modules/internet-connection-status/internet-connection-status.component.ts +++ b/src/app/modules/internet-connection-status/internet-connection-status.component.ts @@ -67,20 +67,18 @@ export class InternetConnectionStatusComponent implements OnInit { .subscribe((effectiveType: string) => { this.connectionType = effectiveType; - - if (!(/\fast-5g|3g|4g/.test(effectiveType)) || !(/\slow-2g|2g/.test(effectiveType))){ + + if (/\fast-5g|3g|4g/.test(effectiveType)) { this.toastrService.error('Your request was not completed, you are offline'); - this.isFast = false; - } - - if (/\fast-5g|3g|4g/.test(effectiveType)){ this.isFast = true; + return } - if (/\slow-2g|2g/.test(effectiveType)) { this.toastrService.warning('Caution your connection is slow'); this.isFast = false; + return } + this.isFast = false; }); } } diff --git a/src/app/modules/shared/services/status-network.service.spec.ts b/src/app/modules/shared/services/status-network.service.spec.ts index d78795ed4..8ae41a12b 100644 --- a/src/app/modules/shared/services/status-network.service.spec.ts +++ b/src/app/modules/shared/services/status-network.service.spec.ts @@ -24,24 +24,24 @@ describe('StatusNetworkService', () => { service = TestBed.inject(StatusNetworkService); }); - it('checkTypeError is error', () => { + it('showTypeToastrServiceAlert is error', () => { const errorType: ErrorType = {error: catchError, message: 'The server is disconnected', isError: true}; spyOn(toastrServiceStub, 'error'); - service.checkTypeError(errorType); + service.showTypeToastrServiceAlert(errorType); expect(toastrServiceStub.error).toHaveBeenCalled(); }); - it('checkTypeError is warning with message', () => { + it('showTypeToastrServiceAlert is warning with message', () => { const errorType: ErrorType = {error: catchError, message: 'The server is disconnected', isError: false}; spyOn(toastrServiceStub, 'warning'); - service.checkTypeError(errorType); + service.showTypeToastrServiceAlert(errorType); expect(toastrServiceStub.warning).toHaveBeenCalled(); }); - it('checkTypeError is warning without message', () => { + it('showTypeToastrServiceAlert is warning without message', () => { const errorType: ErrorType = {error: catchError, isError: false}; spyOn(toastrServiceStub, 'warning'); - service.checkTypeError(errorType); + service.showTypeToastrServiceAlert(errorType); expect(toastrServiceStub.warning).toHaveBeenCalled(); }); }); diff --git a/src/app/modules/shared/services/status-network.service.ts b/src/app/modules/shared/services/status-network.service.ts index b726f3cf9..2058c460f 100644 --- a/src/app/modules/shared/services/status-network.service.ts +++ b/src/app/modules/shared/services/status-network.service.ts @@ -16,18 +16,22 @@ export class StatusNetworkService { private toastrService: ToastrService ) { } - checkTypeError(dataError: ErrorType){ - const { isError = false, message = 'The server is disconnected', error} = dataError; + showTypeToastrServiceAlert(dataError: ErrorType) { + const { isError = false, message = 'The server is disconnected', error } = dataError; const effectiveTypenetwork = navigator.connection; - if ((effectiveTypenetwork.effectiveType !== '2g')){ - if (!isError){ - this.toastrService.warning(message); - } - if (isError){ - const errorMessa = error.error && error.error.message ? error.error.message : 'There is an error with the server, your request have not be completed'; - this.toastrService.error(errorMessa); - } + + if (effectiveTypenetwork.effectiveType === '2g') { + this.toastrService.warning('Your request was not completed, your connection is slow'); + return } - this.toastrService.warning('Your request was not completed, your connection is slow'); - } -} + + if (!isError) { + this.toastrService.warning(message); + return + } + + const errorMessa = (error.error && error.error.message ? error.error.message : + 'There was an error in the server, your request was not completed'); + this.toastrService.error(errorMessa); + + }} diff --git a/src/app/modules/time-clock/store/entry.effects.ts b/src/app/modules/time-clock/store/entry.effects.ts index 8f9d50e9d..e5ae2fd66 100644 --- a/src/app/modules/time-clock/store/entry.effects.ts +++ b/src/app/modules/time-clock/store/entry.effects.ts @@ -37,7 +37,7 @@ export class EntryEffects { return new actions.ClockIn(entry); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, message: 'We could not perform this operation, try again later', isError: false}); + this.statusNetworkService.showTypeToastrServiceAlert({error, message: 'We could not perform this operation, try again later', isError: false}); return of(new actions.StopTimeEntryRunningFail(error)); }) ) @@ -56,7 +56,7 @@ export class EntryEffects { return new actions.LoadEntriesSummarySuccess(response); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, message: 'Your summary information could not be loaded', isError: false}); + this.statusNetworkService.showTypeToastrServiceAlert({error, message: 'Your summary information could not be loaded', isError: false}); return of(new actions.LoadEntriesSummaryFail()); }) ) @@ -101,7 +101,7 @@ export class EntryEffects { this.entryService.loadEntries({ month: date.month, year: date.year }).pipe( map((entries) => new actions.LoadEntriesSuccess(entries)), catchError((error) => { - this.statusNetworkService.checkTypeError({error, message: 'The data could not be loaded', isError: false}); + this.statusNetworkService.showTypeToastrServiceAlert({error, message: 'The data could not be loaded', isError: false}); return of(new actions.LoadEntriesFail(error)); }) ) @@ -123,7 +123,7 @@ export class EntryEffects { return new actions.CreateEntrySuccess(entryData); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.CreateEntryFail(error.error.message)); }) ) @@ -151,7 +151,7 @@ export class EntryEffects { if (error.status === 404) { return of(new actions.CreateEntry(entry)); } else { - this.statusNetworkService.checkTypeError({error, message: 'We could not clock you in, try again later.', isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, message: 'We could not clock you in, try again later.', isError: true}); return of(new actions.CreateEntryFail('Error')); } }) @@ -170,7 +170,7 @@ export class EntryEffects { return new actions.DeleteEntrySuccess(entryId); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.DeleteEntryFail(error)); }) ) @@ -188,7 +188,7 @@ export class EntryEffects { return new actions.UpdateEntrySuccess(entryResponse); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.UpdateEntryFail(error)); }) ) @@ -206,7 +206,7 @@ export class EntryEffects { return new actions.UpdateEntrySuccess(entryResponse); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.UpdateEntryFail(error)); }) ) @@ -224,7 +224,7 @@ export class EntryEffects { return new actions.StopTimeEntryRunningSuccess(response); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.StopTimeEntryRunningFail(error.error.message)); }) ) @@ -251,7 +251,7 @@ export class EntryEffects { } }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.UpdateCurrentOrLastEntryFail('error')); }) ) @@ -284,7 +284,7 @@ export class EntryEffects { return new actions.RestartEntrySuccess(entryResponse); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, message: 'This entry could not be restarted', isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, message: 'This entry could not be restarted', isError: true}); return of(new actions.RestartEntryFail(error)); }) ) diff --git a/src/app/modules/users/store/user.effects.ts b/src/app/modules/users/store/user.effects.ts index bb9718391..6090f07a0 100644 --- a/src/app/modules/users/store/user.effects.ts +++ b/src/app/modules/users/store/user.effects.ts @@ -27,7 +27,7 @@ export class UserEffects { return new actions.LoadUsersSuccess(users); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.LoadUsersFail(error)); }) ) @@ -45,7 +45,7 @@ export class UserEffects { return new actions.AddUserToGroupSuccess(response); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.AddUserToGroupFail(error)); }) ) @@ -63,7 +63,7 @@ export class UserEffects { return new actions.RemoveUserFromGroupSuccess(response); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.RemoveUserFromGroupFail(error)); }) ) @@ -81,7 +81,7 @@ export class UserEffects { return new actions.GrantUserRoleSuccess(response); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.GrantUserRoleFail(error)); }) ) @@ -99,7 +99,7 @@ export class UserEffects { return new actions.RevokeUserRoleSuccess(response); }), catchError((error) => { - this.statusNetworkService.checkTypeError({error, isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert({error, isError: true}); return of(new actions.RevokeUserRoleFail(error)); }) ) From 5bc7915af28e54ba88df69b34276a2ac3253e84b Mon Sep 17 00:00:00 2001 From: Abigail Cabascango Date: Fri, 7 Oct 2022 16:40:34 -0500 Subject: [PATCH 16/17] refactor: TTA-115 solve linting --- .../connection.directive.ts | 4 ++-- .../internet-connection-status.component.ts | 8 ++++---- src/app/modules/shared/services/status-network.service.ts | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts b/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts index 72c5cd47d..34014be43 100644 --- a/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts +++ b/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts @@ -18,11 +18,11 @@ export class ConnectionDirective implements OnInit { let networkSatus; if (/\fast-5g|3g|4g/.test(effectiveType)) { networkSatus = this.fastSrc; - return + return; } if (/\slow-2g|2g/.test(effectiveType)) { networkSatus = this.slowSrc; - return + return; } networkSatus = this.offlineSrc; diff --git a/src/app/modules/internet-connection-status/internet-connection-status.component.ts b/src/app/modules/internet-connection-status/internet-connection-status.component.ts index 0dd0e52ae..791d0b8c7 100644 --- a/src/app/modules/internet-connection-status/internet-connection-status.component.ts +++ b/src/app/modules/internet-connection-status/internet-connection-status.component.ts @@ -67,16 +67,16 @@ export class InternetConnectionStatusComponent implements OnInit { .subscribe((effectiveType: string) => { this.connectionType = effectiveType; - - if (/\fast-5g|3g|4g/.test(effectiveType)) { + + if (/\fast-5g|3g|4g/.test(effectiveType)) { this.toastrService.error('Your request was not completed, you are offline'); this.isFast = true; - return + return; } if (/\slow-2g|2g/.test(effectiveType)) { this.toastrService.warning('Caution your connection is slow'); this.isFast = false; - return + return; } this.isFast = false; }); diff --git a/src/app/modules/shared/services/status-network.service.ts b/src/app/modules/shared/services/status-network.service.ts index 2058c460f..e268962cb 100644 --- a/src/app/modules/shared/services/status-network.service.ts +++ b/src/app/modules/shared/services/status-network.service.ts @@ -22,12 +22,12 @@ export class StatusNetworkService { if (effectiveTypenetwork.effectiveType === '2g') { this.toastrService.warning('Your request was not completed, your connection is slow'); - return + return; } if (!isError) { this.toastrService.warning(message); - return + return; } const errorMessa = (error.error && error.error.message ? error.error.message : From aabefafc463aadb9aec242494cefbb1c32e1cc08 Mon Sep 17 00:00:00 2001 From: mmaquina Date: Tue, 11 Oct 2022 19:59:55 -0300 Subject: [PATCH 17/17] refactor: TTA-115 changed test descriptions - lint --- .../connection.directive.ts | 16 +++++++--------- .../internet-connection-status.component.spec.ts | 6 +++--- .../internet-connection-status.component.ts | 8 ++++---- .../modules/time-clock/store/entry.effects.ts | 9 ++++++--- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts b/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts index 34014be43..e366eb991 100644 --- a/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts +++ b/src/app/modules/internet-connection-status/internet-connection-directives/connection.directive.ts @@ -15,17 +15,15 @@ export class ConnectionDirective implements OnInit { ngOnInit() { const { effectiveType } = navigator.connection; - let networkSatus; + let networkStatus; if (/\fast-5g|3g|4g/.test(effectiveType)) { - networkSatus = this.fastSrc; - return; + networkStatus = this.fastSrc; + } else if (/\slow-2g|2g/.test(effectiveType)) { + networkStatus = this.slowSrc; + } else { + networkStatus = this.offlineSrc; } - if (/\slow-2g|2g/.test(effectiveType)) { - networkSatus = this.slowSrc; - return; - } - networkSatus = this.offlineSrc; - this.host.nativeElement.setAttribute('src', networkSatus); + this.host.nativeElement.setAttribute('src', networkStatus); } } diff --git a/src/app/modules/internet-connection-status/internet-connection-status.component.spec.ts b/src/app/modules/internet-connection-status/internet-connection-status.component.spec.ts index fb212617c..4f273fff8 100644 --- a/src/app/modules/internet-connection-status/internet-connection-status.component.spec.ts +++ b/src/app/modules/internet-connection-status/internet-connection-status.component.spec.ts @@ -32,21 +32,21 @@ describe('InternetConnectionStatusComponent', () => { fixture.detectChanges(); }); - it('should show a stable connection warning', () => { + it('component.isFast should be true when the connection is 4g', () => { component.connection$ = of('4g'); fixture.detectChanges(); component.ngOnInit(); expect(component.isFast).toBe(true); }); - it('should show a slow connection warning', () => { + it('component.isFast should be false when the connection is 2g', () => { component.connection$ = of('2g'); fixture.detectChanges(); component.ngOnInit(); expect(component.isFast).toBe(false); }); - it('should show offline warning', () => { + it('component.isFast should be false when the connection is Offline', () => { component.connection$ = of('Offline'); fixture.detectChanges(); component.ngOnInit(); diff --git a/src/app/modules/internet-connection-status/internet-connection-status.component.ts b/src/app/modules/internet-connection-status/internet-connection-status.component.ts index 791d0b8c7..b1ed09223 100644 --- a/src/app/modules/internet-connection-status/internet-connection-status.component.ts +++ b/src/app/modules/internet-connection-status/internet-connection-status.component.ts @@ -69,15 +69,15 @@ export class InternetConnectionStatusComponent implements OnInit { this.connectionType = effectiveType; if (/\fast-5g|3g|4g/.test(effectiveType)) { - this.toastrService.error('Your request was not completed, you are offline'); this.isFast = true; return; } if (/\slow-2g|2g/.test(effectiveType)) { - this.toastrService.warning('Caution your connection is slow'); - this.isFast = false; - return; + this.toastrService.warning('Caution your connection is slow'); + this.isFast = false; + return; } + this.toastrService.warning('Caution your connection is slow'); this.isFast = false; }); } diff --git a/src/app/modules/time-clock/store/entry.effects.ts b/src/app/modules/time-clock/store/entry.effects.ts index e5ae2fd66..77c355c3e 100644 --- a/src/app/modules/time-clock/store/entry.effects.ts +++ b/src/app/modules/time-clock/store/entry.effects.ts @@ -37,7 +37,8 @@ export class EntryEffects { return new actions.ClockIn(entry); }), catchError((error) => { - this.statusNetworkService.showTypeToastrServiceAlert({error, message: 'We could not perform this operation, try again later', isError: false}); + this.statusNetworkService.showTypeToastrServiceAlert( + {error, message: 'We could not perform this operation, try again later', isError: false}); return of(new actions.StopTimeEntryRunningFail(error)); }) ) @@ -56,7 +57,8 @@ export class EntryEffects { return new actions.LoadEntriesSummarySuccess(response); }), catchError((error) => { - this.statusNetworkService.showTypeToastrServiceAlert({error, message: 'Your summary information could not be loaded', isError: false}); + this.statusNetworkService.showTypeToastrServiceAlert( + {error, message: 'Your summary information could not be loaded', isError: false}); return of(new actions.LoadEntriesSummaryFail()); }) ) @@ -151,7 +153,8 @@ export class EntryEffects { if (error.status === 404) { return of(new actions.CreateEntry(entry)); } else { - this.statusNetworkService.showTypeToastrServiceAlert({error, message: 'We could not clock you in, try again later.', isError: true}); + this.statusNetworkService.showTypeToastrServiceAlert( + {error, message: 'We could not clock you in, try again later.', isError: true}); return of(new actions.CreateEntryFail('Error')); } })