|
1 | 1 | import { MilestoneReportDataComponent } from './milestone-report-data.component'; |
2 | 2 |
|
| 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 | + |
3 | 37 | 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', () => { |
7 | 52 | expect(comp.getPercent()).toEqual('100%'); |
8 | 53 | }); |
| 54 | +} |
9 | 55 |
|
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', () => { |
12 | 62 | 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]; |
19 | 76 | expect(comp.getScoreValuesCount()).toEqual(2); |
20 | 77 | }); |
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