-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schools): school list show a column stating the total number of …
…participants
- Loading branch information
1 parent
befb5e6
commit 8c757e4
Showing
7 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
...-dev-project/schools/display-participants-count/display-participants-count.component.html
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,3 @@ | ||
<p> | ||
{{ participantRelationsCount() }} | ||
</p> |
62 changes: 62 additions & 0 deletions
62
...v-project/schools/display-participants-count/display-participants-count.component.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,62 @@ | ||
import { ComponentFixture, TestBed } from "@angular/core/testing"; | ||
|
||
import { DisplayParticipantsCountComponent } from "./display-participants-count.component"; | ||
import { ChildrenService } from "../../children/children.service"; | ||
import { School } from "../model/school"; | ||
import { ChildSchoolRelation } from "../../children/model/childSchoolRelation"; | ||
|
||
describe("DisplayParticipantsCountComponent", () => { | ||
let component: DisplayParticipantsCountComponent; | ||
let fixture: ComponentFixture<DisplayParticipantsCountComponent>; | ||
|
||
let mockChildrenService: jasmine.SpyObj<ChildrenService>; | ||
|
||
const childSchoolRelations: ChildSchoolRelation[] = [ | ||
new ChildSchoolRelation("r-1"), | ||
new ChildSchoolRelation("r-2"), | ||
new ChildSchoolRelation("r-3"), | ||
]; | ||
|
||
beforeEach(async () => { | ||
mockChildrenService = jasmine.createSpyObj(["queryActiveRelationsOf"]); | ||
mockChildrenService.queryActiveRelationsOf.and.resolveTo( | ||
childSchoolRelations, | ||
); | ||
|
||
await TestBed.configureTestingModule({ | ||
imports: [DisplayParticipantsCountComponent], | ||
providers: [{ provide: ChildrenService, useValue: mockChildrenService }], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(DisplayParticipantsCountComponent); | ||
component = fixture.componentInstance; | ||
component.entity = new School("s-1"); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it("should create", () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it("should count correct number of active students for school", async () => { | ||
expect(component.participantRelationsCount()).toBeNull(); | ||
await component.ngOnChanges(); | ||
expect(component.participantRelationsCount()).toBeDefined(); | ||
expect(component.participantRelationsCount()).toBe(3); | ||
}); | ||
|
||
it("should handle empty response from ChildrenService", async () => { | ||
mockChildrenService.queryActiveRelationsOf.and.resolveTo([]); | ||
expect(component.participantRelationsCount()).toBeNull(); | ||
await component.ngOnChanges(); | ||
expect(component.participantRelationsCount()).toBeDefined(); | ||
expect(component.participantRelationsCount()).toBe(0); | ||
}); | ||
|
||
it("should handle error response from ChildrenService", async () => { | ||
mockChildrenService.queryActiveRelationsOf.and.rejectWith(new Error()); | ||
expect(component.participantRelationsCount()).toBeNull(); | ||
await component.ngOnChanges(); | ||
expect(component.participantRelationsCount()).toBeNull(); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
...ld-dev-project/schools/display-participants-count/display-participants-count.component.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,44 @@ | ||
import { Component, OnChanges, signal, WritableSignal } from "@angular/core"; | ||
import { CommonModule } from "@angular/common"; | ||
import { ChildrenService } from "../../children/children.service"; | ||
import { ViewDirective } from "../../../core/entity/default-datatype/view.directive"; | ||
import { DynamicComponent } from "../../../core/config/dynamic-components/dynamic-component.decorator"; | ||
import { ChildSchoolRelation } from "../../children/model/childSchoolRelation"; | ||
import { LoggingService } from "../../../core/logging/logging.service"; | ||
|
||
@DynamicComponent("DisplayParticipantsCount") | ||
@Component({ | ||
selector: "app-display-participants-count", | ||
standalone: true, | ||
imports: [CommonModule], | ||
templateUrl: "./display-participants-count.component.html", | ||
}) | ||
export class DisplayParticipantsCountComponent | ||
extends ViewDirective<any> | ||
implements OnChanges | ||
{ | ||
participantRelationsCount: WritableSignal<number> = signal(null); | ||
|
||
constructor( | ||
private _childrenService: ChildrenService, | ||
private _loggingService: LoggingService, | ||
) { | ||
super(); | ||
} | ||
|
||
override async ngOnChanges(): Promise<void> { | ||
super.ngOnChanges(); | ||
|
||
return this._childrenService | ||
.queryActiveRelationsOf("school", this.entity.getId()) | ||
.then((relations: ChildSchoolRelation[]) => { | ||
this.participantRelationsCount.set(relations.length); | ||
}) | ||
.catch((reason) => { | ||
this._loggingService.error( | ||
"Could not calculate participantRelationsCount, error response from ChildrenService." + | ||
reason, | ||
); | ||
}); | ||
} | ||
} |
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
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