Skip to content

Commit 7a381fb

Browse files
Refactored ProjectService.getAllPaths(), consolidatePaths(), getParentGroup() and added tests. #2396
1 parent 3dce635 commit 7a381fb

4 files changed

Lines changed: 920 additions & 261 deletions

File tree

src/main/webapp/site/src/app/services/projectService.spec.ts

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { ProjectService } from '../../../../wise5/services/projectService';
55
import { ConfigService } from '../../../../wise5/services/configService';
66
import { UtilService } from '../../../../wise5/services/utilService';
77
import demoProjectJSON_import from './sampleData/curriculum/Demo.project.json';
8+
import oneBranchTwoPathsProjectJSON_import from './sampleData/curriculum/OneBranchTwoPaths.project.json';
89
import scootersProjectJSON_import from './sampleData/curriculum/SelfPropelledVehiclesChallenge.project.json';
910
import { getAuthServiceConfigs } from '../app.module';
11+
import twoStepsProjectJSON_import from './sampleData/curriculum/TwoSteps.project.json';
1012
import { SessionService } from '../../../../wise5/services/sessionService';
1113
const projectIdDefault = 1;
1214
const projectBaseURL = 'http://localhost:8080/curriculum/12345/';
@@ -19,7 +21,9 @@ let sessionService: SessionService;
1921
let utilService: UtilService;
2022
let http: HttpTestingController;
2123
let demoProjectJSON: any;
24+
let oneBranchTwoPathsProjectJSON: any;
2225
let scootersProjectJSON: any;
26+
let twoStepsProjectJSON: any;
2327

2428
describe('ProjectService', () => {
2529
beforeEach(() => {
@@ -34,7 +38,9 @@ describe('ProjectService', () => {
3438
spyOn(utilService, 'broadcastEventInRootScope').and.callFake(() => {});
3539
service = TestBed.get(ProjectService);
3640
demoProjectJSON = JSON.parse(JSON.stringify(demoProjectJSON_import));
41+
oneBranchTwoPathsProjectJSON = JSON.parse(JSON.stringify(oneBranchTwoPathsProjectJSON_import));
3742
scootersProjectJSON = JSON.parse(JSON.stringify(scootersProjectJSON_import));
43+
twoStepsProjectJSON = JSON.parse(JSON.stringify(twoStepsProjectJSON_import));
3844
});
3945
shouldReplaceAssetPathsInNonHtmlComponentContent();
4046
shouldReplaceAssetPathsInHtmlComponentContent();
@@ -87,9 +93,10 @@ describe('ProjectService', () => {
8793
deleteAllStepsInAnActivity();
8894
getTags();
8995
addCurrentUserToAuthors_CM_shouldAddUserInfo();
96+
getAllPaths();
97+
consolidatePaths();
98+
getParentGroup();
9099
// TODO: add test for service.getFlattenedProjectAsNodeIds()
91-
// TODO: add test for service.getAllPaths()
92-
// TODO: add test for service.consolidatePaths()
93100
// TODO: add test for service.consumePathsUntilNodeId()
94101
// TODO: add test for service.getFirstNodeIdInPathAtIndex()
95102
// TODO: add test for service.removeNodeIdFromPaths()
@@ -1060,3 +1067,57 @@ function addCurrentUserToAuthors_CM_shouldAddUserInfo() {
10601067
expect(authors[0].id).toEqual(1);
10611068
});
10621069
}
1070+
1071+
function getAllPaths() {
1072+
describe('getAllPaths()', () => {
1073+
it ('should get all paths in a unit with no branches', () => {
1074+
service.setProject(twoStepsProjectJSON);
1075+
const allPaths = service.getAllPaths([], service.getStartNodeId(), true);
1076+
expect(allPaths.length).toEqual(1);
1077+
expect(allPaths[0]).toEqual(['group1', 'node1', 'node2']);
1078+
});
1079+
it ('should get all paths in a unit with a branch with two paths', () => {
1080+
service.setProject(oneBranchTwoPathsProjectJSON);
1081+
const allPaths = service.getAllPaths([], service.getStartNodeId(), true);
1082+
expect(allPaths.length).toEqual(2);
1083+
expect(allPaths[0]).toEqual(['group1', 'node1', 'node2', 'node3', 'node4', 'node8']);
1084+
expect(allPaths[1]).toEqual(['group1', 'node1', 'node2', 'node5', 'node6', 'node7', 'node8']);
1085+
});
1086+
it ('should get all paths in a unit starting with a node in a branch path', () => {
1087+
service.setProject(oneBranchTwoPathsProjectJSON);
1088+
const allPaths1 = service.getAllPaths(['group1', 'node1', 'node2'], 'node3', true);
1089+
expect(allPaths1.length).toEqual(1);
1090+
expect(allPaths1[0]).toEqual(['node3', 'node4', 'node8']);
1091+
const allPaths2 = service.getAllPaths(['group1', 'node1', 'node2'], 'node5', true);
1092+
expect(allPaths2.length).toEqual(1);
1093+
expect(allPaths2[0]).toEqual(['node5', 'node6', 'node7', 'node8']);
1094+
});
1095+
});
1096+
}
1097+
1098+
function consolidatePaths() {
1099+
describe('consolidatePaths()', () => {
1100+
it('should consolidate all the paths into a linear list of node ids', () => {
1101+
service.setProject(oneBranchTwoPathsProjectJSON);
1102+
const allPaths = service.getAllPaths([], service.getStartNodeId(), true);
1103+
const consolidatedPaths = service.consolidatePaths(allPaths);
1104+
expect(consolidatedPaths).toEqual(['group1', 'node1', 'node2', 'node3', 'node4', 'node5',
1105+
'node6', 'node7', 'node8']);
1106+
});
1107+
});
1108+
}
1109+
1110+
function getParentGroup() {
1111+
describe('getParentGroup()', () => {
1112+
it('should get the parent group of an active node', () => {
1113+
service.setProject(oneBranchTwoPathsProjectJSON);
1114+
const parentGroup = service.getParentGroup('node1');
1115+
expect(parentGroup.id).toEqual('group1');
1116+
});
1117+
it('should get the parent group of an inactive node', () => {
1118+
service.setProject(twoStepsProjectJSON);
1119+
const parentGroup = service.getParentGroup('node3');
1120+
expect(parentGroup.id).toEqual('group2');
1121+
});
1122+
});
1123+
}

0 commit comments

Comments
 (0)