Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,6 @@ describe('IdeaSummaryComponent', () => {
});
});

describe('when expanding for the first time', () => {
beforeEach(() => {
component['expanded'] = false;
component['responses'] = [];
});

it('should not fetch responses again when already loaded', async () => {
component['responses'] = [{ text: 'Existing response', timestamp: 123456 }];

const getComponentSpy = spyOn(projectService, 'getComponent');
const getLatestWorkSpy = spyOn<any>(component, 'getLatestWork');

await component['toggleDetails']();

expect(getComponentSpy).not.toHaveBeenCalled();
expect(getLatestWorkSpy).not.toHaveBeenCalled();
});
});

describe('getDGResponsesWithIdea()', () => {
it('should return responses with the specified idea', () => {
const states = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,28 @@ export class IdeaSummaryComponent extends TeacherSummaryDisplayComponent {
protected expanded: boolean = false;
protected responses: Response[] = [];

protected renderDisplay(): void {
super.renderDisplay();
this.getResponses();
}

protected async toggleDetails(): Promise<void> {
this.expanded = !this.expanded;
if (this.responses.length === 0) {
const component = this.projectService.getComponent(this.nodeId, this.componentId);
const states = await firstValueFrom(this.getLatestWork());
if (component.type === 'DialogGuidance') {
this.responses = this.getDGResponsesWithIdea(states, this.idea.id);
} else if (component.type === 'OpenResponse') {
this.responses = this.getORResponsesWithIdea(states, this.idea.id);
}
if (this.responses.length > 2) {
this.responses = this.responses.slice(0, 2); // only show 2 responses max
}
if (this.expanded) {
await this.getResponses();
}
}

private async getResponses(): Promise<void> {
const component = this.projectService.getComponent(this.nodeId, this.componentId);
const states = await firstValueFrom(this.getLatestWork());
if (component.type === 'DialogGuidance') {
this.responses = this.getDGResponsesWithIdea(states, this.idea.id);
} else if (component.type === 'OpenResponse') {
this.responses = this.getORResponsesWithIdea(states, this.idea.id);
}
if (this.responses.length > 2) {
this.responses = this.responses.slice(0, 2); // only show 2 responses max
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('IdeasSummaryComponent for Open Response component', () => {
ngInit_OR_NoIdeasDetected_ShowMessage();
ngInit_OR_IdeasDetected_ShowSummary();
ngInit_OR_ManyIdeasDetected_ShowTopAndBottomThree();
ngInit_OR_FilterByPeriod();
});
});

Expand Down Expand Up @@ -218,3 +219,34 @@ function generateIdeas(numIdeas: number) {
}
return ideas;
}

function ngInit_OR_FilterByPeriod() {
describe('filtering by period', () => {
beforeEach(() => {
generateMockRubric(1, 1);
const ideas = generateIdeas(1);
spyOn(TestBed.inject(AnnotationService), 'getAnnotationsByNodeIdComponentId').and.returnValue(
[
new Annotation({ periodId: 1, data: { ideas: ideas } } as any),
new Annotation({ periodId: 2, data: { ideas: ideas } } as any)
]
);
});

it('includes all annotations when period is "All Periods" (-1)', () => {
component.periodId = -1;
spyOn<any>(component, 'groupIdeas');
component.ngOnInit();
const summaryData = (component as any).groupIdeas.calls.mostRecent().args[0];
expect(summaryData.dataPoints.length).toEqual(2);
});

it('includes only annotations for the selected period', () => {
component.periodId = 1;
spyOn<any>(component, 'groupIdeas');
component.ngOnInit();
const summaryData = (component as any).groupIdeas.calls.mostRecent().args[0];
expect(summaryData.dataPoints.length).toEqual(1);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,10 @@ export class IdeasSummaryComponent extends TeacherSummaryDisplayComponent {
this.groupIdeas(new DialogGuidanceSummaryData(componentStates, this.rubric))
);
} else if (this.componentType === 'OpenResponse') {
this.groupIdeas(
new OpenResponseSummaryData(
this.annotationService.getAnnotationsByNodeIdComponentId(this.nodeId, this.componentId),
this.rubric
)
);
const annotations = this.annotationService
.getAnnotationsByNodeIdComponentId(this.nodeId, this.componentId)
.filter((annotation) => this.periodId === -1 || annotation.periodId === this.periodId);
this.groupIdeas(new OpenResponseSummaryData(annotations, this.rubric));
}
}

Expand Down
Loading