-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VIH-11263 - witness doesn’t have correct hierarchy on host waiting ro…
…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
1 parent
4a1c637
commit 1d9be0e
Showing
4 changed files
with
73 additions
and
24 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
VideoWeb/VideoWeb/ClientApp/src/app/shared/helpers/sorting-helper.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
VideoWeb/VideoWeb/ClientApp/src/app/shared/helpers/sorting-helper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters