Skip to content

Commit cb25b76

Browse files
Removed outer null check in getParentGroupId() and specified return types. Cleaned up test. #2396
1 parent 7a381fb commit cb25b76

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,15 +1109,14 @@ function consolidatePaths() {
11091109

11101110
function getParentGroup() {
11111111
describe('getParentGroup()', () => {
1112+
beforeEach(() => {
1113+
service.setProject(twoStepsProjectJSON);
1114+
});
11121115
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+
expect(service.getParentGroup('node1').id).toEqual('group1');
11161117
});
11171118
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');
1119+
expect(service.getParentGroup('node3').id).toEqual('group2');
11211120
});
11221121
});
11231122
}

src/main/webapp/wise5/services/projectService.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ export class ProjectService {
722722
return nodeIcon;
723723
}
724724

725-
getParentGroup(nodeId = '') {
725+
getParentGroup(nodeId = ''): any {
726726
const node = this.getNodeById(nodeId);
727727
if (node != null) {
728728
for (const groupNode of this.getGroupNodes()) {
@@ -739,12 +739,10 @@ export class ProjectService {
739739
return null;
740740
}
741741

742-
getParentGroupId(nodeId) {
743-
if (nodeId != null) {
744-
const parentGroup = this.getParentGroup(nodeId);
745-
if (parentGroup != null) {
746-
return parentGroup.id;
747-
}
742+
getParentGroupId(nodeId = ''): string {
743+
const parentGroup = this.getParentGroup(nodeId);
744+
if (parentGroup != null) {
745+
return parentGroup.id;
748746
}
749747
return null;
750748
}

0 commit comments

Comments
 (0)