mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
templating: refactor sorting test
This commit is contained in:
@@ -181,7 +181,7 @@ export class QueryVariable implements Variable {
|
|||||||
options = _.sortBy(options, function(opt) {
|
options = _.sortBy(options, function(opt) {
|
||||||
var matches = opt.text.match(/.*?(\d+).*/);
|
var matches = opt.text.match(/.*?(\d+).*/);
|
||||||
if (!matches || matches.length < 2) {
|
if (!matches || matches.length < 2) {
|
||||||
return 0;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
return parseInt(matches[1], 10);
|
return parseInt(matches[1], 10);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ describe('QueryVariable', () => {
|
|||||||
|
|
||||||
describe('can convert and sort metric names',() => {
|
describe('can convert and sort metric names',() => {
|
||||||
var variable = new QueryVariable({}, null, null, null, null);
|
var variable = new QueryVariable({}, null, null, null, null);
|
||||||
variable.sort = 51;
|
variable.sort = 3; // Numerical (asc)
|
||||||
|
|
||||||
describe('can sort a mixed array of metric variables', () => {
|
describe('can sort a mixed array of metric variables', () => {
|
||||||
var input = [
|
var input = [
|
||||||
@@ -63,15 +63,15 @@ describe('QueryVariable', () => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
var result = variable.metricNamesToVariableValues(input);
|
var result = variable.metricNamesToVariableValues(input);
|
||||||
|
|
||||||
it('should return in same order', () => {
|
it('should return in same order', () => {
|
||||||
expect(result[0].text).to.be('0');
|
var i = 0;
|
||||||
expect(result[1].text).to.be('1');
|
expect(result[i++].text).to.be('');
|
||||||
expect(result[2].text).to.be('');
|
expect(result[i++].text).to.be('0');
|
||||||
expect(result[3].text).to.be('3');
|
expect(result[i++].text).to.be('1');
|
||||||
expect(result[4].text).to.be('4');
|
expect(result[i++].text).to.be('3');
|
||||||
expect(result[5].text).to.be('5');
|
expect(result[i++].text).to.be('4');
|
||||||
expect(result[6].text).to.be('6');
|
expect(result[i++].text).to.be('5');
|
||||||
|
expect(result[i++].text).to.be('6');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user