Skip to content
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

test(Peer Chat Export): Add tests and component export strategy tester #1507

Merged
merged 1 commit into from
Nov 7, 2023
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
@@ -1,97 +1,68 @@
import { of } from 'rxjs';
import { DataExportService } from '../../../services/dataExportService';
import { DataExportComponent } from '../data-export/data-export.component';
import { DiscussionComponentDataExportStrategy } from './DiscussionComponentDataExportStrategy';
import { TeacherDataService } from '../../../services/teacherDataService';
import { ConfigService } from '../../../services/configService';
import { AnnotationService } from '../../../services/annotationService';
import { TeacherProjectService } from '../../../services/teacherProjectService';
import { TeacherWebSocketService } from '../../../services/teacherWebSocketService';
import { ExportStrategyTester } from './ExportStrategyTester';

const componentId = 'component1';
const componentPosition = 0;
const componentPrompt = 'Discuss with your classmates.';
const componentType = 'Discussion';
const nodeId = 'node1';
const nodePositionAndTitle = '1.1: Discuss';
const periodName = 'Period 1';
const projectId = 10;
const projectTitle = 'Discussion Project';
const runId = 10;
const stepNumber = '1.1';
const studentName1 = 'Student A';
const studentName2 = 'Student B';
let exportStrategyTester: ExportStrategyTester;
const studentWorkId1 = 10000;
const studentWorkId2 = 10001;
const studentWorkResponse1 = 'Hello';
const studentWorkResponse2 = 'World';
const userId1 = 100;
const userId2 = 101;
const workgroupId1 = 1000;
const workgroupId2 = 1001;

const componentPartNumber = componentPosition + 1;
const studentData1 = { response: studentWorkResponse1 };
const studentData2 = { componentStateIdReplyingTo: studentWorkId1, response: studentWorkResponse2 };
const workgroupUserInfo1 = {
periodName: periodName,
users: [{ id: userId1, name: studentName1 }]
};
const workgroupUserInfo2 = {
periodName: periodName,
users: [{ id: userId2, name: studentName2 }]
};

const annotationService: AnnotationService = new AnnotationService(null, null, null);
let configService: ConfigService;
let dataExportService: DataExportService;
let discussionExportStrategy: DiscussionComponentDataExportStrategy;
let generateCSVFileSpy: jasmine.Spy;
let teacherDataService: TeacherDataService;
let teacherProjectService: TeacherProjectService;
const teacherWebSocketService: TeacherWebSocketService = new TeacherWebSocketService(
null,
null,
null,
null
);

