Skip to content

Commit

Permalink
Issue #SB-19784 merge: Merge pull request #1152 from Ajoymaity/releas…
Browse files Browse the repository at this point in the history
…e-3.1.0

Issue #SB-19784 fix: Unit test for group details
  • Loading branch information
AmiableAnil authored Jul 23, 2020
2 parents b9f97fb + 38cf53f commit 64b0968
Show file tree
Hide file tree
Showing 2 changed files with 533 additions and 27 deletions.
102 changes: 102 additions & 0 deletions src/app/my-groups/activity-details/activity-details.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { AppHeaderService } from '../../../services';
import { Platform } from '@ionic/angular';
import { Location } from '@angular/common';
import { of } from 'rxjs';
import { CsGroupActivityAggregationMetric } from '@project-sunbird/client-services/services/group/activity';

describe('ActivityDetailsPage', () => {
let activityDetailsPage: ActivityDetailsPage;
Expand Down Expand Up @@ -423,4 +424,105 @@ describe('ActivityDetailsPage', () => {
activityDetailsPage.getMemberName(member);
});
});

describe('calulateProgress', () => {
it('should return progress for activityAgg', () => {
const member = {
agg: [{
metric: CsGroupActivityAggregationMetric.COMPLETED_COUNT,
value: 1
}]
};
activityDetailsPage.activityDetail = {
agg: [{
metric: CsGroupActivityAggregationMetric.LEAF_NODES_COUNT,
value: 1
}]
};
// act
const data = activityDetailsPage.calulateProgress(member);
// assert
expect(data).toBe('100');
});

it('should return progress for activityAgg value is lessthan 0', () => {
const member = {
agg: [{
metric: CsGroupActivityAggregationMetric.COMPLETED_COUNT,
value: 1
}]
};
activityDetailsPage.activityDetail = {
agg: [{
metric: CsGroupActivityAggregationMetric.LEAF_NODES_COUNT,
value: 0
}]
};
// act
const data = activityDetailsPage.calulateProgress(member);
// assert
expect(data).toBe('0');
});

it('should return progress 0 if member agg is empty', () => {
const member = {
agg: []
};
// act
const data = activityDetailsPage.calulateProgress(member);
// assert
expect(data).toBe('0');
});
});

describe('getActivityAggLastUpdatedOn', () => {
it('should return lastUpdatedOn for activityAgg lastUpdatedOn as a string', () => {
activityDetailsPage.activityDetail = {
agg: [{
metric: CsGroupActivityAggregationMetric.ENROLMENT_COUNT,
lastUpdatedOn: '70'
}]
};
// act
const data = activityDetailsPage.getActivityAggLastUpdatedOn();
// assert
expect(data).toBe(70);
});

it('should return lastUpdatedOn for activityAgg lastUpdatedOn as a number', () => {
activityDetailsPage.activityDetail = {
agg: [{
metric: CsGroupActivityAggregationMetric.ENROLMENT_COUNT,
lastUpdatedOn: 50
}]
};
// act
const data = activityDetailsPage.getActivityAggLastUpdatedOn();
// assert
expect(data).toBe(50);
});

it('should return lastUpdatedOn for activityAgg lastUpdatedOn is undefined', () => {
activityDetailsPage.activityDetail = {
agg: [{
metric: CsGroupActivityAggregationMetric.ENROLMENT_COUNT,
lastUpdatedOn: undefined
}]
};
// act
const data = activityDetailsPage.getActivityAggLastUpdatedOn();
// assert
expect(data).toBe(0);
});

it('should return 0 for activityAgg is empty for else part', () => {
activityDetailsPage.activityDetail = {
agg: undefined
};
// act
const data = activityDetailsPage.getActivityAggLastUpdatedOn();
// assert
expect(data).toBe(0);
});
});
});
Loading

0 comments on commit 64b0968

Please sign in to comment.