Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: TTA-115 the if clausses in status network service and conne…
…ction directive and their component
  • Loading branch information
Abigail Cabascango committed Oct 5, 2022
commit 4665966aed4e4893628f7a4642573bbc6639c739
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
}
Expand Down
12 changes: 10 additions & 2 deletions src/app/modules/shared/services/status-network.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
13 changes: 8 additions & 5 deletions src/app/modules/shared/services/status-network.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ export class StatusNetworkService {
checkTypeError(dataError: ErrorType){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

le ponemos de nombre swhowMessage?

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';
}
}