Skip to content

Commit

Permalink
VIH-11263 - witness doesn’t have correct hierarchy on host waiting ro…
Browse files Browse the repository at this point in the history
…om page (#2374)

* changed order

* applied same sorting logic from CC to WR

* added helper for sorting

* added test

* Update sorting-helper.spec.ts
  • Loading branch information
marcogagliardi authored Feb 24, 2025
1 parent 4a1c637 commit 1d9be0e
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { SortingHelper } from './sorting-helper';

describe('SortingHelper', () => {
it('should create an instance', () => {
expect(new SortingHelper()).toBeTruthy();
});

describe('orderByRoleThenName', () => {
it('should sort by role', () => {
const users = [
{ role: 'Admin', hearingRole: 'Judge', displayName: 'Alice' },
{ role: 'User', hearingRole: 'Witness', displayName: 'Bob' },
{ role: 'Admin', hearingRole: 'Witness', displayName: 'Charlie' }
];
users.sort(SortingHelper.orderByRoleThenName);
expect(users[0].displayName).toBe('Alice');
expect(users[1].displayName).toBe('Charlie');
expect(users[2].displayName).toBe('Bob');
});

it('should sort by hearing role when roles are equal', () => {
const users = [
{ role: 'User', hearingRole: 'Witness', displayName: 'Alice' },
{ role: 'User', hearingRole: 'Judge', displayName: 'Bob' },
{ role: 'User', hearingRole: 'Witness', displayName: 'Charlie' }
];
users.sort(SortingHelper.orderByRoleThenName);
expect(users[0].displayName).toBe('Bob');
expect(users[1].displayName).toBe('Alice');
expect(users[2].displayName).toBe('Charlie');
});

it('should sort by display name when roles and hearing roles are equal', () => {
const users = [
{ role: 'User', hearingRole: 'Witness', displayName: 'Charlie' },
{ role: 'User', hearingRole: 'Witness', displayName: 'Alice' },
{ role: 'User', hearingRole: 'Witness', displayName: 'Bob' }
];
users.sort(SortingHelper.orderByRoleThenName);
expect(users[0].displayName).toBe('Alice');
expect(users[1].displayName).toBe('Bob');
expect(users[2].displayName).toBe('Charlie');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export class SortingHelper {
static readonly orderByRoleThenName = (a, b) => {
// Sort by User Role
if (a.role < b.role) {
return -1;
}
if (a.role > b.role) {
return 1;
}
// Sort by Hearing Role
if (a.hearingRole < b.hearingRole) {
return -1;
}
if (a.hearingRole > b.hearingRole) {
return 1;
}
// Sort by Name
return a.displayName.localeCompare(b.displayName);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Logger } from 'src/app/services/logging/logger-base';
import { ParticipantStatusReader } from 'src/app/shared/models/participant-status-reader';
import { ParticipantStatusMessage } from 'src/app/services/models/participant-status-message';
import { HearingRoleHelper } from 'src/app/shared/helpers/hearing-role-helper';
import { SortingHelper } from 'src/app/shared/helpers/sorting-helper';

@Directive()
export abstract class ParticipantStatusDirective {
Expand Down Expand Up @@ -135,37 +136,19 @@ export abstract class ParticipantStatusDirective {
}

sortParticipants() {
const orderByRoleThenName = (a, b) => {
// Sort by User Role
if (a.role < b.role) {
return -1;
}
if (a.role > b.role) {
return 1;
}
// Sort by Hearing Role
if (a.hearingRole < b.hearingRole) {
return -1;
}
if (a.hearingRole > b.hearingRole) {
return 1;
}
// Sort by Name
return a.displayName.localeCompare(b.displayName);
};
const judges = this.participants.filter(participant => participant.hearingRole === HearingRole.JUDGE);
const panelMembersAndWingers = this.participants
.filter(participant => [...HearingRoleHelper.panelMemberRoles, HearingRole.WINGER.toString()].includes(participant.hearingRole))
.sort(orderByRoleThenName);
.sort(SortingHelper.orderByRoleThenName);
const staff = this.participants
.filter(participant => participant.hearingRole === HearingRole.STAFF_MEMBER)
.sort(orderByRoleThenName);
.sort(SortingHelper.orderByRoleThenName);
const observers = this.participants
.filter(participant => participant.hearingRole === HearingRole.OBSERVER)
.sort(orderByRoleThenName);
.sort(SortingHelper.orderByRoleThenName);
const quickLinks = this.participants
.filter(participant => participant.role === Role.QuickLinkParticipant || participant.role === Role.QuickLinkObserver)
.sort(orderByRoleThenName);
.sort(SortingHelper.orderByRoleThenName);

const participants = this.participants
.filter(
Expand All @@ -176,7 +159,7 @@ export abstract class ParticipantStatusDirective {
!quickLinks.includes(participant) &&
!staff.includes(participant)
)
.sort(orderByRoleThenName);
.sort(SortingHelper.orderByRoleThenName);

this.sortedParticipants = [...judges, ...panelMembersAndWingers, ...staff, ...participants, ...observers, ...quickLinks];
return this.sortedParticipants;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { HearingRole } from '../models/hearing-role-model';
import { FocusService } from 'src/app/services/focus.service';
import { VHConference, VHEndpoint, VHParticipant } from '../store/models/vh-conference';
import { ConsultationRules } from 'src/app/services/models/consultation-rules';
import { SortingHelper } from 'src/app/shared/helpers/sorting-helper';

@Directive()
export abstract class WRParticipantStatusListDirective implements OnChanges {
Expand Down Expand Up @@ -180,7 +181,7 @@ export abstract class WRParticipantStatusListDirective implements OnChanges {
x.role !== Role.QuickLinkParticipant &&
x.hearingRole !== HearingRole.STAFF_MEMBER
)
.sort((a, b) => a.role.localeCompare(b.role) || (a.name || a.displayName).localeCompare(b.name || b.displayName));
.sort(SortingHelper.orderByRoleThenName);

nonJudgeParts = [
...nonJudgeParts,
Expand Down

0 comments on commit 1d9be0e

Please sign in to comment.