Skip to content

Commit

Permalink
VIH-10133 Removed edit mode bool from update conditions (#1257)
Browse files Browse the repository at this point in the history
* Removed edit mode bool from update conditions

* lint fix

* Fixed code smells
  • Loading branch information
will-craig authored Sep 5, 2023
1 parent 46708d4 commit 128bf78
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,7 @@ export abstract class AddParticipantBaseDirective extends BookingBaseComponent i

if (this.form.valid && this.validEmail()) {
this.disableCaseAndHearingRoles();
if (this.editMode) {
this.displayNext();
} else {
this.displayAdd();
}
this.displayAdd();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ <h2 class="govuk-heading-m">Client details</h2>
</span>
</div>

<div class="govuk-grid-column-one-half" *ngIf="displayUpdateButton || editMode">
<div class="govuk-grid-column-one-half" *ngIf="displayUpdateButton">
<img src="assets/images/AddIcon.png" alt="Add icon with sign plus" />
<span class="vh-vert-top-m15">
<a
Expand All @@ -228,7 +228,7 @@ <h2 class="govuk-heading-m">Client details</h2>
</span>
</div>

<div class="govuk-grid-column-one-half" *ngIf="displayClearButton || editMode">
<div class="govuk-grid-column-one-half" *ngIf="displayClearButton">
<img src="assets/images/ClearIcon.png" alt="Clear fields icon" />
<span class="vh-vert-top-m15">
<a href="javascript:void(0)" id="clearFormBtn" class="govuk-link govuk-body" (click)="clearForm()"> Clear details </a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -970,14 +970,14 @@ describe('AddParticipantComponent', () => {
it('should return errorAlternativeEmail & errorJohAccountNotFound as false if called with notFoundEmailEvent as false', () => {
component.errorAlternativeEmail = true;
component.errorJohAccountNotFound = true;
component.subcribeForSeachEmailEvents();
component.subscribeForSearchEmailEvents();
component.searchEmail.notFoundEmailEvent.next(false);
expect(component.errorAlternativeEmail).toBeFalsy();
expect(component.errorJohAccountNotFound).toBeFalsy();
});
it('should have called Not Found Participant if Not Found Email Event has been called', () => {
spyOn(component, 'notFoundParticipant');
component.subcribeForSeachEmailEvents();
component.subscribeForSearchEmailEvents();
component.searchEmail.notFoundEmailEvent.next(true);
expect(component.notFoundParticipant).toHaveBeenCalledTimes(1);
});
Expand Down Expand Up @@ -1158,10 +1158,10 @@ describe('AddParticipantComponent edit mode', () => {
expect(videoHearingsServiceSpy.getParticipantRoles).toHaveBeenCalled();
expect(component.showDetails).toBeTruthy();
expect(component.selectedParticipantEmail).toBe('[email protected]');
expect(component.displayNextButton).toBeTruthy();
expect(component.displayClearButton).toBeFalsy();
expect(component.displayNextButton).toBeFalsy();
expect(component.displayClearButton).toBeTruthy();
expect(component.displayAddButton).toBeFalsy();
expect(component.displayUpdateButton).toBeFalsy();
expect(component.displayUpdateButton).toBeTruthy();
});
tick(100);
fixture.detectChanges();
Expand Down Expand Up @@ -1514,17 +1514,6 @@ describe('AddParticipantComponent edit mode no participants added', () => {
expect(component.showDetails).toBeTruthy();
}));

it('should show update participant and clear details links when tries to edit a participant in hearing', fakeAsync(() => {
const debugElement = fixture.debugElement;
component.selectedParticipantEmail = '[email protected]';
fixture.detectChanges();
const clearFormBtn = debugElement.query(By.css('#clearFormBtn'));
const updateFormBtn = debugElement.query(By.css('#updateParticipantBtn'));
tick(600);
expect(updateFormBtn).toBeTruthy();
expect(clearFormBtn).toBeTruthy();
}));

it('should show confirmation to remove participant', fakeAsync(() => {
component.ngAfterContentInit();
component.ngAfterViewInit();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AfterContentInit, AfterViewInit, Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { Observable, Subject, Subscription, combineLatest } from 'rxjs';
import { combineLatest, Observable, Subject, Subscription } from 'rxjs';
import { PageUrls } from 'src/app/shared/page-url.constants';
import { Constants } from '../../common/constants';
import { SanitizeInputText } from '../../common/formatters/sanitize-input-text';
Expand Down Expand Up @@ -148,12 +148,12 @@ export class AddParticipantComponent extends AddParticipantBaseDirective impleme
if (this.editMode) {
if (this.searchEmail && this.participantDetails) {
this.setParticipantEmail();
this.subcribeForSeachEmailEvents();
this.subscribeForSearchEmailEvents();
}
}
}

subcribeForSeachEmailEvents() {
subscribeForSearchEmailEvents() {
this.searchEmail.notFoundEmailEvent$.subscribe(notFound => {
if (notFound) {
this.notFoundParticipant();
Expand All @@ -178,18 +178,17 @@ export class AddParticipantComponent extends AddParticipantBaseDirective impleme

const self = this;
this.$subscriptions.push(
this.form.valueChanges.subscribe(result => {
this.form.valueChanges.subscribe(() => {
setTimeout(() => {
if (
(self.showDetails &&
self.role.value === self.constants.PleaseSelect &&
self.party.value === self.constants.PleaseSelect &&
self.title.value === self.constants.PleaseSelect &&
self.firstName.value === '' &&
self.lastName.value === '' &&
self.phone.value === '' &&
self.displayName.value === '') ||
self.editMode
self.showDetails &&
self.role.value === self.constants.PleaseSelect &&
self.party.value === self.constants.PleaseSelect &&
self.title.value === self.constants.PleaseSelect &&
self.firstName.value === '' &&
self.lastName.value === '' &&
self.phone.value === '' &&
self.displayName.value === ''
) {
self.displayNext();
} else if (
Expand Down Expand Up @@ -289,17 +288,15 @@ export class AddParticipantComponent extends AddParticipantBaseDirective impleme
}

validateJudiciaryEmailAndRole() {
if (this.searchEmail && this.searchEmail.email.length) {
if (this.searchEmail?.email?.length) {
this.searchService.searchJudiciaryEntries(this.searchEmail.email).subscribe(judiciaryEntries => {
this.errorJudiciaryAccount = false;
if (judiciaryEntries && judiciaryEntries.length) {
if (judiciaryEntries?.length) {
if (!this.judiciaryRoles.includes(this.role.value)) {
this.setErrorForJudiciaryAccount();
}
} else {
if (this.judiciaryRoles.includes(this.role.value)) {
this.setErrorForJudiciaryAccount();
}
} else if (this.judiciaryRoles.includes(this.role.value)) {
this.setErrorForJudiciaryAccount();
}
});
}
Expand Down Expand Up @@ -342,7 +339,7 @@ export class AddParticipantComponent extends AddParticipantBaseDirective impleme

this.hearing.participants.push(newParticipant);
this.hearing.participants = [...this.hearing.participants];
this.hearing = Object.assign({}, this.hearing);
this.hearing = { ...this.hearing };

this.populateInterpretedForList();
this.videoHearingService.updateHearingRequest(this.hearing);
Expand All @@ -367,8 +364,7 @@ export class AddParticipantComponent extends AddParticipantBaseDirective impleme
username: newParticipant.username
});
this.showConfirmationPopup = true;
const message = `You have already added ${newParticipant.first_name} ${newParticipant.last_name} to this hearing`;
this.confirmationMessage = message;
this.confirmationMessage = `You have already added ${newParticipant.first_name} ${newParticipant.last_name} to this hearing`;
}
} else {
this.isShowErrorSummary = true;
Expand Down Expand Up @@ -400,7 +396,7 @@ export class AddParticipantComponent extends AddParticipantBaseDirective impleme
}
});
this.hearing.participants = [...this.hearing.participants];
this.hearing = Object.assign({}, this.hearing);
this.hearing = { ...this.hearing };
this.clearForm();
this.participantDetails = null;
this.form.markAsPristine();
Expand All @@ -424,7 +420,7 @@ export class AddParticipantComponent extends AddParticipantBaseDirective impleme
confirmRemoveParticipant() {
if (this.selectedParticipantEmail) {
const participant = this.hearing.participants.find(x => x.email.toLowerCase() === this.selectedParticipantEmail.toLowerCase());
const title = participant && participant.title ? `${participant.title}` : '';
const title = participant?.title ? `${participant.title}` : '';
this.removerFullName = participant ? `${title} ${participant.first_name} ${participant.last_name}` : '';
const anyParticipants = this.hearing.participants.filter(x => !x.is_judge);
this.bookingHasParticipants = anyParticipants && anyParticipants.length > 1;
Expand All @@ -449,7 +445,7 @@ export class AddParticipantComponent extends AddParticipantBaseDirective impleme
}
this.participantService.removeParticipant(this.hearing, this.selectedParticipantEmail);
this.removeLinkedParticipant(this.selectedParticipantEmail);
this.hearing = Object.assign({}, this.hearing);
this.hearing = { ...this.hearing };
this.videoHearingService.updateHearingRequest(this.hearing);
this.videoHearingService.setBookingHasChanged(true);
}
Expand Down Expand Up @@ -478,10 +474,9 @@ export class AddParticipantComponent extends AddParticipantBaseDirective impleme
}

private getUserRoleName(newParticipant: ParticipantModel): string {
const userRole = this.caseAndHearingRoles
return this.caseAndHearingRoles
.find(c => c.name === newParticipant.case_role_name)
?.hearingRoles.find(h => h.name === newParticipant.hearing_role_name)?.userRole;
return userRole;
}

private addUpdateLinkedParticipant(newParticipant: ParticipantModel): LinkedParticipantModel[] {
Expand Down Expand Up @@ -745,7 +740,7 @@ export class AddParticipantComponent extends AddParticipantBaseDirective impleme
}
this.participantService.removeParticipant(this.hearing, this.selectedParticipantEmail);
this.removeLinkedParticipant(this.selectedParticipantEmail);
this.hearing = Object.assign({}, this.hearing);
this.hearing = { ...this.hearing };
this.videoHearingService.updateHearingRequest(this.hearing);
this.videoHearingService.setBookingHasChanged(true);
}
Expand Down

0 comments on commit 128bf78

Please sign in to comment.