Skip to content

Commit b11c31b

Browse files
authored
Merge pull request #2924 from WISE-Community/issue-2896-combine-milestone-reports
Combine milestone reports
2 parents 7de2c18 + 5bd558a commit b11c31b

7 files changed

Lines changed: 376 additions & 144 deletions

File tree

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

Lines changed: 76 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,41 @@ const satisfyCriterionSample = {
3535
value: 3
3636
};
3737

38-
const aggregateAutoScoresSample = {
39-
xfns1g7pga: {
40-
ki: {
41-
counts: { 1: 2, 2: 0, 3: 1, 4: 0, 5: 0 },
42-
scoreSum: 5,
43-
scoreCount: 3,
44-
average: 1.67
38+
const aggregateAutoScoresSample = [
39+
{
40+
nodeId: 'node1',
41+
componentId: 'xfns1g7pga',
42+
stepTitle: 'Step 1.1: Hello',
43+
aggregateAutoScore: {
44+
ki: {
45+
counts: { 1: 2, 2: 0, 3: 1, 4: 0, 5: 0 },
46+
scoreSum: 5,
47+
scoreCount: 3,
48+
average: 1.67
49+
}
4550
}
4651
}
47-
};
52+
];
4853

4954
const possibleScoresKi = [1, 2, 3, 4, 5];
5055

5156
const sampleAggregateData = {
5257
counts: createScoreCounts([10, 20, 30, 40, 50])
5358
};
5459

55-
const aggregateAutoScores50 = {
56-
component1: {
57-
ki: {
58-
counts: createScoreCounts([10, 10, 10, 10, 10]),
59-
scoreCount: 50
60+
const aggregateAutoScores50 = [
61+
{
62+
nodeId: 'node1',
63+
componentId: 'component1',
64+
stepTitle: 'Step 1.2: World',
65+
aggregateAutoScore: {
66+
ki: {
67+
counts: createScoreCounts([10, 10, 10, 10, 10]),
68+
scoreCount: 50
69+
}
6070
}
6171
}
62-
};
72+
];
6373

6474
const reportSettingsCustomScoreValuesSample = {
6575
customScoreValues: {
@@ -392,6 +402,12 @@ function insertMilestoneReport() {
392402
const content = 'template1Content';
393403
const milestone: any = {
394404
report: {
405+
locations: [
406+
{
407+
nodeId: 'node1',
408+
componentId: 'component1'
409+
}
410+
],
395411
templates: [
396412
{
397413
id: 'template1',
@@ -509,6 +525,12 @@ function generateReport() {
509525
const content = 'template1Content';
510526
const projectAchievement = {
511527
report: {
528+
locations: [
529+
{
530+
nodeId: 'node1',
531+
componentId: 'component1'
532+
}
533+
],
512534
templates: [
513535
{
514536
id: 'template1',
@@ -550,7 +572,7 @@ function chooseTemplate() {
550572
id: 'template-2'
551573
};
552574
const templates = [template1, template2];
553-
const aggregateAutoScores = {};
575+
const aggregateAutoScores = [];
554576
spyOn(service, 'isTemplateMatch').and.callFake((template, aggregateAutoScores) => {
555577
if (template.id === 'template-1') {
556578
return false;
@@ -565,7 +587,7 @@ function chooseTemplate() {
565587

566588
function isTemplateMatch() {
567589
describe('isTemplateMatch()', () => {
568-
const aggregateAutoScores = {};
590+
const aggregateAutoScores = [];
569591
const satisfyCriteria = [
570592
{
571593
id: 'satisfy-criteria-1'
@@ -847,14 +869,19 @@ function isPercentOfScoresEqualTo() {
847869
).toEqual(false);
848870
});
849871
it('should check is percent of scores equal to true', () => {
850-
const aggregateAutoScores = {
851-
component1: {
852-
ki: {
853-
counts: createScoreCounts([10, 0, 10, 0, 0]),
854-
scoreCount: 20
872+
const aggregateAutoScores = [
873+
{
874+
nodeId: 'node1',
875+
componentId: 'component1',
876+
stepTitle: 'Step 1.1: Hello',
877+
aggregateAutoScore: {
878+
ki: {
879+
counts: createScoreCounts([10, 0, 10, 0, 0]),
880+
scoreCount: 20
881+
}
855882
}
856883
}
857-
};
884+
];
858885
expect(
859886
service.isPercentOfScoresSatisfiesComparator(
860887
satisfyCriterion,
@@ -877,7 +904,7 @@ function isPercentOfScoresNotEqualTo() {
877904
});
878905
it('should return true when percent of scores equal to value meet threshold', () => {
879906
const aggregateAutoScores = angular.copy(aggregateAutoScoresSample);
880-
aggregateAutoScores.xfns1g7pga.ki.counts = { 1: 1, 2: 0, 3: 2, 4: 0, 5: 0 };
907+
aggregateAutoScores[0].aggregateAutoScore.ki.counts = { 1: 1, 2: 0, 3: 2, 4: 0, 5: 0 };
881908
expect(
882909
service.isPercentOfScoresSatisfiesComparator(
883910
satisfyCriterionSample,
@@ -954,11 +981,15 @@ function getPossibleScores() {
954981
function isPercentThresholdSatisfied() {
955982
describe('isPercentThresholdSatisfied()', () => {
956983
it('should return true when percent threshold is satisfied', () => {
957-
const aggregateAutoScores = {
958-
xfns1g7pga: {
959-
ki: { counts: { 1: 1, 2: 0, 3: 2, 4: 0, 5: 0 }, scoreCount: 3 }
984+
const aggregateAutoScores = [
985+
{
986+
nodeId: 'node1',
987+
componentId: 'xfns1g7pga',
988+
aggregateAutoScore: {
989+
ki: { counts: { 1: 1, 2: 0, 3: 2, 4: 0, 5: 0 }, scoreCount: 3 }
990+
}
960991
}
961-
};
992+
];
962993
const aggregateData = service.getAggregateData(satisfyCriterionSample, aggregateAutoScores);
963994
const sum = service.getComparatorSum(
964995
satisfyCriterionSample,
@@ -1062,7 +1093,7 @@ function addDataToAggregate() {
10621093
]
10631094
}
10641095
};
1065-
const aggregateAutoScore = angular.copy(aggregateAutoScoresSample).xfns1g7pga;
1096+
const aggregateAutoScore = angular.copy(aggregateAutoScoresSample)[0].aggregateAutoScore;
10661097
const result = service.addDataToAggregate(
10671098
aggregateAutoScore,
10681099
annotation,
@@ -1144,40 +1175,27 @@ function processMilestoneGraphsAndData() {
11441175
describe('processMilestoneGraphsAndData()', () => {
11451176
it('should process milestone report graph', () => {
11461177
let content = '<milestone-report-graph id="ki"></milestone-report-graph>';
1147-
const aggregateAutoScores = {
1148-
component1: {
1149-
ki: {
1150-
scoreSum: 4,
1151-
scoreCount: 2,
1152-
average: 2,
1153-
counts: createScoreCounts([1, 0, 1, 0, 0])
1154-
}
1155-
}
1156-
};
1157-
content = service.processMilestoneGraphsAndData(content, aggregateAutoScores);
1158-
expect(
1159-
content.includes(
1160-
`data="{'scoreSum':4,'scoreCount':2,'average':2,'counts':{'1':1,'2':0,'3':1,'4':0,'5':0}}"`
1161-
)
1162-
).toEqual(true);
1163-
});
1164-
it('should process milestone report data', () => {
1165-
let content = '<milestone-report-data score-id="ki"></milestone-report-data>';
1166-
const aggregateAutoScores = {
1167-
component1: {
1168-
ki: {
1169-
scoreSum: 4,
1170-
scoreCount: 2,
1171-
average: 2,
1172-
counts: createScoreCounts([1, 0, 1, 0, 0])
1178+
const componentAggregateAutoScores = [
1179+
{
1180+
nodeId: 'node1',
1181+
componentId: 'component1',
1182+
aggregateAutoScore: {
1183+
ki: {
1184+
scoreSum: 4,
1185+
scoreCount: 2,
1186+
average: 2,
1187+
counts: createScoreCounts([1, 0, 1, 0, 0])
1188+
}
11731189
}
11741190
}
1175-
};
1176-
content = service.processMilestoneGraphsAndData(content, aggregateAutoScores);
1191+
];
1192+
content = service.processMilestoneGraphsAndData(content, componentAggregateAutoScores);
11771193
expect(
11781194
content.includes(
1179-
`data="{'scoreSum':4,'scoreCount':2,'average':2,` +
1180-
`'counts':{'1':1,'2':0,'3':1,'4':0,'5':0}}"`
1195+
`data="[{` +
1196+
`'scoreSum':4,'scoreCount':2,'average':2,'counts':{'1':1,'2':0,'3':1,'4':0,'5':0},` +
1197+
`'nodeId':'node1','componentId':'component1'` +
1198+
`}]"`
11811199
)
11821200
).toEqual(true);
11831201
});

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('UtilService', () => {
2020
calculateMeanTests();
2121
getIntersectOfArraysTests();
2222
isValidJSONStringTests();
23+
trimToLength();
2324
});
2425

2526
function generateKeyTests() {
@@ -210,3 +211,15 @@ function isValidJSONStringTests() {
210211
});
211212
});
212213
}
214+
215+
function trimToLength() {
216+
describe('trimToLength()', () => {
217+
it('should keep strings intact if its length is equal to or less than max length', () => {
218+
expect(service.trimToLength('123456789', 9)).toEqual('123456789');
219+
expect(service.trimToLength('123456789', 10)).toEqual('123456789');
220+
});
221+
it('should trim length and add ellipses if length is longer than max length', () => {
222+
expect(service.trimToLength('123456789', 7)).toEqual('1234...');
223+
});
224+
});
225+
}
Lines changed: 103 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,112 @@
11
import { MilestoneReportDataComponent } from './milestone-report-data.component';
22

3+
let comp: any = null;
4+
const nodeId1: string = 'node1';
5+
const nodeId2: string = 'node2';
6+
const componentId1: string = 'component1';
7+
const componentId2: string = 'component2';
8+
const counts1: any = { 1: 0, 2: 0, 3: 1, 4: 1, 5: 0 };
9+
const counts2: any = { 1: 0, 2: 0, 3: 0, 4: 2, 5: 0 };
10+
const average1: number = 3.5;
11+
const average2: number = 4;
12+
const scoreCount1: number = 2;
13+
const scoreCount2: number = 2;
14+
const scoreSum1: number = 7;
15+
const scoreSum2: number = 8;
16+
const stepTitle1: string = '1.1: Milestone Step 1';
17+
const stepTitle2: string = '1.2: Milestone Step 2';
18+
const componentData1: any = createComponentData(
19+
nodeId1,
20+
componentId1,
21+
counts1,
22+
average1,
23+
scoreCount1,
24+
scoreSum1,
25+
stepTitle1
26+
);
27+
const componentData2: any = createComponentData(
28+
nodeId2,
29+
componentId2,
30+
counts2,
31+
average2,
32+
scoreCount2,
33+
scoreSum2,
34+
stepTitle2
35+
);
36+
337
describe('MilestoneReportDataComponent', () => {
4-
it('#getPercent() should return percentage', () => {
5-
const comp = new MilestoneReportDataComponent();
6-
comp.data = { scoreCount: 5 };
38+
beforeEach(() => {
39+
comp = new MilestoneReportDataComponent();
40+
comp.data = [componentData1, componentData2];
41+
});
42+
43+
getPercent();
44+
getCount();
45+
getAverage();
46+
getScoreValuesCount();
47+
getComponentData();
48+
});
49+
50+
function getPercent(): void {
51+
it('getPercent() should return percentage', () => {
752
expect(comp.getPercent()).toEqual('100%');
853
});
54+
}
955

10-
it('#getScoreValuesCount() should count for current score value', () => {
11-
const comp = new MilestoneReportDataComponent();
56+
function getCount(): void {
57+
it('getCount() should get the count when scoreValues is not specified', () => {
58+
expect(comp.getCount()).toEqual(2);
59+
});
60+
61+
it('getCount() should get the count when scoreValues is specified', () => {
1262
comp.scoreValues = [5];
13-
comp.data = {
14-
average: 4.3333333333333,
15-
counts: { 1: 0, 2: 0, 3: 1, 4: 0, 5: 2 },
16-
scoreCount: 3,
17-
scoreSum: 13
18-
};
63+
expect(comp.getCount()).toEqual(0);
64+
});
65+
}
66+
67+
function getAverage(): void {
68+
it('getAverage() should get the average', () => {
69+
expect(comp.getAverage()).toEqual(4);
70+
});
71+
}
72+
73+
function getScoreValuesCount(): void {
74+
it('getScoreValuesCount() should get the count for the specified score value', () => {
75+
comp.scoreValues = [4];
1976
expect(comp.getScoreValuesCount()).toEqual(2);
2077
});
21-
});
78+
}
79+
80+
function getComponentData(): void {
81+
it(`getComponentData() should get the last component data if nodeId and componentId are not
82+
specified`, () => {
83+
expect(comp.getComponentData()).toEqual(componentData2);
84+
});
85+
86+
it(`getComponentData() should get the component data if nodeId and componentId are
87+
specified`, () => {
88+
comp.nodeId = nodeId1;
89+
comp.componentId = componentId1;
90+
expect(comp.getComponentData()).toEqual(componentData1);
91+
});
92+
}
93+
94+
function createComponentData(
95+
nodeId: string,
96+
componentId: string,
97+
counts: any,
98+
average: number,
99+
scoreCount: number,
100+
scoreSum: number,
101+
stepTitle: string
102+
): any {
103+
return {
104+
nodeId: nodeId,
105+
componentId: componentId,
106+
average: average,
107+
counts: counts,
108+
scoreCount: scoreCount,
109+
scoreSum: scoreSum,
110+
stepTitle: stepTitle
111+
};
112+
}

0 commit comments

Comments
 (0)