-
Notifications
You must be signed in to change notification settings - Fork 45
Adding buttons to sort assignment candidates by first/last name #5403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,8 @@ | ||||||||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||||||||
| import {ComponentFixture, TestBed} from '@angular/core/testing'; | ||||||||
|
|
||||||||
| import { AssignmentDetailComponent } from './assignment-detail.component'; | ||||||||
| import {AssignmentDetailComponent} from './assignment-detail.component'; | ||||||||
|
|
||||||||
| import {ViewAssignmentCandidate} from "../../../../view-models"; | ||||||||
|
|
||||||||
| xdescribe(`AssignmentDetailComponent`, () => { | ||||||||
| let component: AssignmentDetailComponent; | ||||||||
|
|
@@ -21,4 +23,34 @@ xdescribe(`AssignmentDetailComponent`, () => { | |||||||
| it(`should create`, () => { | ||||||||
| expect(component).toBeTruthy(); | ||||||||
| }); | ||||||||
|
|
||||||||
| describe('candidate sorting', () => { | ||||||||
| let candidates: ViewAssignmentCandidate[]; | ||||||||
| let onSortingChangeSpy: jasmine.Spy; | ||||||||
|
|
||||||||
| beforeEach(() => { | ||||||||
| candidates = [ | ||||||||
| {user: {first_name: 'Karl', last_name: 'Marx'}, id: 1} as ViewAssignmentCandidate, | ||||||||
| {user: {first_name: 'Rosa', last_name: 'Luxemburg'}, id: 2} as ViewAssignmentCandidate, | ||||||||
| {user: {first_name: 'Kurt', last_name: 'Eisner'}, id: 3} as ViewAssignmentCandidate, | ||||||||
| {user: {first_name: 'Clara', last_name: 'Zetkin'}, id: 4} as ViewAssignmentCandidate | ||||||||
|
Comment on lines
+33
to
+36
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tests below assume 5 users, so one seems to be missing here. |
||||||||
| ]; | ||||||||
| (component as any)._assignmentCandidates = candidates; | ||||||||
| onSortingChangeSpy = spyOn(component, 'onSortingChange').and.returnValue(Promise.resolve()); | ||||||||
| }); | ||||||||
|
|
||||||||
| it('should sort candidates by first name', async () => { | ||||||||
| await component.sortCandidatesByFirstName(); | ||||||||
| const sortedCandidates = onSortingChangeSpy.calls.mostRecent().args[0]; | ||||||||
| expect(sortedCandidates.map((c: ViewAssignmentCandidate) => c.user.first_name)).toEqual(['Clara', 'Karl', 'Karl', 'Kurt', 'Rosa']); | ||||||||
| expect(sortedCandidates.map((c: ViewAssignmentCandidate) => c.user.last_name)).toEqual(['Zetkin', 'Liebknecht', 'Marx', 'Eisner', 'Luxemburg']); | ||||||||
|
Comment on lines
+45
to
+46
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is shorter. Should also be done for the other test. |
||||||||
| }); | ||||||||
|
|
||||||||
| it('should sort candidates by last name', async () => { | ||||||||
| await component.sortCandidatesByLastName(); | ||||||||
| const sortedCandidates = onSortingChangeSpy.calls.mostRecent().args[0]; | ||||||||
| expect(sortedCandidates.map((c: ViewAssignmentCandidate) => c.user.last_name)).toEqual(['Eisner', 'Liebknecht', 'Luxemburg', 'Marx', 'Zetkin']); | ||||||||
| expect(sortedCandidates.map((c: ViewAssignmentCandidate) => c.user.first_name)).toEqual(['Kurt', 'Karl', 'Rosa', 'Karl', 'Clara']); | ||||||||
| }); | ||||||||
| }); | ||||||||
| }); | ||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -432,6 +432,29 @@ export class AssignmentDetailComponent extends BaseMeetingComponent implements O | |||||
| this.itemRepo.removeFromAgenda(this.assignment.agenda_item_id!); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Sorts the assignment candidates by their last name in ascending order. | ||||||
| * Calls onSortingChange with the sorted array. | ||||||
| */ | ||||||
| public async sortCandidatesByLastName(): Promise<void> { | ||||||
| const sorted = [...this.assignmentCandidates].sort((a, b) => | ||||||
| a.user?.last_name?.localeCompare(b.user?.last_name ?? '') ?? 0 | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this'll sort particularly well if
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for the function below. Also, since they're so similar, perhaps you could consider unifying them into a single function? Or maybe just join the first and last name with a There's also the question of what'll happen if there is neither first, nor last name. In that case the user will be shown as The |
||||||
| ); | ||||||
| await this.onSortingChange(sorted); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Sorts the assignment candidates by their first name in ascending order. | ||||||
| * Calls onSortingChange with the sorted array. | ||||||
| */ | ||||||
| public async sortCandidatesByFirstName(): Promise<void> { | ||||||
| const sorted = [...this.assignmentCandidates].sort((a, b) => | ||||||
| a.user?.first_name?.localeCompare(b.user?.first_name ?? '') ?? 0 | ||||||
| ); | ||||||
| await this.onSortingChange(sorted); | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| public override ngOnDestroy(): void { | ||||||
| super.ngOnDestroy(); | ||||||
| if (this._navigationSubscription) { | ||||||
|
|
@@ -457,6 +480,6 @@ export class AssignmentDetailComponent extends BaseMeetingComponent implements O | |||||
| } | ||||||
|
|
||||||
| public goToHistory(): void { | ||||||
| this.router.navigate([this.activeMeetingId!, `history`], { queryParams: { fqid: this.assignment.fqid } }); | ||||||
| this.router.navigate([this.activeMeetingId!, `history`], {queryParams: {fqid: this.assignment.fqid}}); | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't typically write tests for components (only services, pipes and the like). I don't even think we have any working component tests currently, not that we would be against getting one.
In any case, this test won't be called as long as the main test function (
xdescribe('AssignmentDetailComponent', ...) is x-ed out.So there's two choices right now:
I still reviewed your test code, just in case you want to go with option 1.