From 0b5a3259e1362efc1bf2c01e0e6ac69a60d14776 Mon Sep 17 00:00:00 2001 From: Hiroki Terashima Date: Mon, 11 Dec 2023 17:58:00 -0800 Subject: [PATCH] refactor(TeacherProjectService): Move getBranchLetter to OneWorkgroupPerRowDataExportStrategy --- .../services/teacherProjectService.spec.ts | 19 ------------------ ...eWorkgroupPerRowDataExportStrategy.spec.ts | 20 +++++++++++++++++++ .../OneWorkgroupPerRowDataExportStrategy.ts | 17 +++++++++++++++- .../wise5/services/teacherProjectService.ts | 15 -------------- src/messages.xlf | 12 +++++------ 5 files changed, 42 insertions(+), 41 deletions(-) create mode 100644 src/assets/wise5/classroomMonitor/dataExport/strategies/OneWorkgroupPerRowDataExportStrategy.spec.ts diff --git a/src/app/services/teacherProjectService.spec.ts b/src/app/services/teacherProjectService.spec.ts index 0089b73b0c4..c2fba1cc8e6 100644 --- a/src/app/services/teacherProjectService.spec.ts +++ b/src/app/services/teacherProjectService.spec.ts @@ -47,7 +47,6 @@ describe('TeacherProjectService', () => { testDeleteTransition(); testGetNodeIdAfter(); testCreateNodeAfter(); - shouldGetTheBranchLetter(); lockNode(); unlockNode(); getNextAvailableNodeId(); @@ -204,24 +203,6 @@ function testCreateNodeAfter() { }); } -function shouldGetTheBranchLetter() { - it('should get the branch letter', () => { - service.setProject(teacherProjectJSON); - let branchLetter = service.getBranchLetter('node1'); - expect(branchLetter).toEqual(null); - branchLetter = service.getBranchLetter('node2'); - expect(branchLetter).toEqual('A'); - branchLetter = service.getBranchLetter('node3'); - expect(branchLetter).toEqual('A'); - branchLetter = service.getBranchLetter('node4'); - expect(branchLetter).toEqual('B'); - branchLetter = service.getBranchLetter('node5'); - expect(branchLetter).toEqual('B'); - branchLetter = service.getBranchLetter('node6'); - expect(branchLetter).toEqual(null); - }); -} - function lockNode() { describe('lockNode()', () => { it('should add teacherRemoval constraint to node', () => { diff --git a/src/assets/wise5/classroomMonitor/dataExport/strategies/OneWorkgroupPerRowDataExportStrategy.spec.ts b/src/assets/wise5/classroomMonitor/dataExport/strategies/OneWorkgroupPerRowDataExportStrategy.spec.ts new file mode 100644 index 00000000000..4568a44ad15 --- /dev/null +++ b/src/assets/wise5/classroomMonitor/dataExport/strategies/OneWorkgroupPerRowDataExportStrategy.spec.ts @@ -0,0 +1,20 @@ +import { TeacherProjectService } from '../../../services/teacherProjectService'; +import { OneWorkgroupPerRowDataExportStrategy } from './OneWorkgroupPerRowDataExportStrategy'; + +const strategy = new OneWorkgroupPerRowDataExportStrategy(); +class MockProjectService { + getNodePositionById(nodeId: string): string { + return { node1: '1.1', node2: '1.2A', node3: '1.2B' }[nodeId]; + } +} +describe('OneWorkgroupPerRowDataExportStrategy', () => { + describe('getBranchLetter()', () => { + it('gets the branch letter', () => { + strategy.projectService = new MockProjectService() as TeacherProjectService; + expect(strategy.getBranchLetter('node1')).toEqual(null); + expect(strategy.getBranchLetter('node2')).toEqual('A'); + expect(strategy.getBranchLetter('node3')).toEqual('B'); + expect(strategy.getBranchLetter('node4')).toEqual(null); + }); + }); +}); diff --git a/src/assets/wise5/classroomMonitor/dataExport/strategies/OneWorkgroupPerRowDataExportStrategy.ts b/src/assets/wise5/classroomMonitor/dataExport/strategies/OneWorkgroupPerRowDataExportStrategy.ts index 7fe633a989d..6dd5e15bbe2 100644 --- a/src/assets/wise5/classroomMonitor/dataExport/strategies/OneWorkgroupPerRowDataExportStrategy.ts +++ b/src/assets/wise5/classroomMonitor/dataExport/strategies/OneWorkgroupPerRowDataExportStrategy.ts @@ -222,7 +222,7 @@ export class OneWorkgroupPerRowDataExportStrategy extends AbstractDataExportStra } } if (this.controller.includeBranchPathTaken) { - var branchLetter = this.projectService.getBranchLetter(toNodeId); + var branchLetter = this.getBranchLetter(toNodeId); if (stepTitle != null) { workgroupRow[columnIdToColumnIndex[nodeId + '-branchPathTaken']] = branchLetter; } else { @@ -249,6 +249,21 @@ export class OneWorkgroupPerRowDataExportStrategy extends AbstractDataExportStra }); } + /** + * Get the branch letter in the node position string if the node is in a branch path + * @param nodeId the node id we want the branch letter for + * @return the branch letter in the node position if the node is in a branch path + */ + getBranchLetter(nodeId: string): string { + const nodePosition = this.projectService.getNodePositionById(nodeId); + const branchLetterRegex = /.*([A-Z])/; + const match = branchLetterRegex.exec(nodePosition); + if (match != null) { + return match[1]; + } + return null; + } + /** * Check if we want to export this component * @param selectedNodesMap a mapping of node id to boolean value of whether diff --git a/src/assets/wise5/services/teacherProjectService.ts b/src/assets/wise5/services/teacherProjectService.ts index 97244e5caa2..e55405e7965 100644 --- a/src/assets/wise5/services/teacherProjectService.ts +++ b/src/assets/wise5/services/teacherProjectService.ts @@ -870,21 +870,6 @@ export class TeacherProjectService extends ProjectService { return this.configService.getConfigParam('simulationProjectId') || -1; } - /** - * Get the branch letter in the node position string if the node is in a branch path - * @param nodeId the node id we want the branch letter for - * @return the branch letter in the node position if the node is in a branch path - */ - getBranchLetter(nodeId) { - const nodePosition = this.getNodePositionById(nodeId); - const branchLetterRegex = /.*([A-Z])/; - const match = branchLetterRegex.exec(nodePosition); - if (match != null) { - return match[1]; - } - return null; - } - componentChanged(): void { this.componentChangedSource.next(); } diff --git a/src/messages.xlf b/src/messages.xlf index bb461c14281..2d7d5605e63 100644 --- a/src/messages.xlf +++ b/src/messages.xlf @@ -21411,42 +21411,42 @@ If this problem continues, let your teacher know and move on to the next activit All steps after this one will not be visitable until src/assets/wise5/services/teacherProjectService.ts - 943 + 928 All steps after this one will not be visible until src/assets/wise5/services/teacherProjectService.ts - 946 + 931 All other steps will not be visitable until src/assets/wise5/services/teacherProjectService.ts - 949 + 934 All other steps will not be visible until src/assets/wise5/services/teacherProjectService.ts - 952 + 937 This step will not be visitable until src/assets/wise5/services/teacherProjectService.ts - 955 + 940 This step will not be visible until src/assets/wise5/services/teacherProjectService.ts - 958 + 943