@@ -5,8 +5,10 @@ import { ProjectService } from '../../../../wise5/services/projectService';
55import { ConfigService } from '../../../../wise5/services/configService' ;
66import { UtilService } from '../../../../wise5/services/utilService' ;
77import demoProjectJSON_import from './sampleData/curriculum/Demo.project.json' ;
8+ import oneBranchTwoPathsProjectJSON_import from './sampleData/curriculum/OneBranchTwoPaths.project.json' ;
89import scootersProjectJSON_import from './sampleData/curriculum/SelfPropelledVehiclesChallenge.project.json' ;
910import { getAuthServiceConfigs } from '../app.module' ;
11+ import twoStepsProjectJSON_import from './sampleData/curriculum/TwoSteps.project.json' ;
1012import { SessionService } from '../../../../wise5/services/sessionService' ;
1113const projectIdDefault = 1 ;
1214const projectBaseURL = 'http://localhost:8080/curriculum/12345/' ;
@@ -19,7 +21,9 @@ let sessionService: SessionService;
1921let utilService : UtilService ;
2022let http : HttpTestingController ;
2123let demoProjectJSON : any ;
24+ let oneBranchTwoPathsProjectJSON : any ;
2225let scootersProjectJSON : any ;
26+ let twoStepsProjectJSON : any ;
2327
2428describe ( '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()
@@ -1037,3 +1044,56 @@ function addCurrentUserToAuthors_CM_shouldAddUserInfo() {
10371044 expect ( authors [ 0 ] . id ) . toEqual ( 1 ) ;
10381045 } ) ;
10391046}
1047+
1048+ function getAllPaths ( ) {
1049+ describe ( 'getAllPaths()' , ( ) => {
1050+ it ( 'should get all paths in a unit with no branches' , ( ) => {
1051+ service . setProject ( twoStepsProjectJSON ) ;
1052+ const allPaths = service . getAllPaths ( [ ] , service . getStartNodeId ( ) , true ) ;
1053+ expect ( allPaths . length ) . toEqual ( 1 ) ;
1054+ expect ( allPaths [ 0 ] ) . toEqual ( [ 'group1' , 'node1' , 'node2' ] ) ;
1055+ } ) ;
1056+ it ( 'should get all paths in a unit with a branch with two paths' , ( ) => {
1057+ service . setProject ( oneBranchTwoPathsProjectJSON ) ;
1058+ const allPaths = service . getAllPaths ( [ ] , service . getStartNodeId ( ) , true ) ;
1059+ expect ( allPaths . length ) . toEqual ( 2 ) ;
1060+ expect ( allPaths [ 0 ] ) . toEqual ( [ 'group1' , 'node1' , 'node2' , 'node3' , 'node4' , 'node8' ] ) ;
1061+ expect ( allPaths [ 1 ] ) . toEqual ( [ 'group1' , 'node1' , 'node2' , 'node5' , 'node6' , 'node7' , 'node8' ] ) ;
1062+ } ) ;
1063+ it ( 'should get all paths in a unit starting with a node in a branch path' , ( ) => {
1064+ service . setProject ( oneBranchTwoPathsProjectJSON ) ;
1065+ const allPaths1 = service . getAllPaths ( [ 'group1' , 'node1' , 'node2' ] , 'node3' , true ) ;
1066+ expect ( allPaths1 . length ) . toEqual ( 1 ) ;
1067+ expect ( allPaths1 [ 0 ] ) . toEqual ( [ 'node3' , 'node4' , 'node8' ] ) ;
1068+ const allPaths2 = service . getAllPaths ( [ 'group1' , 'node1' , 'node2' ] , 'node5' , true ) ;
1069+ expect ( allPaths2 . length ) . toEqual ( 1 ) ;
1070+ expect ( allPaths2 [ 0 ] ) . toEqual ( [ 'node5' , 'node6' , 'node7' , 'node8' ] ) ;
1071+ } ) ;
1072+ } ) ;
1073+ }
1074+
1075+ function consolidatePaths ( ) {
1076+ describe ( 'consolidatePaths()' , ( ) => {
1077+ it ( 'should consolidate all the paths into a linear list of node ids' , ( ) => {
1078+ service . setProject ( oneBranchTwoPathsProjectJSON ) ;
1079+ const allPaths = service . getAllPaths ( [ ] , service . getStartNodeId ( ) , true ) ;
1080+ const consolidatedPaths = service . consolidatePaths ( allPaths ) ;
1081+ expect ( consolidatedPaths ) . toEqual ( [ 'group1' , 'node1' , 'node2' , 'node3' , 'node4' , 'node5' ,
1082+ 'node6' , 'node7' , 'node8' ] ) ;
1083+ } ) ;
1084+ } ) ;
1085+ }
1086+
1087+ function getParentGroup ( ) {
1088+ describe ( 'getParentGroup()' , ( ) => {
1089+ beforeEach ( ( ) => {
1090+ service . setProject ( twoStepsProjectJSON ) ;
1091+ } ) ;
1092+ it ( 'should get the parent group of an active node' , ( ) => {
1093+ expect ( service . getParentGroup ( 'node1' ) . id ) . toEqual ( 'group1' ) ;
1094+ } ) ;
1095+ it ( 'should get the parent group of an inactive node' , ( ) => {
1096+ expect ( service . getParentGroup ( 'node3' ) . id ) . toEqual ( 'group2' ) ;
1097+ } ) ;
1098+ } ) ;
1099+ }
0 commit comments