describe('DiscussionComponentDataExportStrategy', () => {
beforeEach(() => {
exportStrategyTester = new ExportStrategyTester();
exportStrategyTester.setUpServices();
});
describe('export', () => {
it('generates export with correct rows of data', () => {
setUpServices();
setUpDiscussionExportStrategy();
setStudentData([
createDiscussionComponentState(studentWorkId1, workgroupId1, studentData1),
createDiscussionComponentState(studentWorkId2, workgroupId2, studentData2)
exportStrategyTester.setComponent({
id: exportStrategyTester.componentId,
type: 'Discussion',
prompt: exportStrategyTester.componentPrompt
});
exportStrategyTester.setStudentData([
createDiscussionComponentState(
studentWorkId1,
exportStrategyTester.workgroupId1,
studentData1
),
createDiscussionComponentState(
studentWorkId2,
exportStrategyTester.workgroupId2,
studentData2
)
]);
discussionExportStrategy.export();
expect(discussionExportStrategy.controller.generateCSVFile).toHaveBeenCalledWith(
setUpExportStrategy();
exportStrategyTester.componentExportStrategy.export();
expect(
exportStrategyTester.componentExportStrategy.controller.generateCSVFile
).toHaveBeenCalledWith(
[
discussionExportStrategy.defaultDiscussionColumnNames,
exportStrategyTester.componentExportStrategy.defaultDiscussionColumnNames,
[
1,
workgroupId1,
userId1,
studentName1,
exportStrategyTester.workgroupId1,
exportStrategyTester.userId1,
exportStrategyTester.studentName1,
'',
'',
'',
'',
periodName,
projectId,
projectTitle,
runId,
exportStrategyTester.periodName,
exportStrategyTester.projectId,
exportStrategyTester.projectTitle,
exportStrategyTester.runId,
'',
'',
'',
'',
nodeId,
componentId,
componentPartNumber,
nodePositionAndTitle,
componentType,
componentPrompt,
exportStrategyTester.nodeId,
exportStrategyTester.component.id,
exportStrategyTester.componentPartNumber,
exportStrategyTester.nodePositionAndTitle,
exportStrategyTester.component.type,
exportStrategyTester.component.prompt,
studentData1,
studentWorkId1,
studentWorkId1,
Expand All @@ -100,126 +71,53 @@ describe('DiscussionComponentDataExportStrategy', () => {
],
[
2,
workgroupId2,
userId2,
studentName2,
exportStrategyTester.workgroupId2,
exportStrategyTester.userId2,
exportStrategyTester.studentName2,
'',
'',
'',
'',
periodName,
projectId,
projectTitle,
runId,
exportStrategyTester.periodName,
exportStrategyTester.projectId,
exportStrategyTester.projectTitle,
exportStrategyTester.runId,
'',
'',
'',
'',
nodeId,
componentId,
componentPartNumber,
nodePositionAndTitle,
componentType,
componentPrompt,
exportStrategyTester.nodeId,
exportStrategyTester.componentId,
exportStrategyTester.componentPartNumber,
exportStrategyTester.nodePositionAndTitle,
exportStrategyTester.component.type,
exportStrategyTester.component.prompt,
studentData2,
studentWorkId1,
studentWorkId2,
2,
studentWorkResponse2
]
],
`${runId}_step_${stepNumber}_component_${componentPartNumber}_discussion_work.csv`
exportStrategyTester.createExpectedFileName('discussion')
);
});
});
});

function setUpServices(): void {
setUpConfigService();
setUpDataExportService();
setUpTeacherProjectService();
setUpTeacherDataService();
}

function setUpConfigService(): void {
configService = new ConfigService(null, null);
spyOn(configService, 'getUserInfoByWorkgroupId').and.callFake((workgroupId: number) => {
switch (workgroupId) {
case workgroupId1:
return workgroupUserInfo1;
case workgroupId2:
return workgroupUserInfo2;
}
});
spyOn(configService, 'getRunId').and.returnValue(runId);
spyOn(configService, 'getProjectId').and.returnValue(projectId);
}

function setUpDataExportService(): void {
dataExportService = new DataExportService(null, null, null);
spyOn(dataExportService, 'retrieveStudentData').and.returnValue(of({}));
}

function setUpTeacherProjectService(): void {
teacherProjectService = new TeacherProjectService(null, null, null, null, null);
spyOn(teacherProjectService, 'getNodePositionById').and.returnValue(stepNumber);
spyOn(teacherProjectService, 'getNodePositionAndTitle').and.returnValue(nodePositionAndTitle);
spyOn(teacherProjectService, 'getComponentPosition').and.returnValue(componentPosition);
spyOn(teacherProjectService, 'getProjectTitle').and.returnValue(projectTitle);
}

function setUpTeacherDataService(): void {
teacherDataService = new TeacherDataService(
null,
annotationService,
configService,
teacherProjectService,
teacherWebSocketService
);
}

function setUpDiscussionExportStrategy(): void {
discussionExportStrategy = new DiscussionComponentDataExportStrategy(nodeId, {
id: componentId,
type: componentType,
prompt: componentPrompt
});
discussionExportStrategy.controller = createDataExportComponent();
discussionExportStrategy.dataExportService = dataExportService;
discussionExportStrategy.teacherDataService = teacherDataService;
discussionExportStrategy.configService = configService;
discussionExportStrategy.projectService = teacherProjectService;
}

function createDataExportComponent(): any {
const controller = new DataExportComponent(
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
function setUpExportStrategy(): void {
exportStrategyTester.setUpExportStrategy(
new DiscussionComponentDataExportStrategy(
exportStrategyTester.nodeId,
exportStrategyTester.component
)
);
spyOn(controller, 'showDownloadingExportMessage').and.callFake(() => {});
generateCSVFileSpy = spyOn(controller, 'generateCSVFile').and.callFake(() => {});
spyOn(controller, 'hideDownloadingExportMessage').and.callFake(() => {});
controller.includeStudentNames = true;
return controller;
}

function createDiscussionComponentState(id: number, workgroupId: number, studentData: any): any {
const componentState = {
return {
id: id,
workgroupId: workgroupId,
studentData: studentData
};
return componentState;
}

function setStudentData(componentStates: any[]): void {
spyOn(teacherDataService, 'getComponentStatesByComponentId').and.returnValue(componentStates);
}
Loading
Loading