Use 'count' as the default metric when available (#4606)

* Use 'count' as the default metric when available

Count is a much better default than the current behavior which is to use
whatever the first metric in the list happens to be.

* Addressing nits
This commit is contained in:
Maxime Beauchemin
2018-03-19 21:51:51 -07:00
committed by GitHub
parent 5c98f5642b
commit ed9867c0cc
3 changed files with 55 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ import { expect } from 'chai';
import {
tryNumify, slugify, formatSelectOptionsForRange, d3format,
d3FormatPreset, d3TimeFormatPreset, defaultNumberFormatter,
mainMetric,
} from '../../../javascripts/modules/utils';
describe('utils', () => {
@@ -69,4 +70,31 @@ describe('utils', () => {
expect(defaultNumberFormatter(-111000000)).to.equal('-111M');
expect(defaultNumberFormatter(-0.23)).to.equal('-230m');
});
describe('mainMetric', () => {
it('is null when no options', () => {
expect(mainMetric([])).to.equal(undefined);
expect(mainMetric(null)).to.equal(undefined);
});
it('prefers the "count" metric when first', () => {
const metrics = [
{ metric_name: 'count' },
{ metric_name: 'foo' },
];
expect(mainMetric(metrics)).to.equal('count');
});
it('prefers the "count" metric when not first', () => {
const metrics = [
{ metric_name: 'foo' },
{ metric_name: 'count' },
];
expect(mainMetric(metrics)).to.equal('count');
});
it('selects the first metric when "count" is not an option', () => {
const metrics = [
{ metric_name: 'foo' },
{ metric_name: 'not_count' },
];
expect(mainMetric(metrics)).to.equal('foo');
});
});
});