Skip to content

Commit 0f20613

Browse files
Merge pull request #2900 from WISE-Community/issue-2897-refactor-milestone-code
Refactor MilestoneService and spec files
2 parents d938831 + f592801 commit 0f20613

4 files changed

Lines changed: 130 additions & 287 deletions

File tree

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

Lines changed: 26 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ const aggregateAutoScoresSample = {
4848

4949
const possibleScoresKi = [1, 2, 3, 4, 5];
5050

51+
const sampleAggregateData = {
52+
counts: createScoreCounts([10, 20, 30, 40, 50])
53+
};
54+
5155
const reportSettingsCustomScoreValuesSample = {
5256
customScoreValues: {
5357
ki: [1, 2, 3, 4]
@@ -964,205 +968,39 @@ function isPercentOfScoresNotEqualTo() {
964968

965969
function getComparatorSum() {
966970
describe('getComparatorSum()', () => {
967-
getGreaterThanSum();
968-
getGreaterThanOrEqualToSum();
969-
getLessThanSum();
970-
getEqualToSum();
971-
getNotEqualToSum();
972-
});
973-
}
974-
975-
function getGreaterThanSum() {
976-
const aggregateData = {
977-
counts: createScoreCounts([10, 20, 30, 40, 50])
978-
};
979-
it('should get greater than sum with score 1', () => {
980-
const satisfyCriterion = { value: 1 };
981-
expect(
982-
service.getComparatorSum(
983-
satisfyCriterion,
984-
aggregateData,
985-
possibleScoresKi,
986-
utilService.greaterThan
987-
)
988-
).toEqual(140);
989-
});
990-
it('should get greater than sum with score 2', () => {
991-
const satisfyCriterion = { value: 2 };
992-
expect(
993-
service.getComparatorSum(
994-
satisfyCriterion,
995-
aggregateData,
996-
possibleScoresKi,
997-
utilService.greaterThan
998-
)
999-
).toEqual(120);
1000-
});
1001-
it('should get greater than sum with score 3', () => {
1002-
const satisfyCriterion = { value: 3 };
1003-
expect(
1004-
service.getComparatorSum(
1005-
satisfyCriterion,
1006-
aggregateData,
1007-
possibleScoresKi,
1008-
utilService.greaterThan
1009-
)
1010-
).toEqual(90);
1011-
});
1012-
it('should get greater than sum with score 4', () => {
1013-
const satisfyCriterion = { value: 4 };
1014-
expect(
1015-
service.getComparatorSum(
1016-
satisfyCriterion,
1017-
aggregateData,
1018-
possibleScoresKi,
1019-
utilService.greaterThan
1020-
)
1021-
).toEqual(50);
971+
getComparatorSum_greaterThan0_ReturnSumAll();
972+
getComparatorSum_greaterThan3_ReturnSumPartial();
973+
getComparatorSum_greaterThan5_Return0();
1022974
});
1023975
}
1024976

1025-
function getGreaterThanOrEqualToSum() {
1026-
const aggregateData = {
1027-
counts: createScoreCounts([10, 20, 30, 40, 50])
1028-
};
1029-
it('should get greater than or equal to sum with score 1', () => {
1030-
const satisfyCriterion = { value: 1 };
1031-
expect(
1032-
service.getComparatorSum(
1033-
satisfyCriterion,
1034-
aggregateData,
1035-
possibleScoresKi,
1036-
utilService.greaterThanEqualTo
1037-
)
1038-
).toEqual(150);
1039-
});
1040-
it('should get greater than or equal to sum with score 2', () => {
1041-
const satisfyCriterion = { value: 2 };
1042-
expect(
1043-
service.getComparatorSum(
1044-
satisfyCriterion,
1045-
aggregateData,
1046-
possibleScoresKi,
1047-
utilService.greaterThanEqualTo
1048-
)
1049-
).toEqual(140);
1050-
});
1051-
it('should get greater than or equal to sum with score 3', () => {
1052-
const satisfyCriterion = { value: 3 };
1053-
expect(
1054-
service.getComparatorSum(
1055-
satisfyCriterion,
1056-
aggregateData,
1057-
possibleScoresKi,
1058-
utilService.greaterThanEqualTo
1059-
)
1060-
).toEqual(120);
1061-
});
1062-
it('should get greater than or equal to sum with score 4', () => {
1063-
const satisfyCriterion = { value: 4 };
1064-
expect(
1065-
service.getComparatorSum(
1066-
satisfyCriterion,
1067-
aggregateData,
1068-
possibleScoresKi,
1069-
utilService.greaterThanEqualTo
1070-
)
1071-
).toEqual(90);
1072-
});
1073-
it('should get greater than or equal to sum with score 5', () => {
1074-
const satisfyCriterion = { value: 5 };
1075-
expect(
1076-
service.getComparatorSum(
1077-
satisfyCriterion,
1078-
aggregateData,
1079-
possibleScoresKi,
1080-
utilService.greaterThanEqualTo
1081-
)
1082-
).toEqual(50);
1083-
});
977+
function expectComparatorResult(satisfyCriterionValue: number, expectedResult: number) {
978+
const satisfyCriterion = { value: satisfyCriterionValue };
979+
expect(
980+
service.getComparatorSum(
981+
satisfyCriterion,
982+
sampleAggregateData,
983+
possibleScoresKi,
984+
utilService.greaterThan
985+
)
986+
).toEqual(expectedResult);
1084987
}
1085988

1086-
function getLessThanSum() {
1087-
const aggregateData = {
1088-
counts: createScoreCounts([10, 20, 30, 40, 50])
1089-
};
1090-
it('should get less than sum with score 2', () => {
1091-
const satisfyCriterion = { value: 2 };
1092-
expect(
1093-
service.getComparatorSum(
1094-
satisfyCriterion,
1095-
aggregateData,
1096-
possibleScoresKi,
1097-
utilService.lessThan
1098-
)
1099-
).toEqual(10);
1100-
});
1101-
it('should get less than sum with score 3', () => {
1102-
const satisfyCriterion = { value: 3 };
1103-
expect(
1104-
service.getComparatorSum(
1105-
satisfyCriterion,
1106-
aggregateData,
1107-
possibleScoresKi,
1108-
utilService.lessThan
1109-
)
1110-
).toEqual(30);
1111-
});
1112-
it('should get less than sum with score 4', () => {
1113-
const satisfyCriterion = { value: 4 };
1114-
expect(
1115-
service.getComparatorSum(
1116-
satisfyCriterion,
1117-
aggregateData,
1118-
possibleScoresKi,
1119-
utilService.lessThan
1120-
)
1121-
).toEqual(60);
1122-
});
1123-
it('should get less than sum with score 5', () => {
1124-
const satisfyCriterion = { value: 5 };
1125-
expect(
1126-
service.getComparatorSum(
1127-
satisfyCriterion,
1128-
aggregateData,
1129-
possibleScoresKi,
1130-
utilService.lessThan
1131-
)
1132-
).toEqual(100);
989+
function getComparatorSum_greaterThan0_ReturnSumAll() {
990+
it('should get greater than sum with score 0', () => {
991+
expectComparatorResult(0, 150);
1133992
});
1134993
}
1135994

1136-
function getEqualToSum() {
1137-
it('should return the sum of scores equal to value', () => {
1138-
const satisfyCriterion = { value: 3 };
1139-
const aggregateData = {
1140-
counts: createScoreCounts([10, 20, 30, 40, 50])
1141-
};
1142-
expect(
1143-
service.getComparatorSum(
1144-
satisfyCriterion,
1145-
aggregateData,
1146-
possibleScoresKi,
1147-
utilService.equalTo
1148-
)
1149-
).toEqual(30);
995+
function getComparatorSum_greaterThan3_ReturnSumPartial() {
996+
it('should get greater than sum with score 3', () => {
997+
expectComparatorResult(3, 90);
1150998
});
1151999
}
11521000

1153-
function getNotEqualToSum() {
1154-
const aggregateData = {
1155-
counts: { 1: 2, 2: 0, 3: 1, 4: 0, 5: 0 },
1156-
scoreCount: 3
1157-
};
1158-
it('should return the sum of scores not equal to value', () => {
1159-
const result = service.getComparatorSum(
1160-
satisfyCriterionSample,
1161-
aggregateData,
1162-
possibleScoresKi,
1163-
utilService.notEqualTo
1164-
);
1165-
expect(result).toBe(2);
1001+
function getComparatorSum_greaterThan5_Return0() {
1002+
it('should get greater than sum with score 5', () => {
1003+
expectComparatorResult(5, 0);
11661004
});
11671005
}
11681006

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<md-dialog class="dialog--wider" aria-label="{{ 'MILESTONE_DETAILS_TITLE' | translate : { name: $ctrl.milestone.name } }}">
2+
<md-toolbar>
3+
<div class="md-toolbar-tools">
4+
<h2>{{ 'MILESTONE_DETAILS_TITLE' | translate : { name: $ctrl.milestone.name } }}</h2>
5+
</div>
6+
</md-toolbar>
7+
<md-dialog-content class="gray-lighter-bg md-dialog-content">
8+
<milestone-details milestone="$ctrl.milestone"
9+
hide-student-work="$ctrl.hideStudentWork"
10+
on-show-workgroup="$ctrl.onShowWorkgroup(value)"
11+
on-visit-node-grading="$ctrl.onVisitNodeGrading()"></milestone-details>
12+
</md-dialog-content>
13+
<md-dialog-actions layout="row" layout-align="start center">
14+
<span flex></span>
15+
<md-button class="md-primary"
16+
ng-click="$ctrl.close()"
17+
aria-label="{{ ::'CLOSE' | translate }}">
18+
{{ ::'CLOSE' | translate }}
19+
</md-button>
20+
</md-dialog-actions>
21+
</md-dialog>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
export class MilestoneDetailsDialog {
2+
title: string;
3+
4+
static $inject = [
5+
'$state',
6+
'$mdDialog',
7+
'$event',
8+
'milestone',
9+
'hideStudentWork',
10+
'TeacherDataService'
11+
];
12+
13+
constructor(
14+
private $state,
15+
private $mdDialog,
16+
private $event,
17+
private milestone,
18+
private hideStudentWork,
19+
private TeacherDataService
20+
) {}
21+
22+
$onInit() {
23+
this.saveMilestoneOpenedEvent();
24+
}
25+
26+
close() {
27+
this.saveMilestoneClosedEvent();
28+
this.$mdDialog.hide();
29+
}
30+
31+
edit() {
32+
this.$mdDialog.hide({
33+
milestone: this.milestone,
34+
action: 'edit',
35+
$event: this.$event
36+
});
37+
}
38+
39+
onShowWorkgroup(workgroup: any) {
40+
this.saveMilestoneClosedEvent();
41+
this.$mdDialog.hide();
42+
this.TeacherDataService.setCurrentWorkgroup(workgroup);
43+
this.$state.go('root.nodeProgress');
44+
}
45+
46+
onVisitNodeGrading() {
47+
this.$mdDialog.hide();
48+
}
49+
50+
saveMilestoneOpenedEvent() {
51+
this.saveMilestoneEvent('MilestoneOpened');
52+
}
53+
54+
saveMilestoneClosedEvent() {
55+
this.saveMilestoneEvent('MilestoneClosed');
56+
}
57+
58+
saveMilestoneEvent(event: any) {
59+
const context = 'ClassroomMonitor',
60+
nodeId = null,
61+
componentId = null,
62+
componentType = null,
63+
category = 'Navigation',
64+
data = { milestoneId: this.milestone.id },
65+
projectId = null;
66+
this.TeacherDataService.saveEvent(
67+
context,
68+
nodeId,
69+
componentId,
70+
componentType,
71+
category,
72+
event,
73+
data,
74+
projectId
75+
);
76+
}
77+
}

0 commit comments

Comments
 (0)