Skip to content

Commit

Permalink
VIH-7753 Change (judge) button shouldn't be displayed during last min…
Browse files Browse the repository at this point in the history
…ute booking (#719)

* Added changes to remove changes button

* Added tests

* Lint & Prettier & Remove f in describe

* Combined if

* Updated method & test

* Remove fdescribe

Co-authored-by: Jordan Mulvaney <[email protected]>
  • Loading branch information
mulvaneyjHMCTS and Jordan Mulvaney authored May 26, 2021
1 parent 348fa92 commit 1e9ab91
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<div class="judge-row__phone" id="judge-phone">{{ getJudgePhone(participant) }}</div>
</div>

<div *ngIf="isSummaryPage" class="judge-row__actions">
<div *ngIf="isSummaryPage && canEditJudge()" class="judge-row__actions">
<a [routerLink]="['/assign-judge']" class="vhlink" (click)="editJudge()">Change</a>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RouterTestingModule } from '@angular/router/testing';
import { BookingService } from 'src/app/services/booking.service';
import { Logger } from 'src/app/services/logger';
import { ParticipantItemComponent } from './participant-item.component';
import { VideoHearingsService } from 'src/app/services/video-hearings.service';

const router = {
navigate: jasmine.createSpy('navigate'),
Expand All @@ -13,6 +14,7 @@ const router = {

const loggerSpy = jasmine.createSpyObj<Logger>('Logger', ['error', 'debug', 'warn']);
let bookingServiceSpy: jasmine.SpyObj<BookingService>;
let videoHearingsServiceSpy: jasmine.SpyObj<VideoHearingsService>;

describe('ParticipantItemComponent', () => {
let component: ParticipantItemComponent;
Expand All @@ -28,13 +30,15 @@ describe('ParticipantItemComponent', () => {

beforeEach(
waitForAsync(() => {
videoHearingsServiceSpy = jasmine.createSpyObj<VideoHearingsService>(['isConferenceClosed', 'isHearingAboutToStart']);
TestBed.configureTestingModule({
declarations: [ParticipantItemComponent],
providers: [
{ provide: Router, useValue: router },
{ provide: Logger, useValue: loggerSpy },
{ provide: BookingService, useValue: bookingServiceSpy },
{ provide: Router, useValue: router }
{ provide: Router, useValue: router },
{ provide: VideoHearingsService, useValue: videoHearingsServiceSpy }
],
imports: [RouterTestingModule]
}).compileComponents();
Expand Down Expand Up @@ -126,4 +130,26 @@ describe('ParticipantItemComponent', () => {
fixture.detectChanges();
expect(component.isInterpreter).toBeTruthy();
});

it('should not be able to edit judge if canEdit is false', () => {
component.canEdit = false;
expect(component.canEditJudge()).toBe(false);
});
it('should not be able to edit judge if canEdit is true and hearing is closed', () => {
component.canEdit = true;
videoHearingsServiceSpy.isConferenceClosed.and.returnValue(true);
expect(component.canEditJudge()).toBe(false);
});
it('should not be able to edit judge if canEdit is true, hearing is open, hearing is about to start', () => {
component.canEdit = true;
videoHearingsServiceSpy.isConferenceClosed.and.returnValue(false);
videoHearingsServiceSpy.isHearingAboutToStart.and.returnValue(true);
expect(component.canEditJudge()).toBe(false);
});
it('should be able to edit judge if canEdit is true, hearing is open and hearing is not about to start', () => {
component.canEdit = true;
videoHearingsServiceSpy.isConferenceClosed.and.returnValue(false);
videoHearingsServiceSpy.isHearingAboutToStart.and.returnValue(false);
expect(component.canEditJudge()).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Logger } from 'src/app/services/logger';
import { PageUrls } from 'src/app/shared/page-url.constants';
import { OtherInformationModel } from '../../../common/model/other-information.model';
import { HearingModel } from '../../../common/model/hearing.model';
import { VideoHearingsService } from 'src/app/services/video-hearings.service';

@Component({
selector: 'app-participant-item',
Expand All @@ -23,7 +24,12 @@ export class ParticipantItemComponent {
@Output() edit = new EventEmitter<ParticipantModel>();
@Output() remove = new EventEmitter<ParticipantModel>();

constructor(private bookingService: BookingService, private logger: Logger, private router: Router) {}
constructor(
private bookingService: BookingService,
private logger: Logger,
private router: Router,
private videoHearingsService: VideoHearingsService
) {}

getJudgeUser(participant: ParticipantModel): string {
return participant.username;
Expand Down Expand Up @@ -87,4 +93,11 @@ export class ParticipantItemComponent {
get isInterpretee() {
return this.participant.is_interpretee;
}

canEditJudge(): boolean {
if (!this.canEdit || this.videoHearingsService.isConferenceClosed() || this.videoHearingsService.isHearingAboutToStart()) {
return false;
}
return true;
}
}

0 comments on commit 1e9ab91

Please sign in to comment.