Skip to content

Commit

Permalink
correct logic for no connection
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsetterfield committed Sep 19, 2024
1 parent a98bc51 commit b040478
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@ describe('MotCardComponent', () => {
describe('isValidMOT', () => {
it('should return true if data.status is "Valid"', () => {
component.data = { status: MotStatusCodes.VALID } as MotHistory;
expect(component.isValidMOT()).toBeTruthy();
expect(component.isValidMOT()).toEqual(true);
});
it('should return false if data.status is not "Valid"', () => {
component.data = { status: MotStatusCodes.NOT_VALID } as MotHistory;
expect(component.isValidMOT()).toBeFalsy();
expect(component.isValidMOT()).toEqual(false);
});
});

describe('callWasSuccessful', () => {
it('should return true if status is 200, data.status is not "No details" and the app is online', () => {
spyOn(component.networkState, 'getNetworkState').and.returnValue(ConnectionStatus.ONLINE);
component.data = { status: MotStatusCodes.VALID } as MotHistory;
component.status = '200';
expect(component.callWasSuccessful()).toBeTruthy();
expect(component.isCallWasSuccessful()).toEqual(true);
});
it(
'should return false if status is not 200 or Already Saved, data.status is ' +
Expand All @@ -51,66 +52,111 @@ describe('MotCardComponent', () => {
spyOn(component.networkState, 'getNetworkState').and.returnValue(ConnectionStatus.ONLINE);
component.data = { status: MotStatusCodes.VALID } as MotHistory;
component.status = '100';
expect(component.callWasSuccessful()).toBeFalsy();
expect(component.isCallWasSuccessful()).toEqual(false);
}
);
it('should return false if status is 200, data.status is ' + '"No details" and the app is online', () => {
spyOn(component.networkState, 'getNetworkState').and.returnValue(ConnectionStatus.ONLINE);
component.data = { status: MotStatusCodes.NO_DETAILS } as MotHistory;
component.status = '200';
expect(component.callWasSuccessful()).toBeFalsy();
expect(component.isCallWasSuccessful()).toBeFalsy();
});
it('should return false if status is 200, data.status is ' + 'not "No details" and the app is not online', () => {
spyOn(component.networkState, 'getNetworkState').and.returnValue(ConnectionStatus.OFFLINE);
component.data = { status: MotStatusCodes.NO_DETAILS } as MotHistory;
component.status = '200';
expect(component.callWasSuccessful()).toBeFalsy();
expect(component.isCallWasSuccessful()).toEqual(false);
});
});
describe('noDetails', () => {

describe('isNoDetails', () => {
it('should return true if status is NO_CONTENT', () => {
component.status = HttpStatusCodes.NO_CONTENT.toString();
expect(component.noDetails()).toBeTruthy();
expect(component.isNoDetails()).toEqual(true);
});

it('should return true if data.status is NO_DETAILS', () => {
spyOn(component, 'is404').and.returnValue(false);
spyOn(component, 'isSearchFailed').and.returnValue(false);
component.data = { status: MotStatusCodes.NO_DETAILS } as MotHistory;
expect(component.noDetails()).toBeTruthy();
expect(component.isNoDetails()).toEqual(true);
});

it('should return true if data.status is AGE_EXEMPTION', () => {
spyOn(component, 'is404').and.returnValue(false);
spyOn(component, 'isSearchFailed').and.returnValue(false);
component.data = { status: MotStatusCodes.AGE_EXEMPTION } as MotHistory;
expect(component.noDetails()).toBeTruthy();
expect(component.isNoDetails()).toEqual(true);
});

it('should return false if status and data.status do not match NO_CONTENT, NO_DETAILS, or AGE_EXEMPTION', () => {
spyOn(component, 'is404').and.returnValue(false);
spyOn(component, 'isSearchFailed').and.returnValue(false);
component.status = HttpStatusCodes.OK.toString();
component.data = { status: MotStatusCodes.VALID } as MotHistory;
expect(component.noDetails()).toBeFalsy();
expect(component.isNoDetails()).toEqual(false);
});

it('should return true if status is equal to 404', () => {
spyOn(component, 'is404').and.returnValue(true);
spyOn(component, 'isSearchFailed').and.returnValue(false);
component.status = HttpStatusCodes.NOT_FOUND.toString();
component.data = { status: MotStatusCodes.VALID } as MotHistory;
expect(component.isNoDetails()).toEqual(true);
});

it('should return true if searchFailed', () => {
spyOn(component, 'is404').and.returnValue(false);
spyOn(component, 'isSearchFailed').and.returnValue(true);
component.status = HttpStatusCodes.NOT_FOUND.toString();
component.data = { status: MotStatusCodes.VALID } as MotHistory;
expect(component.isNoDetails()).toEqual(false);
});
});

describe('is404', () => {
it('should return true if status is NOT_FOUND', () => {
component.status = HttpStatusCodes.NOT_FOUND.toString();
expect(component.is404()).toBeTruthy();
expect(component.is404()).toEqual(true);
});

it('should return false if status is not NOT_FOUND', () => {
component.status = HttpStatusCodes.OK.toString();
expect(component.is404()).toBeFalsy();
expect(component.is404()).toEqual(false);
});
});
describe('searchFailed', () => {
describe('isSearchFailed', () => {
it('should return true if status is UNDEFINED', () => {
component.status = HttpStatusCodes.UNDEFINED.toString();
expect(component.searchFailed()).toBeTruthy();
expect(component.isSearchFailed()).toEqual(true);
});

it('should return true if status is INTERNAL_SERVER_ERROR', () => {
component.status = HttpStatusCodes.INTERNAL_SERVER_ERROR.toString();
expect(component.isSearchFailed()).toEqual(true);
});

it('should return true if status is BAD_GATEWAY', () => {
component.status = HttpStatusCodes.BAD_GATEWAY.toString();
expect(component.isSearchFailed()).toEqual(true);
});

it('should return false if status is not UNDEFINED', () => {
it('should return true if status is SERVICE_UNAVAILABLE', () => {
component.status = HttpStatusCodes.SERVICE_UNAVAILABLE.toString();
expect(component.isSearchFailed()).toEqual(true);
});

it('should return true if status is GATEWAY_TIMEOUT', () => {
component.status = HttpStatusCodes.GATEWAY_TIMEOUT.toString();
expect(component.isSearchFailed()).toEqual(true);
});

it('should return false if status is a listed status code', () => {
component.status = HttpStatusCodes.OK.toString();
expect(component.searchFailed()).toBeFalsy();
expect(component.isSearchFailed()).toEqual(false);
});
});

describe('evidenceRadioSelected', () => {
it('should emit the passed value and set alternateEvidenceRadioCheck to its value', () => {
component.alternateEvidenceRadioCheck = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="black-text" id="mot-details-successful" *ngIf="callWasSuccessful()">
<div class="black-text" id="mot-details-successful" *ngIf="isCallWasSuccessful()">
<ion-row>
<ion-col size="34"></ion-col>
<ion-col size="10">
Expand Down Expand Up @@ -34,15 +34,15 @@
[formGroup]="formGroup"
></alternate-mot-evidence>
</div>
<div class="black-text" id="mot-details-unsuccessful" *ngIf="!callWasSuccessful()">
<div class="black-text" id="mot-details-unsuccessful" *ngIf="!isCallWasSuccessful()">
<ion-row>
<ion-col size="34"></ion-col>
<ion-col size="9">
<ion-icon class="circle-icon" name="alert-circle"></ion-icon>
</ion-col>
<ion-col class="icon-text-align" size="49">
<ion-text *ngIf="noDetails() || is404()"> Unable to determine MOT status.</ion-text>
<ion-text *ngIf="searchFailed()"> Unable to connect. This feature is not available.</ion-text>
<ion-text *ngIf="isNoDetails()"> Unable to determine MOT status.</ion-text>
<ion-text *ngIf="isSearchFailed()"> Unable to connect. This feature is not available.</ion-text>
</ion-col>
</ion-row>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,29 @@ export class MotCardComponent {

constructor(public networkState: NetworkStateProvider) {}

callWasSuccessful() {
isCallWasSuccessful(): boolean {
return (
(+this.status === HttpStatusCodes.OK || this.status === 'Already Saved') &&
this?.data?.status !== MotStatusCodes.NO_DETAILS &&
this?.data?.status !== MotStatusCodes.AGE_EXEMPTION
);
}

noDetails(): boolean {
isNoDetails(): boolean {
return (
+this.status === HttpStatusCodes.NO_CONTENT ||
this.data?.status === MotStatusCodes.NO_DETAILS ||
this?.data?.status === MotStatusCodes.AGE_EXEMPTION
!this.isSearchFailed() &&
(+this.status === HttpStatusCodes.NO_CONTENT ||
this.data?.status === MotStatusCodes.NO_DETAILS ||
this?.data?.status === MotStatusCodes.AGE_EXEMPTION ||
this.is404())
);
}

is404(): boolean {
return +this.status === HttpStatusCodes.NOT_FOUND;
}

isValidMOT() {
isValidMOT(): boolean {
return this.data.status === MotStatusCodes.VALID;
}

Expand All @@ -57,7 +59,13 @@ export class MotCardComponent {
this.alternateEvidenceChange.emit(event);
}

searchFailed() {
return +this.status === HttpStatusCodes.UNDEFINED;
isSearchFailed() {
return (
+this.status === HttpStatusCodes.UNDEFINED ||
+this.status === HttpStatusCodes.INTERNAL_SERVER_ERROR ||
+this.status === HttpStatusCodes.BAD_GATEWAY ||
+this.status === HttpStatusCodes.SERVICE_UNAVAILABLE ||
+this.status === HttpStatusCodes.GATEWAY_TIMEOUT
);
}
}
3 changes: 3 additions & 0 deletions src/app/shared/models/http-status-codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ export enum HttpStatusCodes {
CONFLICT = 409,
UNPROCESSABLE_ENTITY = 422,
INTERNAL_SERVER_ERROR = 500,
BAD_GATEWAY = 502,
SERVICE_UNAVAILABLE = 503,
GATEWAY_TIMEOUT = 504,
}

0 comments on commit b040478

Please sign in to comment.