Skip to content

Commit

Permalink
Merge pull request #2924 from WISE-Community/issue-2896-combine-miles…
Browse files Browse the repository at this point in the history
…tone-reports

Combine milestone reports
  • Loading branch information
breity authored Feb 11, 2021
2 parents 7de2c18 + 5bd558a commit b11c31b
Show file tree
Hide file tree
Showing 7 changed files with 376 additions and 144 deletions.
134 changes: 76 additions & 58 deletions src/main/webapp/site/src/app/services/milestoneService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,41 @@ const satisfyCriterionSample = {
value: 3
};

const aggregateAutoScoresSample = {
xfns1g7pga: {
ki: {
counts: { 1: 2, 2: 0, 3: 1, 4: 0, 5: 0 },
scoreSum: 5,
scoreCount: 3,
average: 1.67
const aggregateAutoScoresSample = [
{
nodeId: 'node1',
componentId: 'xfns1g7pga',
stepTitle: 'Step 1.1: Hello',
aggregateAutoScore: {
ki: {
counts: { 1: 2, 2: 0, 3: 1, 4: 0, 5: 0 },
scoreSum: 5,
scoreCount: 3,
average: 1.67
}
}
}
};
];

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

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

const aggregateAutoScores50 = {
component1: {
ki: {
counts: createScoreCounts([10, 10, 10, 10, 10]),
scoreCount: 50
const aggregateAutoScores50 = [
{
nodeId: 'node1',
componentId: 'component1',
stepTitle: 'Step 1.2: World',
aggregateAutoScore: {
ki: {
counts: createScoreCounts([10, 10, 10, 10, 10]),
scoreCount: 50
}
}
}
};
];

const reportSettingsCustomScoreValuesSample = {
customScoreValues: {
Expand Down Expand Up @@ -392,6 +402,12 @@ function insertMilestoneReport() {
const content = 'template1Content';
const milestone: any = {
report: {
locations: [
{
nodeId: 'node1',
componentId: 'component1'
}
],
templates: [
{
id: 'template1',
Expand Down Expand Up @@ -509,6 +525,12 @@ function generateReport() {
const content = 'template1Content';
const projectAchievement = {
report: {
locations: [
{
nodeId: 'node1',
componentId: 'component1'
}
],
templates: [
{
id: 'template1',
Expand Down Expand Up @@ -550,7 +572,7 @@ function chooseTemplate() {
id: 'template-2'
};
const templates = [template1, template2];
const aggregateAutoScores = {};
const aggregateAutoScores = [];
spyOn(service, 'isTemplateMatch').and.callFake((template, aggregateAutoScores) => {
if (template.id === 'template-1') {
return false;
Expand All @@ -565,7 +587,7 @@ function chooseTemplate() {

function isTemplateMatch() {
describe('isTemplateMatch()', () => {
const aggregateAutoScores = {};
const aggregateAutoScores = [];
const satisfyCriteria = [
{
id: 'satisfy-criteria-1'
Expand Down Expand Up @@ -847,14 +869,19 @@ function isPercentOfScoresEqualTo() {
).toEqual(false);
});
it('should check is percent of scores equal to true', () => {
const aggregateAutoScores = {
component1: {
ki: {
counts: createScoreCounts([10, 0, 10, 0, 0]),
scoreCount: 20
const aggregateAutoScores = [
{
nodeId: 'node1',
componentId: 'component1',
stepTitle: 'Step 1.1: Hello',
aggregateAutoScore: {
ki: {
counts: createScoreCounts([10, 0, 10, 0, 0]),
scoreCount: 20
}
}
}
};
];
expect(
service.isPercentOfScoresSatisfiesComparator(
satisfyCriterion,
Expand All @@ -877,7 +904,7 @@ function isPercentOfScoresNotEqualTo() {
});
it('should return true when percent of scores equal to value meet threshold', () => {
const aggregateAutoScores = angular.copy(aggregateAutoScoresSample);
aggregateAutoScores.xfns1g7pga.ki.counts = { 1: 1, 2: 0, 3: 2, 4: 0, 5: 0 };
aggregateAutoScores[0].aggregateAutoScore.ki.counts = { 1: 1, 2: 0, 3: 2, 4: 0, 5: 0 };
expect(
service.isPercentOfScoresSatisfiesComparator(
satisfyCriterionSample,
Expand Down Expand Up @@ -954,11 +981,15 @@ function getPossibleScores() {
function isPercentThresholdSatisfied() {
describe('isPercentThresholdSatisfied()', () => {
it('should return true when percent threshold is satisfied', () => {
const aggregateAutoScores = {
xfns1g7pga: {
ki: { counts: { 1: 1, 2: 0, 3: 2, 4: 0, 5: 0 }, scoreCount: 3 }
const aggregateAutoScores = [
{
nodeId: 'node1',
componentId: 'xfns1g7pga',
aggregateAutoScore: {
ki: { counts: { 1: 1, 2: 0, 3: 2, 4: 0, 5: 0 }, scoreCount: 3 }
}
}
};
];
const aggregateData = service.getAggregateData(satisfyCriterionSample, aggregateAutoScores);
const sum = service.getComparatorSum(
satisfyCriterionSample,
Expand Down Expand Up @@ -1062,7 +1093,7 @@ function addDataToAggregate() {
]
}
};
const aggregateAutoScore = angular.copy(aggregateAutoScoresSample).xfns1g7pga;
const aggregateAutoScore = angular.copy(aggregateAutoScoresSample)[0].aggregateAutoScore;
const result = service.addDataToAggregate(
aggregateAutoScore,
annotation,
Expand Down Expand Up @@ -1144,40 +1175,27 @@ function processMilestoneGraphsAndData() {
describe('processMilestoneGraphsAndData()', () => {
it('should process milestone report graph', () => {
let content = '<milestone-report-graph id="ki"></milestone-report-graph>';
const aggregateAutoScores = {
component1: {
ki: {
scoreSum: 4,
scoreCount: 2,
average: 2,
counts: createScoreCounts([1, 0, 1, 0, 0])
}
}
};
content = service.processMilestoneGraphsAndData(content, aggregateAutoScores);
expect(
content.includes(
`data="{'scoreSum':4,'scoreCount':2,'average':2,'counts':{'1':1,'2':0,'3':1,'4':0,'5':0}}"`
)
).toEqual(true);
});
it('should process milestone report data', () => {
let content = '<milestone-report-data score-id="ki"></milestone-report-data>';
const aggregateAutoScores = {
component1: {
ki: {
scoreSum: 4,
scoreCount: 2,
average: 2,
counts: createScoreCounts([1, 0, 1, 0, 0])
const componentAggregateAutoScores = [
{
nodeId: 'node1',
componentId: 'component1',
aggregateAutoScore: {
ki: {
scoreSum: 4,
scoreCount: 2,
average: 2,
counts: createScoreCounts([1, 0, 1, 0, 0])
}
}
}
};
content = service.processMilestoneGraphsAndData(content, aggregateAutoScores);
];
content = service.processMilestoneGraphsAndData(content, componentAggregateAutoScores);
expect(
content.includes(
`data="{'scoreSum':4,'scoreCount':2,'average':2,` +
`'counts':{'1':1,'2':0,'3':1,'4':0,'5':0}}"`
`data="[{` +
`'scoreSum':4,'scoreCount':2,'average':2,'counts':{'1':1,'2':0,'3':1,'4':0,'5':0},` +
`'nodeId':'node1','componentId':'component1'` +
`}]"`
)
).toEqual(true);
});
Expand Down
13 changes: 13 additions & 0 deletions src/main/webapp/site/src/app/services/utilService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('UtilService', () => {
calculateMeanTests();
getIntersectOfArraysTests();
isValidJSONStringTests();
trimToLength();
});

function generateKeyTests() {
Expand Down Expand Up @@ -210,3 +211,15 @@ function isValidJSONStringTests() {
});
});
}

function trimToLength() {
describe('trimToLength()', () => {
it('should keep strings intact if its length is equal to or less than max length', () => {
expect(service.trimToLength('123456789', 9)).toEqual('123456789');
expect(service.trimToLength('123456789', 10)).toEqual('123456789');
});
it('should trim length and add ellipses if length is longer than max length', () => {
expect(service.trimToLength('123456789', 7)).toEqual('1234...');
});
});
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,112 @@
import { MilestoneReportDataComponent } from './milestone-report-data.component';

let comp: any = null;
const nodeId1: string = 'node1';
const nodeId2: string = 'node2';
const componentId1: string = 'component1';
const componentId2: string = 'component2';
const counts1: any = { 1: 0, 2: 0, 3: 1, 4: 1, 5: 0 };
const counts2: any = { 1: 0, 2: 0, 3: 0, 4: 2, 5: 0 };
const average1: number = 3.5;
const average2: number = 4;
const scoreCount1: number = 2;
const scoreCount2: number = 2;
const scoreSum1: number = 7;
const scoreSum2: number = 8;
const stepTitle1: string = '1.1: Milestone Step 1';
const stepTitle2: string = '1.2: Milestone Step 2';
const componentData1: any = createComponentData(
nodeId1,
componentId1,
counts1,
average1,
scoreCount1,
scoreSum1,
stepTitle1
);
const componentData2: any = createComponentData(
nodeId2,
componentId2,
counts2,
average2,
scoreCount2,
scoreSum2,
stepTitle2
);

describe('MilestoneReportDataComponent', () => {
it('#getPercent() should return percentage', () => {
const comp = new MilestoneReportDataComponent();
comp.data = { scoreCount: 5 };
beforeEach(() => {
comp = new MilestoneReportDataComponent();
comp.data = [componentData1, componentData2];
});

getPercent();
getCount();
getAverage();
getScoreValuesCount();
getComponentData();
});

function getPercent(): void {
it('getPercent() should return percentage', () => {
expect(comp.getPercent()).toEqual('100%');
});
}

it('#getScoreValuesCount() should count for current score value', () => {
const comp = new MilestoneReportDataComponent();
function getCount(): void {
it('getCount() should get the count when scoreValues is not specified', () => {
expect(comp.getCount()).toEqual(2);
});

it('getCount() should get the count when scoreValues is specified', () => {
comp.scoreValues = [5];
comp.data = {
average: 4.3333333333333,
counts: { 1: 0, 2: 0, 3: 1, 4: 0, 5: 2 },
scoreCount: 3,
scoreSum: 13
};
expect(comp.getCount()).toEqual(0);
});
}

function getAverage(): void {
it('getAverage() should get the average', () => {
expect(comp.getAverage()).toEqual(4);
});
}

function getScoreValuesCount(): void {
it('getScoreValuesCount() should get the count for the specified score value', () => {
comp.scoreValues = [4];
expect(comp.getScoreValuesCount()).toEqual(2);
});
});
}

function getComponentData(): void {
it(`getComponentData() should get the last component data if nodeId and componentId are not
specified`, () => {
expect(comp.getComponentData()).toEqual(componentData2);
});

it(`getComponentData() should get the component data if nodeId and componentId are
specified`, () => {
comp.nodeId = nodeId1;
comp.componentId = componentId1;
expect(comp.getComponentData()).toEqual(componentData1);
});
}

function createComponentData(
nodeId: string,
componentId: string,
counts: any,
average: number,
scoreCount: number,
scoreSum: number,
stepTitle: string
): any {
return {
nodeId: nodeId,
componentId: componentId,
average: average,
counts: counts,
scoreCount: scoreCount,
scoreSum: scoreSum,
stepTitle: stepTitle
};
}
Loading

0 comments on commit b11c31b

Please sign in to comment.