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

refactor(ProjectService): Clean up calculateNodeNumbersHelper() #1510

Merged
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
21 changes: 21 additions & 0 deletions src/app/services/projectService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import demoProjectJSON_import from './sampleData/curriculum/Demo.project.json';
import oneBranchTwoPathsProjectJSON_import from './sampleData/curriculum/OneBranchTwoPaths.project.json';
import scootersProjectJSON_import from './sampleData/curriculum/SelfPropelledVehiclesChallenge.project.json';
import twoStepsProjectJSON_import from './sampleData/curriculum/TwoSteps.project.json';
import twoLesssonsProjectJSON_import from './sampleData/curriculum/TwoLessons.project.json';
import { PeerGrouping } from '../domain/peerGrouping';
import { StudentTeacherCommonServicesModule } from '../student-teacher-common-services.module';
import { EmbeddedContent } from '../../assets/wise5/components/embedded/EmbeddedContent';
Expand All @@ -25,6 +26,7 @@ let demoProjectJSON: any;
let oneBranchTwoPathsProjectJSON: any;
let scootersProjectJSON: any;
let twoStepsProjectJSON: any;
let twoLessonsProjectJSON: any;
describe('ProjectService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -38,6 +40,7 @@ describe('ProjectService', () => {
oneBranchTwoPathsProjectJSON = copy(oneBranchTwoPathsProjectJSON_import);
scootersProjectJSON = copy(scootersProjectJSON_import);
twoStepsProjectJSON = copy(twoStepsProjectJSON_import);
twoLessonsProjectJSON = copy(twoLesssonsProjectJSON_import);
});
shouldReplaceAssetPathsInNonHtmlComponentContent();
shouldReplaceAssetPathsInHtmlComponentContent();
Expand Down Expand Up @@ -434,6 +437,7 @@ function calculateNodeNumbers(): void {
calculateNodeNumbersWhenNoBranches();
calculateNodeNumbersWhenBranchInOneActivity();
calculateNodeNumbersWhenBranchSpansMultipleActivities();
calculateNodeNumbersWhenOnlyLessons();
}

function calculateNodeNumbersWhenNoBranches(): void {
Expand All @@ -442,6 +446,7 @@ function calculateNodeNumbersWhenNoBranches(): void {
service.project = twoStepsProjectJSON;
service.parseProject();
expectNodeIdsToHaveNumbers([
{ nodeId: 'group1', number: '1' },
{ nodeId: 'node1', number: '1.1' },
{ nodeId: 'node2', number: '1.2' }
]);
Expand All @@ -455,6 +460,7 @@ function calculateNodeNumbersWhenBranchInOneActivity(): void {
service.project = oneBranchTwoPathsProjectJSON;
service.parseProject();
expectNodeIdsToHaveNumbers([
{ nodeId: 'group1', number: '1' },
{ nodeId: 'node1', number: '1.1' },
{ nodeId: 'node2', number: '1.2' },
{ nodeId: 'node3', number: '1.3 A' },
Expand All @@ -474,9 +480,11 @@ function calculateNodeNumbersWhenBranchSpansMultipleActivities(): void {
service.project = branchSpansActivitiesProjectJSON;
service.parseProject();
expectNodeIdsToHaveNumbers([
{ nodeId: 'group1', number: '1' },
{ nodeId: 'node1', number: '1.1' },
{ nodeId: 'node2', number: '1.2 A' },
{ nodeId: 'node3', number: '1.2 B' },
{ nodeId: 'group2', number: '2' },
{ nodeId: 'node4', number: '2.1 A' },
{ nodeId: 'node5', number: '2.1 B' },
{ nodeId: 'node6', number: '2.2 B' },
Expand All @@ -486,6 +494,19 @@ function calculateNodeNumbersWhenBranchSpansMultipleActivities(): void {
});
}

function calculateNodeNumbersWhenOnlyLessons(): void {
describe('project with only lessons', () => {
it('should calculate node numbers correctly', () => {
service.project = twoLessonsProjectJSON;
service.parseProject();
expectNodeIdsToHaveNumbers([
{ nodeId: 'group1', number: '1' },
{ nodeId: 'group2', number: '2' }
]);
});
});
}

function expectNodeIdsToHaveNumbers(objs: any[]): void {
objs.forEach((obj: any) => {
expectNodeIdToHaveNumber(obj.nodeId, obj.number);
Expand Down
143 changes: 143 additions & 0 deletions src/app/services/sampleData/curriculum/TwoLessons.project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"nodes": [
{
"id": "group0",
"type": "group",
"title": "Master",
"startId": "group1",
"ids": [
"group1",
"group2"
]
},
{
"id": "group1",
"type": "group",
"title": "Lesson 1",
"startId": "",
"constraints": [],
"transitionLogic": {
"transitions": [
{
"to": "group2"
}
]
},
"ids": []
},
{
"id": "group2",
"type": "group",
"title": "Lesson 2",
"startId": "",
"constraints": [],
"transitionLogic": {
"transitions": []
},
"ids": []
}
],
"constraints": [],
"startGroupId": "group0",
"startNodeId": "group1",
"navigationMode": "guided",
"layout": {
"template": "starmap|leftNav|rightNav"
},
"metadata": {
"title": "Node Number Test",
"authors": [
{
"firstName": "g",
"lastName": "k",
"id": 3,
"username": "gk"
}
]
},
"notebook": {
"enabled": false,
"label": "Notebook",
"enableAddNew": true,
"itemTypes": {
"note": {
"type": "note",
"enabled": true,
"enableLink": true,
"enableAddNote": true,
"enableClipping": true,
"enableStudentUploads": true,
"requireTextOnEveryNote": false,
"label": {
"singular": "note",
"plural": "notes",
"link": "Notes",
"icon": "note",
"color": "#1565C0"
}
},
"report": {
"enabled": false,
"label": {
"singular": "report",
"plural": "reports",
"link": "Report",
"icon": "assignment",
"color": "#AD1457"
},
"notes": [
{
"reportId": "finalReport",
"title": "Final Report",
"description": "Final summary report of what you learned in this unit",
"prompt": "Use this space to write your final report using evidence from your notebook.",
"content": "<h3>This is a heading</h3><p>This is a paragraph.</p>"
}
]
}
}
},
"teacherNotebook": {
"enabled": true,
"label": "Teacher Notebook",
"enableAddNew": true,
"itemTypes": {
"note": {
"type": "note",
"enabled": false,
"enableLink": true,
"enableAddNote": true,
"enableClipping": true,
"enableStudentUploads": true,
"requireTextOnEveryNote": false,
"label": {
"singular": "note",
"plural": "notes",
"link": "Notes",
"icon": "note",
"color": "#1565C0"
}
},
"report": {
"enabled": true,
"label": {
"singular": "teacher notes",
"plural": "teacher notes",
"link": "Teacher Notes",
"icon": "assignment",
"color": "#AD1457"
},
"notes": [
{
"reportId": "teacherReport",
"title": "Teacher Notes",
"description": "Notes for the teacher as they're running the WISE unit",
"prompt": "Use this space to take notes for this unit",
"content": "<p>Use this space to take notes for this unit</p>"
}
]
}
}
},
"inactiveNodes": []
}
Loading
Loading