Skip to content

Commit

Permalink
feat(MatchComponentDataExportStrategy): Include ideas detected by CRa…
Browse files Browse the repository at this point in the history
…ter in export (#2081)
  • Loading branch information
hirokiterashima authored Feb 6, 2025
1 parent a6dc5c6 commit 8d77009
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,15 @@ export abstract class AbstractComponentDataExportStrategy extends AbstractDataEx

protected abstract getComponentTypeWithUnderscore(): string;

protected getComponentStates(component: any): ComponentState[] {
protected getComponentStates(
component: any,
calculateRevisions: boolean = true
): ComponentState[] {
let componentStates = this.dataService.getComponentStatesByComponentId(component.id);
this.sortByWorkgroupIdAndTimestamp(componentStates);
this.calculateRevisionNumbers(componentStates);
if (calculateRevisions) {
this.calculateRevisionNumbers(componentStates);
}
if (this.allOrLatest === 'latest') {
componentStates = this.getLatestRevisions(componentStates);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ function exportAllRevisions(): void {
]);
setUpExportStrategy('all');
exportStrategyTester.componentExportStrategy.export();
const headerRow = exportStrategyTester.createHeaderRowAddAdditionalColumnsAtEnd(
additionalColumns
);
const headerRow =
exportStrategyTester.createHeaderRowAddAdditionalColumnsAtEnd(additionalColumns);

expect(exportStrategyTester.componentExportStrategy.generateCSVFile).toHaveBeenCalledWith(
[
headerRow,
Expand Down Expand Up @@ -241,9 +241,8 @@ function exportLatestRevisions(): void {
]);
setUpExportStrategy('latest');
exportStrategyTester.componentExportStrategy.export();
const headerRow = exportStrategyTester.createHeaderRowAddAdditionalColumnsAtEnd(
additionalColumns
);
const headerRow =
exportStrategyTester.createHeaderRowAddAdditionalColumnsAtEnd(additionalColumns);
expect(exportStrategyTester.componentExportStrategy.generateCSVFile).toHaveBeenCalledWith(
[
headerRow,
Expand Down Expand Up @@ -339,9 +338,8 @@ function exportMatchComponentWithChoiceReuse(): void {
exportStrategyTester.setStudentData([componentState1]);
setUpExportStrategy('all');
exportStrategyTester.componentExportStrategy.export();
const headerRow = exportStrategyTester.createHeaderRowAddAdditionalColumnsAtEnd(
additionalColumns
);
const headerRow =
exportStrategyTester.createHeaderRowAddAdditionalColumnsAtEnd(additionalColumns);
expect(exportStrategyTester.componentExportStrategy.generateCSVFile).toHaveBeenCalledWith(
[
headerRow,
Expand Down Expand Up @@ -399,9 +397,8 @@ function exportMatchComponentWithCorrectPosition(): void {
exportStrategyTester.setStudentData([componentState1]);
setUpExportStrategy('all');
exportStrategyTester.componentExportStrategy.export();
const headerRow = exportStrategyTester.createHeaderRowAddAdditionalColumnsAtEnd(
additionalColumns
);
const headerRow =
exportStrategyTester.createHeaderRowAddAdditionalColumnsAtEnd(additionalColumns);
expect(exportStrategyTester.componentExportStrategy.generateCSVFile).toHaveBeenCalledWith(
[
headerRow,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class MatchComponentDataExportStrategy extends AbstractComponentDataExpor
for (const choice of component.choices) {
headerRow.push(choice.value);
}
headerRow = this.addCRaterChoices(component, headerRow);
if (this.componentHasCorrectAnswer(component)) {
for (const choice of component.choices) {
headerRow.push(`${choice.value} ${this.correctnessLabel}`);
Expand All @@ -35,6 +36,17 @@ export class MatchComponentDataExportStrategy extends AbstractComponentDataExpor
}
}

private addCRaterChoices(component: any, headerRow: string[]): string[] {
this.getComponentStates(component, false).forEach((componentState: any) =>
componentState.studentData.buckets.forEach((bucket: Bucket) =>
bucket.items
.filter((item) => !item.studentCreated && !headerRow.includes(item.value))
.forEach((item: Choice) => headerRow.push(item.value))
)
);
return headerRow;
}

private componentHasCorrectAnswer(component: MatchContent): boolean {
return component.feedback.some((feedback: any) =>
feedback.choices.some((choice: any) => choice.isCorrect)
Expand Down

0 comments on commit 8d77009

Please sign in to comment.