|
@@ -2,6 +2,7 @@ import {mount} from 'enzyme';
|
|
|
|
|
|
import {
|
|
|
getChartData,
|
|
|
+ getChartDataWithPercentages,
|
|
|
getChartDataByDay,
|
|
|
getDisplayValue,
|
|
|
getDisplayText,
|
|
@@ -45,55 +46,43 @@ describe('Utils', function() {
|
|
|
|
|
|
expect(getChartData(raw, query)).toEqual(expected);
|
|
|
});
|
|
|
+ });
|
|
|
|
|
|
- it('customizes separator', function() {
|
|
|
- const expected = [
|
|
|
- {
|
|
|
- seriesName: 'count',
|
|
|
- data: [
|
|
|
- {value: 2, name: 'project.id 5, environment null'},
|
|
|
- {value: 2, name: 'project.id 5, environment staging'},
|
|
|
- {value: 2, name: 'project.id 5, environment alpha'},
|
|
|
- {value: 6, name: 'project.id 5, environment production'},
|
|
|
- ],
|
|
|
- },
|
|
|
- {
|
|
|
- seriesName: 'uniq_id',
|
|
|
- data: [
|
|
|
- {value: 1, name: 'project.id 5, environment null'},
|
|
|
- {value: 3, name: 'project.id 5, environment staging'},
|
|
|
- {value: 4, name: 'project.id 5, environment alpha'},
|
|
|
- {value: 10, name: 'project.id 5, environment production'},
|
|
|
- ],
|
|
|
- },
|
|
|
- ];
|
|
|
-
|
|
|
- expect(getChartData(raw, query, {separator: ', '})).toEqual(expected);
|
|
|
- });
|
|
|
+ describe('getChartDataWithPercentages()', function() {
|
|
|
+ const raw = [
|
|
|
+ {count: 2, uniq_id: 1, 'project.id': 5, environment: null},
|
|
|
+ {count: 2, uniq_id: 3, 'project.id': 5, environment: 'staging'},
|
|
|
+ {count: 2, uniq_id: 4, 'project.id': 5, environment: 'alpha'},
|
|
|
+ {count: 6, uniq_id: 10, 'project.id': 5, environment: 'production'},
|
|
|
+ ];
|
|
|
+ const query = {
|
|
|
+ aggregations: [['count()', null, 'count'], ['uniq', 'id', 'uniq_id']],
|
|
|
+ fields: ['project.id', 'environment'],
|
|
|
+ };
|
|
|
|
|
|
- it('hides field name for series label', function() {
|
|
|
+ it('returns chart data with percentages', function() {
|
|
|
const expected = [
|
|
|
{
|
|
|
seriesName: 'count',
|
|
|
data: [
|
|
|
- {value: 2, name: '5 null'},
|
|
|
- {value: 2, name: '5 staging'},
|
|
|
- {value: 2, name: '5 alpha'},
|
|
|
- {value: 6, name: '5 production'},
|
|
|
+ {value: 2, percentage: 16.67, name: '5 null'},
|
|
|
+ {value: 2, percentage: 16.67, name: '5 staging'},
|
|
|
+ {value: 2, percentage: 16.67, name: '5 alpha'},
|
|
|
+ {value: 6, percentage: 50, name: '5 production'},
|
|
|
],
|
|
|
},
|
|
|
{
|
|
|
seriesName: 'uniq_id',
|
|
|
data: [
|
|
|
- {value: 1, name: '5 null'},
|
|
|
- {value: 3, name: '5 staging'},
|
|
|
- {value: 4, name: '5 alpha'},
|
|
|
- {value: 10, name: '5 production'},
|
|
|
+ {value: 1, percentage: 5.56, name: '5 null'},
|
|
|
+ {value: 3, percentage: 16.67, name: '5 staging'},
|
|
|
+ {value: 4, percentage: 22.22, name: '5 alpha'},
|
|
|
+ {value: 10, percentage: 55.56, name: '5 production'},
|
|
|
],
|
|
|
},
|
|
|
];
|
|
|
|
|
|
- expect(getChartData(raw, query, {hideFieldName: true})).toEqual(expected);
|
|
|
+ expect(getChartDataWithPercentages(raw, query)).toEqual(expected);
|
|
|
});
|
|
|
});
|
|
|
|