Skip to content

Commit

Permalink
Include study courses in current events list #671
Browse files Browse the repository at this point in the history
  • Loading branch information
hupf committed May 2, 2024
1 parent c168267 commit 1412769
Show file tree
Hide file tree
Showing 15 changed files with 459 additions and 120 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
<h1>{{ "events.current.title" | translate }}</h1>
<bkd-events-list [withRatings]="false"></bkd-events-list>
<bkd-events-list
[withStudyCourses]="true"
[withRatings]="false"
></bkd-events-list>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="designation">
<a [href]="event.detailLink">{{ event.Designation }}</a>
<a [href]="event.detailLink">{{ event.designation }}</a>
</div>
<div class="date">
<span *ngIf="event.dateFrom && event.dateTo"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";
import { buildEvent } from "src/spec-builders";
import { buildEventEntry } from "src/spec-builders";
import { buildTestModuleMetadata } from "src/spec-helpers";
import { EventsListEntryComponent } from "./events-list-entry.component";

Expand All @@ -19,7 +19,7 @@ describe("EventsListEntryComponent", () => {
component = fixture.componentInstance;
element = fixture.debugElement.nativeElement;

component.event = buildEvent(1);
component.event = buildEventEntry(1);
component.event.evaluationText = "Lorem ipsum";
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DatePipe, NgIf } from "@angular/common";
import { Component, Input } from "@angular/core";
import { RouterLink } from "@angular/router";
import { TranslateModule } from "@ngx-translate/core";
import { Event } from "../../services/events-state.service";
import { EventEntry } from "../../services/events-state.service";

@Component({
selector: "bkd-events-list-entry",
Expand All @@ -12,6 +12,6 @@ import { Event } from "../../services/events-state.service";
styleUrl: "./events-list-entry.component.scss",
})
export class EventsListEntryComponent {
@Input() event: Event;
@Input() withRatings: boolean = true;
@Input() event: EventEntry;
@Input() withRatings = true;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div
class="bkd-container"
*bkdLet="{ events: state.getEvents(withRatings) | async } as data"
*bkdLet="{ events: state.getEntries(withRatings) | async } as data"
>
<bkd-resettable-input
class="d-flex search"
Expand Down
43 changes: 31 additions & 12 deletions src/app/events/components/events-list/events-list.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentFixture, TestBed, waitForAsync } from "@angular/core/testing";
import { BehaviorSubject, of } from "rxjs";
import { buildTestModuleMetadata } from "src/spec-helpers";
import { buildEvent } from "../../../../spec-builders";
import { buildTestModuleMetadata, changeInput } from "src/spec-helpers";
import { buildEventEntry } from "../../../../spec-builders";
import { StorageService } from "../../../shared/services/storage.service";
import { EventsStateService } from "../../services/events-state.service";
import { EventsListComponent } from "./events-list.component";
Expand All @@ -12,18 +12,21 @@ describe("EventsListComponent", () => {
let stateServiceMock: EventsStateService;
let element: HTMLElement;
let roles$: BehaviorSubject<Option<ReadonlyArray<string>>>;
let setWithStudyCourses: jasmine.Spy;

beforeEach(waitForAsync(() => {
roles$ = new BehaviorSubject<Option<ReadonlyArray<string>>>(null);
setWithStudyCourses = jasmine.createSpy("setWithStudyCourses");
stateServiceMock = {
loading$: of(false),
events$: of([buildEvent(1)]),
events$: of([buildEventEntry(1)]),
search$: of(""),
roles$,
setRoles(roles: Option<ReadonlyArray<string>>) {
roles$.next(roles);
},
getEvents: () => of([buildEvent(1)]),
setWithStudyCourses,
getEntries: () => of([buildEventEntry(1)]),
} as unknown as EventsStateService;

TestBed.configureTestingModule(
Expand Down Expand Up @@ -51,17 +54,33 @@ describe("EventsListComponent", () => {
fixture.detectChanges();
});

it("renders entry without ratings column", () => {
component.withRatings = false;
describe("withRatings", () => {
it("renders entry without ratings column", () => {
component.withRatings = false;

fixture.detectChanges();
expect(element.textContent).not.toContain("events.rating");
fixture.detectChanges();
expect(element.textContent).not.toContain("events.rating");
});

it("renders entry with ratings column", () => {
component.withRatings = true;

fixture.detectChanges();
expect(element.textContent).toContain("events.rating");
});
});

it("renders entry with ratings column", () => {
component.withRatings = true;
describe("withStudyCourses", () => {
it("enables study courses on state service if set to true", () => {
changeInput(component, "withStudyCourses", true);
fixture.detectChanges();
expect(setWithStudyCourses).toHaveBeenCalledWith(true);
});

fixture.detectChanges();
expect(element.textContent).toContain("events.rating");
it("does not enable study courses on state service if set to false", () => {
changeInput(component, "withStudyCourses", false);
fixture.detectChanges();
expect(setWithStudyCourses).toHaveBeenCalledWith(false);
});
});
});
14 changes: 11 additions & 3 deletions src/app/events/components/events-list/events-list.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AsyncPipe, NgFor, NgIf } from "@angular/common";
import { Component, Input } from "@angular/core";
import { Component, Input, OnChanges, SimpleChanges } from "@angular/core";
import { TranslateModule } from "@ngx-translate/core";
import { ResettableInputComponent } from "../../../shared/components/resettable-input/resettable-input.component";
import { SpinnerComponent } from "../../../shared/components/spinner/spinner.component";
Expand All @@ -24,12 +24,20 @@ import { EventsListEntryComponent } from "../events-list-entry/events-list-entry
EventsListEntryComponent,
],
})
export class EventsListComponent {
@Input() withRatings: boolean = true;
export class EventsListComponent implements OnChanges {
@Input() withStudyCourses = false;
@Input() withRatings = true;

constructor(
public state: EventsStateService,
private storage: StorageService,
) {
this.state.setRoles(this.storage.getPayload()?.roles ?? null);
}

ngOnChanges(changes: SimpleChanges): void {
if (changes["withStudyCourses"]) {
this.state.setWithStudyCourses(changes["withStudyCourses"].currentValue);
}
}
}
84 changes: 64 additions & 20 deletions src/app/events/services/events-state.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,32 @@ import { HttpTestingController } from "@angular/common/http/testing";
import { TestBed } from "@angular/core/testing";
import * as t from "io-ts/lib/index";
import { Course } from "src/app/shared/models/course.model";
import { Event } from "src/app/shared/models/event.model";
import { StudyClass } from "src/app/shared/models/study-class.model";
import {
buildCourse,
buildFinalGrading,
buildStudyClass,
} from "src/spec-builders";
import { buildTestModuleMetadata } from "src/spec-helpers";
import { Event, EventState, EventsStateService } from "./events-state.service";
import {
EventEntry,
EventState,
EventsStateService,
} from "./events-state.service";

describe("EventsStateService", () => {
let service: EventsStateService;
let httpTestingController: HttpTestingController;

let courseEvents: Event[];
let courses: Course[];
let studyClassEvents: Event[];
let courseEntries: EventEntry[];
let studyCourses: Event[];
let studyCoursesEntries: EventEntry[];
let studyClasses: StudyClass[];
let studyClassEntries: EventEntry[];
let assessments: StudyClass[];
let assessmentEvents: Event[];
let assessmentEntries: EventEntry[];

beforeEach(() => {
TestBed.configureTestingModule(buildTestModuleMetadata());
Expand All @@ -45,21 +52,21 @@ describe("EventsStateService", () => {
};

studyClasses = [buildStudyClass(5, "22a"), buildStudyClass(6, "22b")];
studyClassEvents = [
studyClassEntries = [
{
id: 5,
Designation: "22a",
designation: "22a",
detailLink: "link-to-event-detail-module/5",
studentCount: 0,
state: null,
},
];

assessments = [studyClasses[1]];
assessmentEvents = [
assessmentEntries = [
{
id: 6,
Designation: "22b",
designation: "22b",
detailLink: "link-to-event-detail-module/6",
studentCount: 0,
state: EventState.Rating,
Expand Down Expand Up @@ -121,9 +128,9 @@ describe("EventsStateService", () => {
ratedCourse,
];

const courseEvent: Event = {
const courseEvent: EventEntry = {
id: 1,
Designation: "Physik, 22a, 22b",
designation: "Physik, 22a, 22b",
detailLink: "link-to-event-detail-module/1",
dateFrom: new Date("2022-02-09T00:00:00"),
dateTo: new Date("2022-06-30T00:00:00"),
Expand All @@ -133,11 +140,11 @@ describe("EventsStateService", () => {
evaluationLink: null,
};

courseEvents = [
courseEntries = [
{
...courseEvent,
id: 2,
Designation: "Bio, 22a",
designation: "Bio, 22a",
detailLink: "link-to-event-detail-module/2",
state: EventState.RatingUntil,
evaluationText: "events.state.rating-until 03.06.2022",
Expand All @@ -146,7 +153,7 @@ describe("EventsStateService", () => {
{
...courseEvent,
id: 4,
Designation: "Franz, 22a, 22b",
designation: "Franz, 22a, 22b",
detailLink: "link-to-event-detail-module/4",
state: EventState.Tests,
evaluationText: "events.state.add-tests",
Expand All @@ -155,13 +162,24 @@ describe("EventsStateService", () => {
{
...courseEvent,
id: 3,
Designation: "Zeichnen, 22b",
designation: "Zeichnen, 22b",
detailLink: "link-to-event-detail-module/3",
state: EventState.IntermediateRating,
evaluationText: "events.state.intermediate-rating",
evaluationLink: "link-to-evaluation-module/3",
},
];

studyCourses = [{ Id: 10, Designation: "Zoologie", StudentCount: 42 }];
studyCoursesEntries = [
{
id: 10,
designation: "Zoologie",
studentCount: 42,
detailLink: "link-to-event-detail-module/10",
state: null,
},
];
});

afterEach(() => {
Expand All @@ -174,11 +192,11 @@ describe("EventsStateService", () => {
});

it("loads events", () => {
service.getEvents().subscribe((result) => {
service.getEntries().subscribe((result) => {
expect(result).toEqual([
...studyClassEvents,
...assessmentEvents,
...courseEvents,
...studyClassEntries,
...assessmentEntries,
...courseEntries,
]);
});

Expand All @@ -188,6 +206,26 @@ describe("EventsStateService", () => {

httpTestingController.verify();
});

it("loads events with study courses", () => {
service.setWithStudyCourses(true);

service.getEntries().subscribe((result) => {
expect(result).toEqual([
...studyClassEntries,
...assessmentEntries,
...courseEntries,
...studyCoursesEntries,
]);
});

expectCoursesRequest();
expectStudyCoursesRequest();
expectFormativeAssessmentsRequest();
expectStudyClassesRequest();

httpTestingController.verify();
});
});

describe("without ClassTeacherRole", () => {
Expand All @@ -197,7 +235,7 @@ describe("EventsStateService", () => {

it("loads events", () => {
service
.getEvents()
.getEntries()
.subscribe((result) =>
expect(result.map((r) => r.id)).toEqual([2, 4, 1, 3]),
);
Expand All @@ -209,7 +247,7 @@ describe("EventsStateService", () => {

it("loads events with ratings", () => {
service
.getEvents(true)
.getEntries(true)
.subscribe((result) =>
expect(result.map((r) => r.id)).toEqual([2, 4, 3]),
);
Expand All @@ -229,6 +267,12 @@ describe("EventsStateService", () => {
.flush(t.array(Course).encode(response));
}

function expectStudyCoursesRequest(response = studyCourses): void {
const url = "https://eventotest.api/Events/?filter.EventTypeId==1";

httpTestingController.expectOne(url).flush(t.array(Event).encode(response));
}

function expectFormativeAssessmentsRequest(response = assessments): void {
const url =
"https://eventotest.api/StudyClasses/FormativeAssessments?filter.IsActive==true";
Expand Down
Loading

0 comments on commit 1412769

Please sign in to comment.