prettier: change to single quoting

This commit is contained in:
Torkel Ödegaard
2017-12-20 12:33:33 +01:00
parent 2a360c45a2
commit 85879a7014
304 changed files with 10558 additions and 10519 deletions
+10 -10
View File
@@ -3,16 +3,16 @@ import {
beforeEach,
it,
expect,
angularMocks
} from "test/lib/common";
import "app/core/services/backend_srv";
angularMocks,
} from 'test/lib/common';
import 'app/core/services/backend_srv';
describe("backend_srv", function() {
describe('backend_srv', function() {
var _backendSrv;
var _httpBackend;
beforeEach(angularMocks.module("grafana.core"));
beforeEach(angularMocks.module("grafana.services"));
beforeEach(angularMocks.module('grafana.core'));
beforeEach(angularMocks.module('grafana.services'));
beforeEach(
angularMocks.inject(function($httpBackend, $http, backendSrv) {
_httpBackend = $httpBackend;
@@ -20,12 +20,12 @@ describe("backend_srv", function() {
})
);
describe("when handling errors", function() {
it("should return the http status code", function(done) {
_httpBackend.whenGET("gateway-error").respond(502);
describe('when handling errors', function() {
it('should return the http status code', function(done) {
_httpBackend.whenGET('gateway-error').respond(502);
_backendSrv
.datasourceRequest({
url: "gateway-error"
url: 'gateway-error',
})
.catch(function(err) {
expect(err.status).to.be(502);
+46 -46
View File
@@ -1,55 +1,55 @@
import sinon from "sinon";
import sinon from 'sinon';
import * as dateMath from "app/core/utils/datemath";
import moment from "moment";
import _ from "lodash";
import * as dateMath from 'app/core/utils/datemath';
import moment from 'moment';
import _ from 'lodash';
describe("DateMath", () => {
var spans = ["s", "m", "h", "d", "w", "M", "y"];
var anchor = "2014-01-01T06:06:06.666Z";
describe('DateMath', () => {
var spans = ['s', 'm', 'h', 'd', 'w', 'M', 'y'];
var anchor = '2014-01-01T06:06:06.666Z';
var unix = moment(anchor).valueOf();
var format = "YYYY-MM-DDTHH:mm:ss.SSSZ";
var format = 'YYYY-MM-DDTHH:mm:ss.SSSZ';
var clock;
describe("errors", () => {
it("should return undefined if passed something falsy", () => {
describe('errors', () => {
it('should return undefined if passed something falsy', () => {
expect(dateMath.parse(false)).toBe(undefined);
});
it("should return undefined if I pass an operator besides [+-/]", () => {
expect(dateMath.parse("now&1d")).toBe(undefined);
it('should return undefined if I pass an operator besides [+-/]', () => {
expect(dateMath.parse('now&1d')).toBe(undefined);
});
it(
"should return undefined if I pass a unit besides" + spans.toString(),
'should return undefined if I pass a unit besides' + spans.toString(),
() => {
expect(dateMath.parse("now+5f")).toBe(undefined);
expect(dateMath.parse('now+5f')).toBe(undefined);
}
);
it("should return undefined if rounding unit is not 1", () => {
expect(dateMath.parse("now/2y")).toBe(undefined);
expect(dateMath.parse("now/0.5y")).toBe(undefined);
it('should return undefined if rounding unit is not 1', () => {
expect(dateMath.parse('now/2y')).toBe(undefined);
expect(dateMath.parse('now/0.5y')).toBe(undefined);
});
it("should not go into an infinite loop when missing a unit", () => {
expect(dateMath.parse("now-0")).toBe(undefined);
expect(dateMath.parse("now-00")).toBe(undefined);
it('should not go into an infinite loop when missing a unit', () => {
expect(dateMath.parse('now-0')).toBe(undefined);
expect(dateMath.parse('now-00')).toBe(undefined);
});
});
it("now/d should set to start of current day", () => {
it('now/d should set to start of current day', () => {
var expected = new Date();
expected.setHours(0);
expected.setMinutes(0);
expected.setSeconds(0);
expected.setMilliseconds(0);
var startOfDay = dateMath.parse("now/d", false).valueOf();
var startOfDay = dateMath.parse('now/d', false).valueOf();
expect(startOfDay).toBe(expected.getTime());
});
it("now/d on a utc dashboard should be start of the current day in UTC time", () => {
it('now/d on a utc dashboard should be start of the current day in UTC time', () => {
var today = new Date();
var expected = new Date(
Date.UTC(
@@ -63,11 +63,11 @@ describe("DateMath", () => {
)
);
var startOfDay = dateMath.parse("now/d", false, "utc").valueOf();
var startOfDay = dateMath.parse('now/d', false, 'utc').valueOf();
expect(startOfDay).toBe(expected.getTime());
});
describe("subtraction", () => {
describe('subtraction', () => {
var now;
var anchored;
@@ -78,16 +78,16 @@ describe("DateMath", () => {
});
_.each(spans, span => {
var nowEx = "now-5" + span;
var thenEx = anchor + "||-5" + span;
var nowEx = 'now-5' + span;
var thenEx = anchor + '||-5' + span;
it("should return 5" + span + " ago", () => {
it('should return 5' + span + ' ago', () => {
expect(dateMath.parse(nowEx).format(format)).toEqual(
now.subtract(5, span).format(format)
);
});
it("should return 5" + span + " before " + anchor, () => {
it('should return 5' + span + ' before ' + anchor, () => {
expect(dateMath.parse(thenEx).format(format)).toEqual(
anchored.subtract(5, span).format(format)
);
@@ -99,7 +99,7 @@ describe("DateMath", () => {
});
});
describe("rounding", () => {
describe('rounding', () => {
var now;
beforeEach(() => {
@@ -108,14 +108,14 @@ describe("DateMath", () => {
});
_.each(spans, span => {
it("should round now to the beginning of the " + span, function() {
expect(dateMath.parse("now/" + span).format(format)).toEqual(
it('should round now to the beginning of the ' + span, function() {
expect(dateMath.parse('now/' + span).format(format)).toEqual(
now.startOf(span).format(format)
);
});
it("should round now to the end of the " + span, function() {
expect(dateMath.parse("now/" + span, true).format(format)).toEqual(
it('should round now to the end of the ' + span, function() {
expect(dateMath.parse('now/' + span, true).format(format)).toEqual(
now.endOf(span).format(format)
);
});
@@ -126,28 +126,28 @@ describe("DateMath", () => {
});
});
describe("isValid", () => {
it("should return false when invalid date text", () => {
expect(dateMath.isValid("asd")).toBe(false);
describe('isValid', () => {
it('should return false when invalid date text', () => {
expect(dateMath.isValid('asd')).toBe(false);
});
it("should return true when valid date text", () => {
expect(dateMath.isValid("now-1h")).toBe(true);
it('should return true when valid date text', () => {
expect(dateMath.isValid('now-1h')).toBe(true);
});
});
describe("relative time to date parsing", function() {
it("should handle negative time", function() {
var date = dateMath.parseDateMath("-2d", moment([2014, 1, 5]));
describe('relative time to date parsing', function() {
it('should handle negative time', function() {
var date = dateMath.parseDateMath('-2d', moment([2014, 1, 5]));
expect(date.valueOf()).toEqual(moment([2014, 1, 3]).valueOf());
});
it("should handle multiple math expressions", function() {
var date = dateMath.parseDateMath("-2d-6h", moment([2014, 1, 5]));
it('should handle multiple math expressions', function() {
var date = dateMath.parseDateMath('-2d-6h', moment([2014, 1, 5]));
expect(date.valueOf()).toEqual(moment([2014, 1, 2, 18]).valueOf());
});
it("should return false when invalid expression", function() {
var date = dateMath.parseDateMath("2", moment([2014, 1, 5]));
it('should return false when invalid expression', function() {
var date = dateMath.parseDateMath('2', moment([2014, 1, 5]));
expect(date).toEqual(undefined);
});
});
+17 -17
View File
@@ -1,26 +1,26 @@
import { Emitter } from "../utils/emitter";
import { Emitter } from '../utils/emitter';
describe("Emitter", () => {
describe("given 2 subscribers", () => {
it("should notfiy subscribers", () => {
describe('Emitter', () => {
describe('given 2 subscribers', () => {
it('should notfiy subscribers', () => {
var events = new Emitter();
var sub1Called = false;
var sub2Called = false;
events.on("test", () => {
events.on('test', () => {
sub1Called = true;
});
events.on("test", () => {
events.on('test', () => {
sub2Called = true;
});
events.emit("test", null);
events.emit('test', null);
expect(sub1Called).toBe(true);
expect(sub2Called).toBe(true);
});
it("when subscribing twice", () => {
it('when subscribing twice', () => {
var events = new Emitter();
var sub1Called = 0;
@@ -28,33 +28,33 @@ describe("Emitter", () => {
sub1Called += 1;
}
events.on("test", handler);
events.on("test", handler);
events.on('test', handler);
events.on('test', handler);
events.emit("test", null);
events.emit('test', null);
expect(sub1Called).toBe(2);
});
it("should handle errors", () => {
it('should handle errors', () => {
var events = new Emitter();
var sub1Called = 0;
var sub2Called = 0;
events.on("test", () => {
events.on('test', () => {
sub1Called++;
throw { message: "hello" };
throw { message: 'hello' };
});
events.on("test", () => {
events.on('test', () => {
sub2Called++;
});
try {
events.emit("test", null);
events.emit('test', null);
} catch (_) {}
try {
events.emit("test", null);
events.emit('test', null);
} catch (_) {}
expect(sub1Called).toBe(2);
+11 -11
View File
@@ -1,22 +1,22 @@
import flatten from "app/core/utils/flatten";
import flatten from 'app/core/utils/flatten';
describe("flatten", () => {
it("should return flatten object", () => {
describe('flatten', () => {
it('should return flatten object', () => {
var flattened = flatten(
{
level1: "level1-value",
level1: 'level1-value',
deeper: {
level2: "level2-value",
level2: 'level2-value',
deeper: {
level3: "level3-value"
}
}
level3: 'level3-value',
},
},
},
null
);
expect(flattened["level1"]).toBe("level1-value");
expect(flattened["deeper.level2"]).toBe("level2-value");
expect(flattened["deeper.deeper.level3"]).toBe("level3-value");
expect(flattened['level1']).toBe('level1-value');
expect(flattened['deeper.level2']).toBe('level2-value');
expect(flattened['deeper.deeper.level3']).toBe('level3-value');
});
});
@@ -1,23 +1,23 @@
import { GlobalEventSrv } from "app/core/services/global_event_srv";
import { beforeEach } from "test/lib/common";
import { GlobalEventSrv } from 'app/core/services/global_event_srv';
import { beforeEach } from 'test/lib/common';
jest.mock("app/core/config", () => {
jest.mock('app/core/config', () => {
return {
appSubUrl: "/subUrl"
appSubUrl: '/subUrl',
};
});
describe("GlobalEventSrv", () => {
describe('GlobalEventSrv', () => {
let searchSrv;
beforeEach(() => {
searchSrv = new GlobalEventSrv(null, null, null);
});
describe("With /subUrl as appSubUrl", () => {
it("/subUrl should be stripped", () => {
const urlWithoutMaster = searchSrv.stripBaseFromUrl("/subUrl/grafana/");
expect(urlWithoutMaster).toBe("/grafana/");
describe('With /subUrl as appSubUrl', () => {
it('/subUrl should be stripped', () => {
const urlWithoutMaster = searchSrv.stripBaseFromUrl('/subUrl/grafana/');
expect(urlWithoutMaster).toBe('/grafana/');
});
});
});
+202 -202
View File
@@ -1,29 +1,29 @@
import kbn from "../utils/kbn";
import * as dateMath from "../utils/datemath";
import moment from "moment";
import kbn from '../utils/kbn';
import * as dateMath from '../utils/datemath';
import moment from 'moment';
describe("unit format menu", function() {
describe('unit format menu', function() {
var menu = kbn.getUnitFormats();
menu.map(function(submenu) {
describe("submenu " + submenu.text, function() {
it("should have a title", function() {
expect(typeof submenu.text).toBe("string");
describe('submenu ' + submenu.text, function() {
it('should have a title', function() {
expect(typeof submenu.text).toBe('string');
});
it("should have a submenu", function() {
it('should have a submenu', function() {
expect(Array.isArray(submenu.submenu)).toBe(true);
});
submenu.submenu.map(function(entry) {
describe("entry " + entry.text, function() {
it("should have a title", function() {
expect(typeof entry.text).toBe("string");
describe('entry ' + entry.text, function() {
it('should have a title', function() {
expect(typeof entry.text).toBe('string');
});
it("should have a format", function() {
expect(typeof entry.value).toBe("string");
it('should have a format', function() {
expect(typeof entry.value).toBe('string');
});
it("should have a valid format", function() {
expect(typeof kbn.valueFormats[entry.value]).toBe("function");
it('should have a valid format', function() {
expect(typeof kbn.valueFormats[entry.value]).toBe('function');
});
});
});
@@ -32,8 +32,8 @@ describe("unit format menu", function() {
});
function describeValueFormat(desc, value, tickSize, tickDecimals, result) {
describe("value format: " + desc, function() {
it("should translate " + value + " as " + result, function() {
describe('value format: ' + desc, function() {
it('should translate ' + value + ' as ' + result, function() {
var scaledDecimals =
tickDecimals - Math.floor(Math.log(tickSize) / Math.LN10);
var str = kbn.valueFormats[desc](value, tickDecimals, scaledDecimals);
@@ -42,314 +42,314 @@ function describeValueFormat(desc, value, tickSize, tickDecimals, result) {
});
}
describeValueFormat("ms", 0.0024, 0.0005, 4, "0.0024 ms");
describeValueFormat("ms", 100, 1, 0, "100 ms");
describeValueFormat("ms", 1250, 10, 0, "1.25 s");
describeValueFormat("ms", 1250, 300, 0, "1.3 s");
describeValueFormat("ms", 65150, 10000, 0, "1.1 min");
describeValueFormat("ms", 6515000, 1500000, 0, "1.8 hour");
describeValueFormat("ms", 651500000, 150000000, 0, "8 day");
describeValueFormat('ms', 0.0024, 0.0005, 4, '0.0024 ms');
describeValueFormat('ms', 100, 1, 0, '100 ms');
describeValueFormat('ms', 1250, 10, 0, '1.25 s');
describeValueFormat('ms', 1250, 300, 0, '1.3 s');
describeValueFormat('ms', 65150, 10000, 0, '1.1 min');
describeValueFormat('ms', 6515000, 1500000, 0, '1.8 hour');
describeValueFormat('ms', 651500000, 150000000, 0, '8 day');
describeValueFormat("none", 2.75e-10, 0, 10, "3e-10");
describeValueFormat("none", 0, 0, 2, "0");
describeValueFormat("dB", 10, 1000, 2, "10.00 dB");
describeValueFormat('none', 2.75e-10, 0, 10, '3e-10');
describeValueFormat('none', 0, 0, 2, '0');
describeValueFormat('dB', 10, 1000, 2, '10.00 dB');
describeValueFormat("percent", 0, 0, 0, "0%");
describeValueFormat("percent", 53, 0, 1, "53.0%");
describeValueFormat("percentunit", 0.0, 0, 0, "0%");
describeValueFormat("percentunit", 0.278, 0, 1, "27.8%");
describeValueFormat("percentunit", 1.0, 0, 0, "100%");
describeValueFormat('percent', 0, 0, 0, '0%');
describeValueFormat('percent', 53, 0, 1, '53.0%');
describeValueFormat('percentunit', 0.0, 0, 0, '0%');
describeValueFormat('percentunit', 0.278, 0, 1, '27.8%');
describeValueFormat('percentunit', 1.0, 0, 0, '100%');
describeValueFormat("currencyUSD", 7.42, 10000, 2, "$7.42");
describeValueFormat("currencyUSD", 1532.82, 1000, 1, "$1.53K");
describeValueFormat("currencyUSD", 18520408.7, 10000000, 0, "$19M");
describeValueFormat('currencyUSD', 7.42, 10000, 2, '$7.42');
describeValueFormat('currencyUSD', 1532.82, 1000, 1, '$1.53K');
describeValueFormat('currencyUSD', 18520408.7, 10000000, 0, '$19M');
describeValueFormat("bytes", -1.57e308, -1.57e308, 2, "NA");
describeValueFormat('bytes', -1.57e308, -1.57e308, 2, 'NA');
describeValueFormat("ns", 25, 1, 0, "25 ns");
describeValueFormat("ns", 2558, 50, 0, "2.56 µs");
describeValueFormat('ns', 25, 1, 0, '25 ns');
describeValueFormat('ns', 2558, 50, 0, '2.56 µs');
describeValueFormat("ops", 123, 1, 0, "123 ops");
describeValueFormat("rps", 456000, 1000, -1, "456K rps");
describeValueFormat("rps", 123456789, 1000000, 2, "123.457M rps");
describeValueFormat("wps", 789000000, 1000000, -1, "789M wps");
describeValueFormat("iops", 11000000000, 1000000000, -1, "11B iops");
describeValueFormat('ops', 123, 1, 0, '123 ops');
describeValueFormat('rps', 456000, 1000, -1, '456K rps');
describeValueFormat('rps', 123456789, 1000000, 2, '123.457M rps');
describeValueFormat('wps', 789000000, 1000000, -1, '789M wps');
describeValueFormat('iops', 11000000000, 1000000000, -1, '11B iops');
describeValueFormat("s", 1.23456789e-7, 1e-10, 8, "123.5 ns");
describeValueFormat("s", 1.23456789e-4, 1e-7, 5, "123.5 µs");
describeValueFormat("s", 1.23456789e-3, 1e-6, 4, "1.235 ms");
describeValueFormat("s", 1.23456789e-2, 1e-5, 3, "12.35 ms");
describeValueFormat("s", 1.23456789e-1, 1e-4, 2, "123.5 ms");
describeValueFormat("s", 24, 1, 0, "24 s");
describeValueFormat("s", 246, 1, 0, "4.1 min");
describeValueFormat("s", 24567, 100, 0, "6.82 hour");
describeValueFormat("s", 24567890, 10000, 0, "40.62 week");
describeValueFormat("s", 24567890000, 1000000, 0, "778.53 year");
describeValueFormat('s', 1.23456789e-7, 1e-10, 8, '123.5 ns');
describeValueFormat('s', 1.23456789e-4, 1e-7, 5, '123.5 µs');
describeValueFormat('s', 1.23456789e-3, 1e-6, 4, '1.235 ms');
describeValueFormat('s', 1.23456789e-2, 1e-5, 3, '12.35 ms');
describeValueFormat('s', 1.23456789e-1, 1e-4, 2, '123.5 ms');
describeValueFormat('s', 24, 1, 0, '24 s');
describeValueFormat('s', 246, 1, 0, '4.1 min');
describeValueFormat('s', 24567, 100, 0, '6.82 hour');
describeValueFormat('s', 24567890, 10000, 0, '40.62 week');
describeValueFormat('s', 24567890000, 1000000, 0, '778.53 year');
describeValueFormat("m", 24, 1, 0, "24 min");
describeValueFormat("m", 246, 10, 0, "4.1 hour");
describeValueFormat("m", 6545, 10, 0, "4.55 day");
describeValueFormat("m", 24567, 100, 0, "2.44 week");
describeValueFormat("m", 24567892, 10000, 0, "46.7 year");
describeValueFormat('m', 24, 1, 0, '24 min');
describeValueFormat('m', 246, 10, 0, '4.1 hour');
describeValueFormat('m', 6545, 10, 0, '4.55 day');
describeValueFormat('m', 24567, 100, 0, '2.44 week');
describeValueFormat('m', 24567892, 10000, 0, '46.7 year');
describeValueFormat("h", 21, 1, 0, "21 hour");
describeValueFormat("h", 145, 1, 0, "6.04 day");
describeValueFormat("h", 1234, 100, 0, "7.3 week");
describeValueFormat("h", 9458, 1000, 0, "1.08 year");
describeValueFormat('h', 21, 1, 0, '21 hour');
describeValueFormat('h', 145, 1, 0, '6.04 day');
describeValueFormat('h', 1234, 100, 0, '7.3 week');
describeValueFormat('h', 9458, 1000, 0, '1.08 year');
describeValueFormat("d", 3, 1, 0, "3 day");
describeValueFormat("d", 245, 100, 0, "35 week");
describeValueFormat("d", 2456, 10, 0, "6.73 year");
describeValueFormat('d', 3, 1, 0, '3 day');
describeValueFormat('d', 245, 100, 0, '35 week');
describeValueFormat('d', 2456, 10, 0, '6.73 year');
describe("date time formats", function() {
it("should format as iso date", function() {
describe('date time formats', function() {
it('should format as iso date', function() {
var str = kbn.valueFormats.dateTimeAsIso(1505634997920, 1);
expect(str).toBe(moment(1505634997920).format("YYYY-MM-DD HH:mm:ss"));
expect(str).toBe(moment(1505634997920).format('YYYY-MM-DD HH:mm:ss'));
});
it("should format as iso date and skip date when today", function() {
it('should format as iso date and skip date when today', function() {
var now = moment();
var str = kbn.valueFormats.dateTimeAsIso(now.valueOf(), 1);
expect(str).toBe(now.format("HH:mm:ss"));
expect(str).toBe(now.format('HH:mm:ss'));
});
it("should format as US date", function() {
it('should format as US date', function() {
var str = kbn.valueFormats.dateTimeAsUS(1505634997920, 1);
expect(str).toBe(moment(1505634997920).format("MM/DD/YYYY h:mm:ss a"));
expect(str).toBe(moment(1505634997920).format('MM/DD/YYYY h:mm:ss a'));
});
it("should format as US date and skip date when today", function() {
it('should format as US date and skip date when today', function() {
var now = moment();
var str = kbn.valueFormats.dateTimeAsUS(now.valueOf(), 1);
expect(str).toBe(now.format("h:mm:ss a"));
expect(str).toBe(now.format('h:mm:ss a'));
});
it("should format as from now with days", function() {
var daysAgo = moment().add(-7, "d");
it('should format as from now with days', function() {
var daysAgo = moment().add(-7, 'd');
var str = kbn.valueFormats.dateTimeFromNow(daysAgo.valueOf(), 1);
expect(str).toBe("7 days ago");
expect(str).toBe('7 days ago');
});
it("should format as from now with minutes", function() {
var daysAgo = moment().add(-2, "m");
it('should format as from now with minutes', function() {
var daysAgo = moment().add(-2, 'm');
var str = kbn.valueFormats.dateTimeFromNow(daysAgo.valueOf(), 1);
expect(str).toBe("2 minutes ago");
expect(str).toBe('2 minutes ago');
});
});
describe("kbn.toFixed and negative decimals", function() {
it("should treat as zero decimals", function() {
describe('kbn.toFixed and negative decimals', function() {
it('should treat as zero decimals', function() {
var str = kbn.toFixed(186.123, -2);
expect(str).toBe("186");
expect(str).toBe('186');
});
});
describe("kbn ms format when scaled decimals is null do not use it", function() {
it("should use specified decimals", function() {
var str = kbn.valueFormats["ms"](10000086.123, 1, null);
expect(str).toBe("2.8 hour");
describe('kbn ms format when scaled decimals is null do not use it', function() {
it('should use specified decimals', function() {
var str = kbn.valueFormats['ms'](10000086.123, 1, null);
expect(str).toBe('2.8 hour');
});
});
describe("kbn kbytes format when scaled decimals is null do not use it", function() {
it("should use specified decimals", function() {
var str = kbn.valueFormats["kbytes"](10000000, 3, null);
expect(str).toBe("9.537 GiB");
describe('kbn kbytes format when scaled decimals is null do not use it', function() {
it('should use specified decimals', function() {
var str = kbn.valueFormats['kbytes'](10000000, 3, null);
expect(str).toBe('9.537 GiB');
});
});
describe("kbn deckbytes format when scaled decimals is null do not use it", function() {
it("should use specified decimals", function() {
var str = kbn.valueFormats["deckbytes"](10000000, 3, null);
expect(str).toBe("10.000 GB");
describe('kbn deckbytes format when scaled decimals is null do not use it', function() {
it('should use specified decimals', function() {
var str = kbn.valueFormats['deckbytes'](10000000, 3, null);
expect(str).toBe('10.000 GB');
});
});
describe("kbn roundValue", function() {
it("should should handle null value", function() {
describe('kbn roundValue', function() {
it('should should handle null value', function() {
var str = kbn.roundValue(null, 2);
expect(str).toBe(null);
});
it("should round value", function() {
it('should round value', function() {
var str = kbn.roundValue(200.877, 2);
expect(str).toBe(200.88);
});
});
describe("calculateInterval", function() {
it("1h 100 resultion", function() {
var range = { from: dateMath.parse("now-1h"), to: dateMath.parse("now") };
describe('calculateInterval', function() {
it('1h 100 resultion', function() {
var range = { from: dateMath.parse('now-1h'), to: dateMath.parse('now') };
var res = kbn.calculateInterval(range, 100, null);
expect(res.interval).toBe("30s");
expect(res.interval).toBe('30s');
});
it("10m 1600 resolution", function() {
var range = { from: dateMath.parse("now-10m"), to: dateMath.parse("now") };
it('10m 1600 resolution', function() {
var range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') };
var res = kbn.calculateInterval(range, 1600, null);
expect(res.interval).toBe("500ms");
expect(res.interval).toBe('500ms');
expect(res.intervalMs).toBe(500);
});
it("fixed user min interval", function() {
var range = { from: dateMath.parse("now-10m"), to: dateMath.parse("now") };
var res = kbn.calculateInterval(range, 1600, "10s");
expect(res.interval).toBe("10s");
it('fixed user min interval', function() {
var range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') };
var res = kbn.calculateInterval(range, 1600, '10s');
expect(res.interval).toBe('10s');
expect(res.intervalMs).toBe(10000);
});
it("short time range and user low limit", function() {
var range = { from: dateMath.parse("now-10m"), to: dateMath.parse("now") };
var res = kbn.calculateInterval(range, 1600, ">10s");
expect(res.interval).toBe("10s");
it('short time range and user low limit', function() {
var range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') };
var res = kbn.calculateInterval(range, 1600, '>10s');
expect(res.interval).toBe('10s');
});
it("large time range and user low limit", function() {
var range = { from: dateMath.parse("now-14d"), to: dateMath.parse("now") };
var res = kbn.calculateInterval(range, 1000, ">10s");
expect(res.interval).toBe("20m");
it('large time range and user low limit', function() {
var range = { from: dateMath.parse('now-14d'), to: dateMath.parse('now') };
var res = kbn.calculateInterval(range, 1000, '>10s');
expect(res.interval).toBe('20m');
});
it("10s 900 resolution and user low limit in ms", function() {
var range = { from: dateMath.parse("now-10s"), to: dateMath.parse("now") };
var res = kbn.calculateInterval(range, 900, ">15ms");
expect(res.interval).toBe("15ms");
it('10s 900 resolution and user low limit in ms', function() {
var range = { from: dateMath.parse('now-10s'), to: dateMath.parse('now') };
var res = kbn.calculateInterval(range, 900, '>15ms');
expect(res.interval).toBe('15ms');
});
it("1d 1 resolution", function() {
var range = { from: dateMath.parse("now-1d"), to: dateMath.parse("now") };
it('1d 1 resolution', function() {
var range = { from: dateMath.parse('now-1d'), to: dateMath.parse('now') };
var res = kbn.calculateInterval(range, 1, null);
expect(res.interval).toBe("1d");
expect(res.interval).toBe('1d');
expect(res.intervalMs).toBe(86400000);
});
it("86399s 1 resolution", function() {
it('86399s 1 resolution', function() {
var range = {
from: dateMath.parse("now-86390s"),
to: dateMath.parse("now")
from: dateMath.parse('now-86390s'),
to: dateMath.parse('now'),
};
var res = kbn.calculateInterval(range, 1, null);
expect(res.interval).toBe("12h");
expect(res.interval).toBe('12h');
expect(res.intervalMs).toBe(43200000);
});
});
describe("hex", function() {
it("positive integer", function() {
describe('hex', function() {
it('positive integer', function() {
var str = kbn.valueFormats.hex(100, 0);
expect(str).toBe("64");
expect(str).toBe('64');
});
it("negative integer", function() {
it('negative integer', function() {
var str = kbn.valueFormats.hex(-100, 0);
expect(str).toBe("-64");
expect(str).toBe('-64');
});
it("null", function() {
it('null', function() {
var str = kbn.valueFormats.hex(null, 0);
expect(str).toBe("");
expect(str).toBe('');
});
it("positive float", function() {
it('positive float', function() {
var str = kbn.valueFormats.hex(50.52, 1);
expect(str).toBe("32.8");
expect(str).toBe('32.8');
});
it("negative float", function() {
it('negative float', function() {
var str = kbn.valueFormats.hex(-50.333, 2);
expect(str).toBe("-32.547AE147AE14");
expect(str).toBe('-32.547AE147AE14');
});
});
describe("hex 0x", function() {
it("positive integeter", function() {
describe('hex 0x', function() {
it('positive integeter', function() {
var str = kbn.valueFormats.hex0x(7999, 0);
expect(str).toBe("0x1F3F");
expect(str).toBe('0x1F3F');
});
it("negative integer", function() {
it('negative integer', function() {
var str = kbn.valueFormats.hex0x(-584, 0);
expect(str).toBe("-0x248");
expect(str).toBe('-0x248');
});
it("null", function() {
it('null', function() {
var str = kbn.valueFormats.hex0x(null, 0);
expect(str).toBe("");
expect(str).toBe('');
});
it("positive float", function() {
it('positive float', function() {
var str = kbn.valueFormats.hex0x(74.443, 3);
expect(str).toBe("0x4A.716872B020C4");
expect(str).toBe('0x4A.716872B020C4');
});
it("negative float", function() {
it('negative float', function() {
var str = kbn.valueFormats.hex0x(-65.458, 1);
expect(str).toBe("-0x41.8");
expect(str).toBe('-0x41.8');
});
});
describe("duration", function() {
it("null", function() {
var str = kbn.toDuration(null, 0, "millisecond");
expect(str).toBe("");
describe('duration', function() {
it('null', function() {
var str = kbn.toDuration(null, 0, 'millisecond');
expect(str).toBe('');
});
it("0 milliseconds", function() {
var str = kbn.toDuration(0, 0, "millisecond");
expect(str).toBe("0 milliseconds");
it('0 milliseconds', function() {
var str = kbn.toDuration(0, 0, 'millisecond');
expect(str).toBe('0 milliseconds');
});
it("1 millisecond", function() {
var str = kbn.toDuration(1, 0, "millisecond");
expect(str).toBe("1 millisecond");
it('1 millisecond', function() {
var str = kbn.toDuration(1, 0, 'millisecond');
expect(str).toBe('1 millisecond');
});
it("-1 millisecond", function() {
var str = kbn.toDuration(-1, 0, "millisecond");
expect(str).toBe("1 millisecond ago");
it('-1 millisecond', function() {
var str = kbn.toDuration(-1, 0, 'millisecond');
expect(str).toBe('1 millisecond ago');
});
it("seconds", function() {
var str = kbn.toDuration(1, 0, "second");
expect(str).toBe("1 second");
it('seconds', function() {
var str = kbn.toDuration(1, 0, 'second');
expect(str).toBe('1 second');
});
it("minutes", function() {
var str = kbn.toDuration(1, 0, "minute");
expect(str).toBe("1 minute");
it('minutes', function() {
var str = kbn.toDuration(1, 0, 'minute');
expect(str).toBe('1 minute');
});
it("hours", function() {
var str = kbn.toDuration(1, 0, "hour");
expect(str).toBe("1 hour");
it('hours', function() {
var str = kbn.toDuration(1, 0, 'hour');
expect(str).toBe('1 hour');
});
it("days", function() {
var str = kbn.toDuration(1, 0, "day");
expect(str).toBe("1 day");
it('days', function() {
var str = kbn.toDuration(1, 0, 'day');
expect(str).toBe('1 day');
});
it("weeks", function() {
var str = kbn.toDuration(1, 0, "week");
expect(str).toBe("1 week");
it('weeks', function() {
var str = kbn.toDuration(1, 0, 'week');
expect(str).toBe('1 week');
});
it("months", function() {
var str = kbn.toDuration(1, 0, "month");
expect(str).toBe("1 month");
it('months', function() {
var str = kbn.toDuration(1, 0, 'month');
expect(str).toBe('1 month');
});
it("years", function() {
var str = kbn.toDuration(1, 0, "year");
expect(str).toBe("1 year");
it('years', function() {
var str = kbn.toDuration(1, 0, 'year');
expect(str).toBe('1 year');
});
it("decimal days", function() {
var str = kbn.toDuration(1.5, 2, "day");
expect(str).toBe("1 day, 12 hours, 0 minutes");
it('decimal days', function() {
var str = kbn.toDuration(1.5, 2, 'day');
expect(str).toBe('1 day, 12 hours, 0 minutes');
});
it("decimal months", function() {
var str = kbn.toDuration(1.5, 3, "month");
expect(str).toBe("1 month, 2 weeks, 1 day, 0 hours");
it('decimal months', function() {
var str = kbn.toDuration(1.5, 3, 'month');
expect(str).toBe('1 month, 2 weeks, 1 day, 0 hours');
});
it("no decimals", function() {
var str = kbn.toDuration(38898367008, 0, "millisecond");
expect(str).toBe("1 year");
it('no decimals', function() {
var str = kbn.toDuration(38898367008, 0, 'millisecond');
expect(str).toBe('1 year');
});
it("1 decimal", function() {
var str = kbn.toDuration(38898367008, 1, "millisecond");
expect(str).toBe("1 year, 2 months");
it('1 decimal', function() {
var str = kbn.toDuration(38898367008, 1, 'millisecond');
expect(str).toBe('1 year, 2 months');
});
it("too many decimals", function() {
var str = kbn.toDuration(38898367008, 20, "millisecond");
it('too many decimals', function() {
var str = kbn.toDuration(38898367008, 20, 'millisecond');
expect(str).toBe(
"1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, 7 seconds, 8 milliseconds"
'1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, 7 seconds, 8 milliseconds'
);
});
it("floating point error", function() {
var str = kbn.toDuration(36993906007, 8, "millisecond");
it('floating point error', function() {
var str = kbn.toDuration(36993906007, 8, 'millisecond');
expect(str).toBe(
"1 year, 2 months, 0 weeks, 3 days, 4 hours, 5 minutes, 6 seconds, 7 milliseconds"
'1 year, 2 months, 0 weeks, 3 days, 4 hours, 5 minutes, 6 seconds, 7 milliseconds'
);
});
});
+163 -163
View File
@@ -1,58 +1,58 @@
import { ManageDashboardsCtrl } from "app/core/components/manage_dashboards/manage_dashboards";
import { SearchSrv } from "app/core/services/search_srv";
import q from "q";
import { ManageDashboardsCtrl } from 'app/core/components/manage_dashboards/manage_dashboards';
import { SearchSrv } from 'app/core/services/search_srv';
import q from 'q';
describe("ManageDashboards", () => {
describe('ManageDashboards', () => {
let ctrl;
describe("when browsing dashboards", () => {
describe('when browsing dashboards', () => {
beforeEach(() => {
const response = [
{
id: 410,
title: "afolder",
type: "dash-folder",
title: 'afolder',
type: 'dash-folder',
items: [
{
id: 399,
title: "Dashboard Test",
url: "dashboard/db/dashboard-test",
icon: "fa fa-folder",
title: 'Dashboard Test',
url: 'dashboard/db/dashboard-test',
icon: 'fa fa-folder',
tags: [],
isStarred: false,
folderId: 410,
folderTitle: "afolder",
folderSlug: "afolder"
}
folderTitle: 'afolder',
folderSlug: 'afolder',
},
],
tags: [],
isStarred: false
isStarred: false,
},
{
id: 0,
title: "Root",
icon: "fa fa-folder-open",
uri: "db/something-else",
type: "dash-db",
title: 'Root',
icon: 'fa fa-folder-open',
uri: 'db/something-else',
type: 'dash-db',
items: [
{
id: 500,
title: "Dashboard Test",
url: "dashboard/db/dashboard-test",
icon: "fa fa-folder",
title: 'Dashboard Test',
url: 'dashboard/db/dashboard-test',
icon: 'fa fa-folder',
tags: [],
isStarred: false
}
isStarred: false,
},
],
tags: [],
isStarred: false
}
isStarred: false,
},
];
ctrl = createCtrlWithStubs(response);
return ctrl.getDashboards();
});
it("should set checked to false on all sections and children", () => {
it('should set checked to false on all sections and children', () => {
expect(ctrl.sections.length).toEqual(2);
expect(ctrl.sections[0].checked).toEqual(false);
expect(ctrl.sections[0].items[0].checked).toEqual(false);
@@ -62,41 +62,41 @@ describe("ManageDashboards", () => {
});
});
describe("when browsing dashboards for a folder", () => {
describe('when browsing dashboards for a folder', () => {
beforeEach(() => {
const response = [
{
id: 410,
title: "afolder",
type: "dash-folder",
title: 'afolder',
type: 'dash-folder',
items: [
{
id: 399,
title: "Dashboard Test",
url: "dashboard/db/dashboard-test",
icon: "fa fa-folder",
title: 'Dashboard Test',
url: 'dashboard/db/dashboard-test',
icon: 'fa fa-folder',
tags: [],
isStarred: false,
folderId: 410,
folderTitle: "afolder",
folderSlug: "afolder"
}
folderTitle: 'afolder',
folderSlug: 'afolder',
},
],
tags: [],
isStarred: false
}
isStarred: false,
},
];
ctrl = createCtrlWithStubs(response);
ctrl.folderId = 410;
return ctrl.getDashboards();
});
it("should set hide header to true on section", () => {
it('should set hide header to true on section', () => {
expect(ctrl.sections[0].hideHeader).toBeTruthy();
});
});
describe("when searching dashboards", () => {
describe('when searching dashboards', () => {
beforeEach(() => {
const response = [
{
@@ -106,121 +106,121 @@ describe("ManageDashboards", () => {
items: [
{
id: 399,
title: "Dashboard Test",
url: "dashboard/db/dashboard-test",
icon: "fa fa-folder",
title: 'Dashboard Test',
url: 'dashboard/db/dashboard-test',
icon: 'fa fa-folder',
tags: [],
isStarred: false,
folderId: 410,
folderTitle: "afolder",
folderSlug: "afolder"
folderTitle: 'afolder',
folderSlug: 'afolder',
},
{
id: 500,
title: "Dashboard Test",
url: "dashboard/db/dashboard-test",
icon: "fa fa-folder",
title: 'Dashboard Test',
url: 'dashboard/db/dashboard-test',
icon: 'fa fa-folder',
tags: [],
folderId: 499,
isStarred: false
}
]
}
isStarred: false,
},
],
},
];
ctrl = createCtrlWithStubs(response);
});
describe("with query filter", () => {
describe('with query filter', () => {
beforeEach(() => {
ctrl.query.query = "d";
ctrl.query.query = 'd';
ctrl.canMove = true;
ctrl.canDelete = true;
ctrl.selectAllChecked = true;
return ctrl.getDashboards();
});
it("should set checked to false on all sections and children", () => {
it('should set checked to false on all sections and children', () => {
expect(ctrl.sections.length).toEqual(1);
expect(ctrl.sections[0].checked).toEqual(false);
expect(ctrl.sections[0].items[0].checked).toEqual(false);
expect(ctrl.sections[0].items[1].checked).toEqual(false);
});
it("should uncheck select all", () => {
it('should uncheck select all', () => {
expect(ctrl.selectAllChecked).toBeFalsy();
});
it("should disable Move To button", () => {
it('should disable Move To button', () => {
expect(ctrl.canMove).toBeFalsy();
});
it("should disable delete button", () => {
it('should disable delete button', () => {
expect(ctrl.canDelete).toBeFalsy();
});
it("should have active filters", () => {
it('should have active filters', () => {
expect(ctrl.hasFilters).toBeTruthy();
});
describe("when select all is checked", () => {
describe('when select all is checked', () => {
beforeEach(() => {
ctrl.selectAllChecked = true;
ctrl.onSelectAllChanged();
});
it("should select all dashboards", () => {
it('should select all dashboards', () => {
expect(ctrl.sections[0].checked).toBeFalsy();
expect(ctrl.sections[0].items[0].checked).toBeTruthy();
expect(ctrl.sections[0].items[1].checked).toBeTruthy();
});
it("should enable Move To button", () => {
it('should enable Move To button', () => {
expect(ctrl.canMove).toBeTruthy();
});
it("should enable delete button", () => {
it('should enable delete button', () => {
expect(ctrl.canDelete).toBeTruthy();
});
describe("when clearing filters", () => {
describe('when clearing filters', () => {
beforeEach(() => {
return ctrl.clearFilters();
});
it("should reset query filter", () => {
expect(ctrl.query.query).toEqual("");
it('should reset query filter', () => {
expect(ctrl.query.query).toEqual('');
});
});
});
});
describe("with tag filter", () => {
describe('with tag filter', () => {
beforeEach(() => {
return ctrl.filterByTag("test");
return ctrl.filterByTag('test');
});
it("should set tag filter", () => {
it('should set tag filter', () => {
expect(ctrl.sections.length).toEqual(1);
expect(ctrl.query.tag[0]).toEqual("test");
expect(ctrl.query.tag[0]).toEqual('test');
});
it("should have active filters", () => {
it('should have active filters', () => {
expect(ctrl.hasFilters).toBeTruthy();
});
describe("when clearing filters", () => {
describe('when clearing filters', () => {
beforeEach(() => {
return ctrl.clearFilters();
});
it("should reset tag filter", () => {
it('should reset tag filter', () => {
expect(ctrl.query.tag.length).toEqual(0);
});
});
});
describe("with starred filter", () => {
describe('with starred filter', () => {
beforeEach(() => {
const yesOption: any = ctrl.starredFilterOptions[1];
@@ -228,253 +228,253 @@ describe("ManageDashboards", () => {
return ctrl.onStarredFilterChange();
});
it("should set starred filter", () => {
it('should set starred filter', () => {
expect(ctrl.sections.length).toEqual(1);
expect(ctrl.query.starred).toEqual(true);
});
it("should have active filters", () => {
it('should have active filters', () => {
expect(ctrl.hasFilters).toBeTruthy();
});
describe("when clearing filters", () => {
describe('when clearing filters', () => {
beforeEach(() => {
return ctrl.clearFilters();
});
it("should reset starred filter", () => {
it('should reset starred filter', () => {
expect(ctrl.query.starred).toEqual(false);
});
});
});
});
describe("when selecting dashboards", () => {
describe('when selecting dashboards', () => {
let ctrl;
beforeEach(() => {
ctrl = createCtrlWithStubs([]);
});
describe("and no dashboards are selected", () => {
describe('and no dashboards are selected', () => {
beforeEach(() => {
ctrl.sections = [
{
id: 1,
items: [{ id: 2, checked: false }],
checked: false
checked: false,
},
{
id: 0,
items: [{ id: 3, checked: false }],
checked: false
}
checked: false,
},
];
ctrl.selectionChanged();
});
it("should disable Move To button", () => {
it('should disable Move To button', () => {
expect(ctrl.canMove).toBeFalsy();
});
it("should disable delete button", () => {
it('should disable delete button', () => {
expect(ctrl.canDelete).toBeFalsy();
});
describe("when select all is checked", () => {
describe('when select all is checked', () => {
beforeEach(() => {
ctrl.selectAllChecked = true;
ctrl.onSelectAllChanged();
});
it("should select all folders and dashboards", () => {
it('should select all folders and dashboards', () => {
expect(ctrl.sections[0].checked).toBeTruthy();
expect(ctrl.sections[0].items[0].checked).toBeTruthy();
expect(ctrl.sections[1].checked).toBeTruthy();
expect(ctrl.sections[1].items[0].checked).toBeTruthy();
});
it("should enable Move To button", () => {
it('should enable Move To button', () => {
expect(ctrl.canMove).toBeTruthy();
});
it("should enable delete button", () => {
it('should enable delete button', () => {
expect(ctrl.canDelete).toBeTruthy();
});
});
});
describe("and all folders and dashboards are selected", () => {
describe('and all folders and dashboards are selected', () => {
beforeEach(() => {
ctrl.sections = [
{
id: 1,
items: [{ id: 2, checked: true }],
checked: true
checked: true,
},
{
id: 0,
items: [{ id: 3, checked: true }],
checked: true
}
checked: true,
},
];
ctrl.selectionChanged();
});
it("should enable Move To button", () => {
it('should enable Move To button', () => {
expect(ctrl.canMove).toBeTruthy();
});
it("should enable delete button", () => {
it('should enable delete button', () => {
expect(ctrl.canDelete).toBeTruthy();
});
describe("when select all is unchecked", () => {
describe('when select all is unchecked', () => {
beforeEach(() => {
ctrl.selectAllChecked = false;
ctrl.onSelectAllChanged();
});
it("should uncheck all checked folders and dashboards", () => {
it('should uncheck all checked folders and dashboards', () => {
expect(ctrl.sections[0].checked).toBeFalsy();
expect(ctrl.sections[0].items[0].checked).toBeFalsy();
expect(ctrl.sections[1].checked).toBeFalsy();
expect(ctrl.sections[1].items[0].checked).toBeFalsy();
});
it("should disable Move To button", () => {
it('should disable Move To button', () => {
expect(ctrl.canMove).toBeFalsy();
});
it("should disable delete button", () => {
it('should disable delete button', () => {
expect(ctrl.canDelete).toBeFalsy();
});
});
});
describe("and one dashboard in root is selected", () => {
describe('and one dashboard in root is selected', () => {
beforeEach(() => {
ctrl.sections = [
{
id: 1,
title: "folder",
title: 'folder',
items: [{ id: 2, checked: false }],
checked: false
checked: false,
},
{
id: 0,
title: "Root",
title: 'Root',
items: [{ id: 3, checked: true }],
checked: false
}
checked: false,
},
];
ctrl.selectionChanged();
});
it("should enable Move To button", () => {
it('should enable Move To button', () => {
expect(ctrl.canMove).toBeTruthy();
});
it("should enable delete button", () => {
it('should enable delete button', () => {
expect(ctrl.canDelete).toBeTruthy();
});
});
describe("and one child dashboard is selected", () => {
describe('and one child dashboard is selected', () => {
beforeEach(() => {
ctrl.sections = [
{
id: 1,
title: "folder",
title: 'folder',
items: [{ id: 2, checked: true }],
checked: false
checked: false,
},
{
id: 0,
title: "Root",
title: 'Root',
items: [{ id: 3, checked: false }],
checked: false
}
checked: false,
},
];
ctrl.selectionChanged();
});
it("should enable Move To button", () => {
it('should enable Move To button', () => {
expect(ctrl.canMove).toBeTruthy();
});
it("should enable delete button", () => {
it('should enable delete button', () => {
expect(ctrl.canDelete).toBeTruthy();
});
});
describe("and one child dashboard and one dashboard is selected", () => {
describe('and one child dashboard and one dashboard is selected', () => {
beforeEach(() => {
ctrl.sections = [
{
id: 1,
title: "folder",
title: 'folder',
items: [{ id: 2, checked: true }],
checked: false
checked: false,
},
{
id: 0,
title: "Root",
title: 'Root',
items: [{ id: 3, checked: true }],
checked: false
}
checked: false,
},
];
ctrl.selectionChanged();
});
it("should enable Move To button", () => {
it('should enable Move To button', () => {
expect(ctrl.canMove).toBeTruthy();
});
it("should enable delete button", () => {
it('should enable delete button', () => {
expect(ctrl.canDelete).toBeTruthy();
});
});
describe("and one child dashboard and one folder is selected", () => {
describe('and one child dashboard and one folder is selected', () => {
beforeEach(() => {
ctrl.sections = [
{
id: 1,
title: "folder",
title: 'folder',
items: [{ id: 2, checked: false }],
checked: true
checked: true,
},
{
id: 3,
title: "folder",
title: 'folder',
items: [{ id: 4, checked: true }],
checked: false
checked: false,
},
{
id: 0,
title: "Root",
title: 'Root',
items: [{ id: 3, checked: false }],
checked: false
}
checked: false,
},
];
ctrl.selectionChanged();
});
it("should enable Move To button", () => {
it('should enable Move To button', () => {
expect(ctrl.canMove).toBeTruthy();
});
it("should enable delete button", () => {
it('should enable delete button', () => {
expect(ctrl.canDelete).toBeTruthy();
});
});
});
describe("when deleting dashboards", () => {
describe('when deleting dashboards', () => {
let toBeDeleted: any;
beforeEach(() => {
@@ -483,76 +483,76 @@ describe("ManageDashboards", () => {
ctrl.sections = [
{
id: 1,
title: "folder",
items: [{ id: 2, checked: true, slug: "folder-dash" }],
title: 'folder',
items: [{ id: 2, checked: true, slug: 'folder-dash' }],
checked: true,
slug: "folder"
slug: 'folder',
},
{
id: 3,
title: "folder-2",
items: [{ id: 3, checked: true, slug: "folder-2-dash" }],
title: 'folder-2',
items: [{ id: 3, checked: true, slug: 'folder-2-dash' }],
checked: false,
slug: "folder-2"
slug: 'folder-2',
},
{
id: 0,
title: "Root",
items: [{ id: 3, checked: true, slug: "root-dash" }],
checked: true
}
title: 'Root',
items: [{ id: 3, checked: true, slug: 'root-dash' }],
checked: true,
},
];
toBeDeleted = ctrl.getFoldersAndDashboardsToDelete();
});
it("should return 1 folder", () => {
it('should return 1 folder', () => {
expect(toBeDeleted.folders.length).toEqual(1);
});
it("should return 2 dashboards", () => {
it('should return 2 dashboards', () => {
expect(toBeDeleted.dashboards.length).toEqual(2);
});
it("should filter out children if parent is checked", () => {
expect(toBeDeleted.folders[0]).toEqual("folder");
it('should filter out children if parent is checked', () => {
expect(toBeDeleted.folders[0]).toEqual('folder');
});
it("should not filter out children if parent not is checked", () => {
expect(toBeDeleted.dashboards[0]).toEqual("folder-2-dash");
it('should not filter out children if parent not is checked', () => {
expect(toBeDeleted.dashboards[0]).toEqual('folder-2-dash');
});
it("should not filter out children if parent is checked and root", () => {
expect(toBeDeleted.dashboards[1]).toEqual("root-dash");
it('should not filter out children if parent is checked and root', () => {
expect(toBeDeleted.dashboards[1]).toEqual('root-dash');
});
});
describe("when moving dashboards", () => {
describe('when moving dashboards', () => {
beforeEach(() => {
ctrl = createCtrlWithStubs([]);
ctrl.sections = [
{
id: 1,
title: "folder",
items: [{ id: 2, checked: true, slug: "dash" }],
title: 'folder',
items: [{ id: 2, checked: true, slug: 'dash' }],
checked: false,
slug: "folder"
slug: 'folder',
},
{
id: 0,
title: "Root",
items: [{ id: 3, checked: true, slug: "dash-2" }],
checked: false
}
title: 'Root',
items: [{ id: 3, checked: true, slug: 'dash-2' }],
checked: false,
},
];
});
it("should get selected dashboards", () => {
it('should get selected dashboards', () => {
const toBeMove = ctrl.getDashboardsToMove();
expect(toBeMove.length).toEqual(2);
expect(toBeMove[0]).toEqual("dash");
expect(toBeMove[1]).toEqual("dash-2");
expect(toBeMove[0]).toEqual('dash');
expect(toBeMove[1]).toEqual('dash-2');
});
});
});
@@ -564,7 +564,7 @@ function createCtrlWithStubs(searchResponse: any, tags?: any) {
},
getDashboardTags: () => {
return q.resolve(tags || []);
}
},
};
return new ManageDashboardsCtrl(
+13 -13
View File
@@ -1,14 +1,14 @@
import { OrgSwitchCtrl } from "../components/org_switcher";
import q from "q";
import { OrgSwitchCtrl } from '../components/org_switcher';
import q from 'q';
jest.mock("app/core/services/context_srv", () => ({
jest.mock('app/core/services/context_srv', () => ({
contextSrv: {
user: { orgId: 1 }
}
user: { orgId: 1 },
},
}));
describe("OrgSwitcher", () => {
describe("when switching org", () => {
describe('OrgSwitcher', () => {
describe('when switching org', () => {
let expectedHref;
let expectedUsingUrl;
@@ -20,25 +20,25 @@ describe("OrgSwitcher", () => {
post: url => {
expectedUsingUrl = url;
return q.resolve({});
}
},
};
const orgSwitcherCtrl = new OrgSwitchCtrl(backendSrvStub);
orgSwitcherCtrl.getWindowLocationHref = () =>
"http://localhost:3000?orgId=1&from=now-3h&to=now";
'http://localhost:3000?orgId=1&from=now-3h&to=now';
orgSwitcherCtrl.setWindowLocationHref = href => (expectedHref = href);
return orgSwitcherCtrl.setUsingOrg({ orgId: 2 });
});
it("should switch orgId in call to backend", () => {
expect(expectedUsingUrl).toBe("/api/user/using/2");
it('should switch orgId in call to backend', () => {
expect(expectedUsingUrl).toBe('/api/user/using/2');
});
it("should switch orgId in url", () => {
it('should switch orgId in url', () => {
expect(expectedHref).toBe(
"http://localhost:3000?orgId=2&from=now-3h&to=now"
'http://localhost:3000?orgId=2&from=now-3h&to=now'
);
});
});
+65 -65
View File
@@ -1,120 +1,120 @@
import * as rangeUtil from "app/core/utils/rangeutil";
import _ from "lodash";
import moment from "moment";
import * as rangeUtil from 'app/core/utils/rangeutil';
import _ from 'lodash';
import moment from 'moment';
describe("rangeUtil", () => {
describe("Can get range grouped list of ranges", () => {
it("when custom settings should return default range list", () => {
describe('rangeUtil', () => {
describe('Can get range grouped list of ranges', () => {
it('when custom settings should return default range list', () => {
var groups = rangeUtil.getRelativeTimesList(
{ time_options: [] },
"Last 5 minutes"
'Last 5 minutes'
);
expect(_.keys(groups).length).toBe(4);
expect(groups[3][0].active).toBe(true);
});
});
describe("Can get range text described", () => {
it("should handle simple old expression with only amount and unit", () => {
var info = rangeUtil.describeTextRange("5m");
expect(info.display).toBe("Last 5 minutes");
describe('Can get range text described', () => {
it('should handle simple old expression with only amount and unit', () => {
var info = rangeUtil.describeTextRange('5m');
expect(info.display).toBe('Last 5 minutes');
});
it("should have singular when amount is 1", () => {
var info = rangeUtil.describeTextRange("1h");
expect(info.display).toBe("Last 1 hour");
it('should have singular when amount is 1', () => {
var info = rangeUtil.describeTextRange('1h');
expect(info.display).toBe('Last 1 hour');
});
it("should handle non default amount", () => {
var info = rangeUtil.describeTextRange("13h");
expect(info.display).toBe("Last 13 hours");
expect(info.from).toBe("now-13h");
it('should handle non default amount', () => {
var info = rangeUtil.describeTextRange('13h');
expect(info.display).toBe('Last 13 hours');
expect(info.from).toBe('now-13h');
});
it("should handle non default future amount", () => {
var info = rangeUtil.describeTextRange("+3h");
expect(info.display).toBe("Next 3 hours");
expect(info.from).toBe("now");
expect(info.to).toBe("now+3h");
it('should handle non default future amount', () => {
var info = rangeUtil.describeTextRange('+3h');
expect(info.display).toBe('Next 3 hours');
expect(info.from).toBe('now');
expect(info.to).toBe('now+3h');
});
it("should handle now/d", () => {
var info = rangeUtil.describeTextRange("now/d");
expect(info.display).toBe("Today so far");
it('should handle now/d', () => {
var info = rangeUtil.describeTextRange('now/d');
expect(info.display).toBe('Today so far');
});
it("should handle now/w", () => {
var info = rangeUtil.describeTextRange("now/w");
expect(info.display).toBe("This week so far");
it('should handle now/w', () => {
var info = rangeUtil.describeTextRange('now/w');
expect(info.display).toBe('This week so far');
});
it("should handle now/M", () => {
var info = rangeUtil.describeTextRange("now/M");
expect(info.display).toBe("This month so far");
it('should handle now/M', () => {
var info = rangeUtil.describeTextRange('now/M');
expect(info.display).toBe('This month so far');
});
it("should handle now/y", () => {
var info = rangeUtil.describeTextRange("now/y");
expect(info.display).toBe("This year so far");
it('should handle now/y', () => {
var info = rangeUtil.describeTextRange('now/y');
expect(info.display).toBe('This year so far');
});
});
describe("Can get date range described", () => {
it("Date range with simple ranges", () => {
var text = rangeUtil.describeTimeRange({ from: "now-1h", to: "now" });
expect(text).toBe("Last 1 hour");
describe('Can get date range described', () => {
it('Date range with simple ranges', () => {
var text = rangeUtil.describeTimeRange({ from: 'now-1h', to: 'now' });
expect(text).toBe('Last 1 hour');
});
it("Date range with rounding ranges", () => {
var text = rangeUtil.describeTimeRange({ from: "now/d+6h", to: "now" });
expect(text).toBe("now/d+6h to now");
it('Date range with rounding ranges', () => {
var text = rangeUtil.describeTimeRange({ from: 'now/d+6h', to: 'now' });
expect(text).toBe('now/d+6h to now');
});
it("Date range with absolute to now", () => {
it('Date range with absolute to now', () => {
var text = rangeUtil.describeTimeRange({
from: moment([2014, 10, 10, 2, 3, 4]),
to: "now"
to: 'now',
});
expect(text).toBe("Nov 10, 2014 02:03:04 to a few seconds ago");
expect(text).toBe('Nov 10, 2014 02:03:04 to a few seconds ago');
});
it("Date range with absolute to relative", () => {
it('Date range with absolute to relative', () => {
var text = rangeUtil.describeTimeRange({
from: moment([2014, 10, 10, 2, 3, 4]),
to: "now-1d"
to: 'now-1d',
});
expect(text).toBe("Nov 10, 2014 02:03:04 to a day ago");
expect(text).toBe('Nov 10, 2014 02:03:04 to a day ago');
});
it("Date range with relative to absolute", () => {
it('Date range with relative to absolute', () => {
var text = rangeUtil.describeTimeRange({
from: "now-7d",
to: moment([2014, 10, 10, 2, 3, 4])
from: 'now-7d',
to: moment([2014, 10, 10, 2, 3, 4]),
});
expect(text).toBe("7 days ago to Nov 10, 2014 02:03:04");
expect(text).toBe('7 days ago to Nov 10, 2014 02:03:04');
});
it("Date range with non matching default ranges", () => {
var text = rangeUtil.describeTimeRange({ from: "now-13h", to: "now" });
expect(text).toBe("Last 13 hours");
it('Date range with non matching default ranges', () => {
var text = rangeUtil.describeTimeRange({ from: 'now-13h', to: 'now' });
expect(text).toBe('Last 13 hours');
});
it("Date range with from and to both are in now-* format", () => {
var text = rangeUtil.describeTimeRange({ from: "now-6h", to: "now-3h" });
expect(text).toBe("now-6h to now-3h");
it('Date range with from and to both are in now-* format', () => {
var text = rangeUtil.describeTimeRange({ from: 'now-6h', to: 'now-3h' });
expect(text).toBe('now-6h to now-3h');
});
it("Date range with from and to both are either in now-* or now/* format", () => {
it('Date range with from and to both are either in now-* or now/* format', () => {
var text = rangeUtil.describeTimeRange({
from: "now/d+6h",
to: "now-3h"
from: 'now/d+6h',
to: 'now-3h',
});
expect(text).toBe("now/d+6h to now-3h");
expect(text).toBe('now/d+6h to now-3h');
});
it("Date range with from and to both are either in now-* or now+* format", () => {
var text = rangeUtil.describeTimeRange({ from: "now-6h", to: "now+1h" });
expect(text).toBe("now-6h to now+1h");
it('Date range with from and to both are either in now-* or now+* format', () => {
var text = rangeUtil.describeTimeRange({ from: 'now-6h', to: 'now+1h' });
expect(text).toBe('now-6h to now+1h');
});
});
});
+54 -54
View File
@@ -1,10 +1,10 @@
import { SearchCtrl } from "../components/search/search";
import { SearchSrv } from "../services/search_srv";
import { SearchCtrl } from '../components/search/search';
import { SearchSrv } from '../services/search_srv';
describe("SearchCtrl", () => {
describe('SearchCtrl', () => {
const searchSrvStub = {
search: (options: any) => {},
getDashboardTags: () => {}
getDashboardTags: () => {},
};
let ctrl = new SearchCtrl(
{ $on: () => {} },
@@ -13,63 +13,63 @@ describe("SearchCtrl", () => {
<SearchSrv>searchSrvStub
);
describe("Given an empty result", () => {
describe('Given an empty result', () => {
beforeEach(() => {
ctrl.results = [];
});
describe("When navigating down one step", () => {
describe('When navigating down one step', () => {
beforeEach(() => {
ctrl.selectedIndex = 0;
ctrl.moveSelection(1);
});
it("should not navigate", () => {
it('should not navigate', () => {
expect(ctrl.selectedIndex).toBe(0);
});
});
describe("When navigating up one step", () => {
describe('When navigating up one step', () => {
beforeEach(() => {
ctrl.selectedIndex = 0;
ctrl.moveSelection(-1);
});
it("should not navigate", () => {
it('should not navigate', () => {
expect(ctrl.selectedIndex).toBe(0);
});
});
});
describe("Given a result of one selected collapsed folder with no dashboards and a root folder with 2 dashboards", () => {
describe('Given a result of one selected collapsed folder with no dashboards and a root folder with 2 dashboards', () => {
beforeEach(() => {
ctrl.results = [
{
id: 1,
title: "folder",
title: 'folder',
items: [],
selected: true,
expanded: false,
toggle: i => (i.expanded = !i.expanded)
toggle: i => (i.expanded = !i.expanded),
},
{
id: 0,
title: "Root",
title: 'Root',
items: [{ id: 3, selected: false }, { id: 5, selected: false }],
selected: false,
expanded: true,
toggle: i => (i.expanded = !i.expanded)
}
toggle: i => (i.expanded = !i.expanded),
},
];
});
describe("When navigating down one step", () => {
describe('When navigating down one step', () => {
beforeEach(() => {
ctrl.selectedIndex = 0;
ctrl.moveSelection(1);
});
it("should select first dashboard in root folder", () => {
it('should select first dashboard in root folder', () => {
expect(ctrl.results[0].selected).toBeFalsy();
expect(ctrl.results[1].selected).toBeFalsy();
expect(ctrl.results[1].items[0].selected).toBeTruthy();
@@ -77,14 +77,14 @@ describe("SearchCtrl", () => {
});
});
describe("When navigating down two steps", () => {
describe('When navigating down two steps', () => {
beforeEach(() => {
ctrl.selectedIndex = 0;
ctrl.moveSelection(1);
ctrl.moveSelection(1);
});
it("should select last dashboard in root folder", () => {
it('should select last dashboard in root folder', () => {
expect(ctrl.results[0].selected).toBeFalsy();
expect(ctrl.results[1].selected).toBeFalsy();
expect(ctrl.results[1].items[0].selected).toBeFalsy();
@@ -92,7 +92,7 @@ describe("SearchCtrl", () => {
});
});
describe("When navigating down three steps", () => {
describe('When navigating down three steps', () => {
beforeEach(() => {
ctrl.selectedIndex = 0;
ctrl.moveSelection(1);
@@ -100,7 +100,7 @@ describe("SearchCtrl", () => {
ctrl.moveSelection(1);
});
it("should select first folder", () => {
it('should select first folder', () => {
expect(ctrl.results[0].selected).toBeTruthy();
expect(ctrl.results[1].selected).toBeFalsy();
expect(ctrl.results[1].items[0].selected).toBeFalsy();
@@ -108,13 +108,13 @@ describe("SearchCtrl", () => {
});
});
describe("When navigating up one step", () => {
describe('When navigating up one step', () => {
beforeEach(() => {
ctrl.selectedIndex = 0;
ctrl.moveSelection(-1);
});
it("should select last dashboard in root folder", () => {
it('should select last dashboard in root folder', () => {
expect(ctrl.results[0].selected).toBeFalsy();
expect(ctrl.results[1].selected).toBeFalsy();
expect(ctrl.results[1].items[0].selected).toBeFalsy();
@@ -122,14 +122,14 @@ describe("SearchCtrl", () => {
});
});
describe("When navigating up two steps", () => {
describe('When navigating up two steps', () => {
beforeEach(() => {
ctrl.selectedIndex = 0;
ctrl.moveSelection(-1);
ctrl.moveSelection(-1);
});
it("should select first dashboard in root folder", () => {
it('should select first dashboard in root folder', () => {
expect(ctrl.results[0].selected).toBeFalsy();
expect(ctrl.results[1].selected).toBeFalsy();
expect(ctrl.results[1].items[0].selected).toBeTruthy();
@@ -138,35 +138,35 @@ describe("SearchCtrl", () => {
});
});
describe("Given a result of one selected collapsed folder with 2 dashboards and a root folder with 2 dashboards", () => {
describe('Given a result of one selected collapsed folder with 2 dashboards and a root folder with 2 dashboards', () => {
beforeEach(() => {
ctrl.results = [
{
id: 1,
title: "folder",
title: 'folder',
items: [{ id: 2, selected: false }, { id: 4, selected: false }],
selected: true,
expanded: false,
toggle: i => (i.expanded = !i.expanded)
toggle: i => (i.expanded = !i.expanded),
},
{
id: 0,
title: "Root",
title: 'Root',
items: [{ id: 3, selected: false }, { id: 5, selected: false }],
selected: false,
expanded: true,
toggle: i => (i.expanded = !i.expanded)
}
toggle: i => (i.expanded = !i.expanded),
},
];
});
describe("When navigating down one step", () => {
describe('When navigating down one step', () => {
beforeEach(() => {
ctrl.selectedIndex = 0;
ctrl.moveSelection(1);
});
it("should select first dashboard in root folder", () => {
it('should select first dashboard in root folder', () => {
expect(ctrl.results[0].selected).toBeFalsy();
expect(ctrl.results[1].selected).toBeFalsy();
expect(ctrl.results[0].items[0].selected).toBeFalsy();
@@ -176,14 +176,14 @@ describe("SearchCtrl", () => {
});
});
describe("When navigating down two steps", () => {
describe('When navigating down two steps', () => {
beforeEach(() => {
ctrl.selectedIndex = 0;
ctrl.moveSelection(1);
ctrl.moveSelection(1);
});
it("should select last dashboard in root folder", () => {
it('should select last dashboard in root folder', () => {
expect(ctrl.results[0].selected).toBeFalsy();
expect(ctrl.results[1].selected).toBeFalsy();
expect(ctrl.results[0].items[0].selected).toBeFalsy();
@@ -193,7 +193,7 @@ describe("SearchCtrl", () => {
});
});
describe("When navigating down three steps", () => {
describe('When navigating down three steps', () => {
beforeEach(() => {
ctrl.selectedIndex = 0;
ctrl.moveSelection(1);
@@ -201,7 +201,7 @@ describe("SearchCtrl", () => {
ctrl.moveSelection(1);
});
it("should select first folder", () => {
it('should select first folder', () => {
expect(ctrl.results[0].selected).toBeTruthy();
expect(ctrl.results[1].selected).toBeFalsy();
expect(ctrl.results[0].items[0].selected).toBeFalsy();
@@ -211,13 +211,13 @@ describe("SearchCtrl", () => {
});
});
describe("When navigating up one step", () => {
describe('When navigating up one step', () => {
beforeEach(() => {
ctrl.selectedIndex = 0;
ctrl.moveSelection(-1);
});
it("should select last dashboard in root folder", () => {
it('should select last dashboard in root folder', () => {
expect(ctrl.results[0].selected).toBeFalsy();
expect(ctrl.results[1].selected).toBeFalsy();
expect(ctrl.results[0].items[0].selected).toBeFalsy();
@@ -227,14 +227,14 @@ describe("SearchCtrl", () => {
});
});
describe("When navigating up two steps", () => {
describe('When navigating up two steps', () => {
beforeEach(() => {
ctrl.selectedIndex = 0;
ctrl.moveSelection(-1);
ctrl.moveSelection(-1);
});
it("should select first dashboard in root folder", () => {
it('should select first dashboard in root folder', () => {
expect(ctrl.results[0].selected).toBeFalsy();
expect(ctrl.results[1].selected).toBeFalsy();
expect(ctrl.results[1].items[0].selected).toBeTruthy();
@@ -243,7 +243,7 @@ describe("SearchCtrl", () => {
});
});
describe("Given a result of a search with 2 dashboards where the first is selected", () => {
describe('Given a result of a search with 2 dashboards where the first is selected', () => {
beforeEach(() => {
ctrl.results = [
{
@@ -251,39 +251,39 @@ describe("SearchCtrl", () => {
items: [{ id: 3, selected: true }, { id: 5, selected: false }],
selected: false,
expanded: true,
toggle: i => (i.expanded = !i.expanded)
}
toggle: i => (i.expanded = !i.expanded),
},
];
});
describe("When navigating down one step", () => {
describe('When navigating down one step', () => {
beforeEach(() => {
ctrl.selectedIndex = 1;
ctrl.moveSelection(1);
});
it("should select last dashboard", () => {
it('should select last dashboard', () => {
expect(ctrl.results[0].selected).toBeFalsy();
expect(ctrl.results[0].items[0].selected).toBeFalsy();
expect(ctrl.results[0].items[1].selected).toBeTruthy();
});
});
describe("When navigating down two steps", () => {
describe('When navigating down two steps', () => {
beforeEach(() => {
ctrl.selectedIndex = 1;
ctrl.moveSelection(1);
ctrl.moveSelection(1);
});
it("should select first dashboard", () => {
it('should select first dashboard', () => {
expect(ctrl.results[0].selected).toBeFalsy();
expect(ctrl.results[0].items[0].selected).toBeTruthy();
expect(ctrl.results[0].items[1].selected).toBeFalsy();
});
});
describe("When navigating down three steps", () => {
describe('When navigating down three steps', () => {
beforeEach(() => {
ctrl.selectedIndex = 1;
ctrl.moveSelection(1);
@@ -291,34 +291,34 @@ describe("SearchCtrl", () => {
ctrl.moveSelection(1);
});
it("should select last dashboard", () => {
it('should select last dashboard', () => {
expect(ctrl.results[0].selected).toBeFalsy();
expect(ctrl.results[0].items[0].selected).toBeFalsy();
expect(ctrl.results[0].items[1].selected).toBeTruthy();
});
});
describe("When navigating up one step", () => {
describe('When navigating up one step', () => {
beforeEach(() => {
ctrl.selectedIndex = 1;
ctrl.moveSelection(-1);
});
it("should select last dashboard", () => {
it('should select last dashboard', () => {
expect(ctrl.results[0].selected).toBeFalsy();
expect(ctrl.results[0].items[0].selected).toBeFalsy();
expect(ctrl.results[0].items[1].selected).toBeTruthy();
});
});
describe("When navigating up two steps", () => {
describe('When navigating up two steps', () => {
beforeEach(() => {
ctrl.selectedIndex = 1;
ctrl.moveSelection(-1);
ctrl.moveSelection(-1);
});
it("should select first dashboard", () => {
it('should select first dashboard', () => {
expect(ctrl.results[0].selected).toBeFalsy();
expect(ctrl.results[0].items[0].selected).toBeTruthy();
expect(ctrl.results[0].items[1].selected).toBeFalsy();
+30 -30
View File
@@ -1,17 +1,17 @@
import { SearchResultsCtrl } from "../components/search/search_results";
import { beforeEach, afterEach } from "test/lib/common";
import appEvents from "app/core/app_events";
import { SearchResultsCtrl } from '../components/search/search_results';
import { beforeEach, afterEach } from 'test/lib/common';
import appEvents from 'app/core/app_events';
jest.mock("app/core/app_events", () => {
jest.mock('app/core/app_events', () => {
return {
emit: jest.fn<any>()
emit: jest.fn<any>(),
};
});
describe("SearchResultsCtrl", () => {
describe('SearchResultsCtrl', () => {
let ctrl;
describe("when checking an item that is not checked", () => {
describe('when checking an item that is not checked', () => {
let item = { checked: false };
let selectionChanged = false;
@@ -21,16 +21,16 @@ describe("SearchResultsCtrl", () => {
ctrl.toggleSelection(item);
});
it("should set checked to true", () => {
it('should set checked to true', () => {
expect(item.checked).toBeTruthy();
});
it("should trigger selection changed callback", () => {
it('should trigger selection changed callback', () => {
expect(selectionChanged).toBeTruthy();
});
});
describe("when checking an item that is checked", () => {
describe('when checking an item that is checked', () => {
let item = { checked: true };
let selectionChanged = false;
@@ -40,30 +40,30 @@ describe("SearchResultsCtrl", () => {
ctrl.toggleSelection(item);
});
it("should set checked to false", () => {
it('should set checked to false', () => {
expect(item.checked).toBeFalsy();
});
it("should trigger selection changed callback", () => {
it('should trigger selection changed callback', () => {
expect(selectionChanged).toBeTruthy();
});
});
describe("when selecting a tag", () => {
describe('when selecting a tag', () => {
let selectedTag = null;
beforeEach(() => {
ctrl = new SearchResultsCtrl({});
ctrl.onTagSelected = tag => (selectedTag = tag);
ctrl.selectTag("tag-test");
ctrl.selectTag('tag-test');
});
it("should trigger tag selected callback", () => {
expect(selectedTag["$tag"]).toBe("tag-test");
it('should trigger tag selected callback', () => {
expect(selectedTag['$tag']).toBe('tag-test');
});
});
describe("when toggle a collapsed folder", () => {
describe('when toggle a collapsed folder', () => {
let folderExpanded = false;
beforeEach(() => {
@@ -74,18 +74,18 @@ describe("SearchResultsCtrl", () => {
let folder = {
expanded: false,
toggle: () => Promise.resolve(folder)
toggle: () => Promise.resolve(folder),
};
ctrl.toggleFolderExpand(folder);
});
it("should trigger folder expanding callback", () => {
it('should trigger folder expanding callback', () => {
expect(folderExpanded).toBeTruthy();
});
});
describe("when toggle an expanded folder", () => {
describe('when toggle an expanded folder', () => {
let folderExpanded = false;
beforeEach(() => {
@@ -96,43 +96,43 @@ describe("SearchResultsCtrl", () => {
let folder = {
expanded: true,
toggle: () => Promise.resolve(folder)
toggle: () => Promise.resolve(folder),
};
ctrl.toggleFolderExpand(folder);
});
it("should not trigger folder expanding callback", () => {
it('should not trigger folder expanding callback', () => {
expect(folderExpanded).toBeFalsy();
});
});
describe("when clicking on a link in search result", () => {
const dashPath = "dashboard/path";
describe('when clicking on a link in search result', () => {
const dashPath = 'dashboard/path';
const $location = { path: () => dashPath };
const appEventsMock = appEvents as any;
describe("with the same url as current path", () => {
describe('with the same url as current path', () => {
beforeEach(() => {
ctrl = new SearchResultsCtrl($location);
const item = { url: dashPath };
ctrl.onItemClick(item);
});
it("should close the search", () => {
it('should close the search', () => {
expect(appEventsMock.emit.mock.calls.length).toBe(1);
expect(appEventsMock.emit.mock.calls[0][0]).toBe("hide-dash-search");
expect(appEventsMock.emit.mock.calls[0][0]).toBe('hide-dash-search');
});
});
describe("with a different url than current path", () => {
describe('with a different url than current path', () => {
beforeEach(() => {
ctrl = new SearchResultsCtrl($location);
const item = { url: "another/path" };
const item = { url: 'another/path' };
ctrl.onItemClick(item);
});
it("should do nothing", () => {
it('should do nothing', () => {
expect(appEventsMock.emit.mock.calls.length).toBe(0);
});
});
+76 -76
View File
@@ -1,23 +1,23 @@
import { SearchSrv } from "app/core/services/search_srv";
import { BackendSrvMock } from "test/mocks/backend_srv";
import impressionSrv from "app/core/services/impression_srv";
import { contextSrv } from "app/core/services/context_srv";
import { beforeEach } from "test/lib/common";
import { SearchSrv } from 'app/core/services/search_srv';
import { BackendSrvMock } from 'test/mocks/backend_srv';
import impressionSrv from 'app/core/services/impression_srv';
import { contextSrv } from 'app/core/services/context_srv';
import { beforeEach } from 'test/lib/common';
jest.mock("app/core/store", () => {
jest.mock('app/core/store', () => {
return {
getBool: jest.fn(),
set: jest.fn()
set: jest.fn(),
};
});
jest.mock("app/core/services/impression_srv", () => {
jest.mock('app/core/services/impression_srv', () => {
return {
getDashboardOpened: jest.fn
getDashboardOpened: jest.fn,
};
});
describe("SearchSrv", () => {
describe('SearchSrv', () => {
let searchSrv, backendSrvMock;
beforeEach(() => {
@@ -28,7 +28,7 @@ describe("SearchSrv", () => {
impressionSrv.getDashboardOpened = jest.fn().mockReturnValue([]);
});
describe("With recent dashboards", () => {
describe('With recent dashboards', () => {
let results;
beforeEach(() => {
@@ -36,36 +36,36 @@ describe("SearchSrv", () => {
.fn()
.mockReturnValueOnce(
Promise.resolve([
{ id: 2, title: "second but first" },
{ id: 1, title: "first but second" }
{ id: 2, title: 'second but first' },
{ id: 1, title: 'first but second' },
])
)
.mockReturnValue(Promise.resolve([]));
impressionSrv.getDashboardOpened = jest.fn().mockReturnValue([1, 2]);
return searchSrv.search({ query: "" }).then(res => {
return searchSrv.search({ query: '' }).then(res => {
results = res;
});
});
it("should include recent dashboards section", () => {
expect(results[0].title).toBe("Recent Boards");
it('should include recent dashboards section', () => {
expect(results[0].title).toBe('Recent Boards');
});
it("should return order decided by impressions store not api", () => {
expect(results[0].items[0].title).toBe("first but second");
expect(results[0].items[1].title).toBe("second but first");
it('should return order decided by impressions store not api', () => {
expect(results[0].items[0].title).toBe('first but second');
expect(results[0].items[1].title).toBe('second but first');
});
describe("and 3 recent dashboards removed in backend", () => {
describe('and 3 recent dashboards removed in backend', () => {
let results;
beforeEach(() => {
backendSrvMock.search = jest
.fn()
.mockReturnValueOnce(
Promise.resolve([{ id: 2, title: "two" }, { id: 1, title: "one" }])
Promise.resolve([{ id: 2, title: 'two' }, { id: 1, title: 'one' }])
)
.mockReturnValue(Promise.resolve([]));
@@ -73,12 +73,12 @@ describe("SearchSrv", () => {
.fn()
.mockReturnValue([4, 5, 1, 2, 3]);
return searchSrv.search({ query: "" }).then(res => {
return searchSrv.search({ query: '' }).then(res => {
results = res;
});
});
it("should return 2 dashboards", () => {
it('should return 2 dashboards', () => {
expect(results[0].items.length).toBe(2);
expect(results[0].items[0].id).toBe(1);
expect(results[0].items[1].id).toBe(2);
@@ -86,26 +86,26 @@ describe("SearchSrv", () => {
});
});
describe("With starred dashboards", () => {
describe('With starred dashboards', () => {
let results;
beforeEach(() => {
backendSrvMock.search = jest
.fn()
.mockReturnValue(Promise.resolve([{ id: 1, title: "starred" }]));
.mockReturnValue(Promise.resolve([{ id: 1, title: 'starred' }]));
return searchSrv.search({ query: "" }).then(res => {
return searchSrv.search({ query: '' }).then(res => {
results = res;
});
});
it("should include starred dashboards section", () => {
expect(results[0].title).toBe("Starred");
it('should include starred dashboards section', () => {
expect(results[0].title).toBe('Starred');
expect(results[0].items.length).toBe(1);
});
});
describe("With starred dashboards and recent", () => {
describe('With starred dashboards and recent', () => {
let results;
beforeEach(() => {
@@ -113,32 +113,32 @@ describe("SearchSrv", () => {
.fn()
.mockReturnValueOnce(
Promise.resolve([
{ id: 1, title: "starred and recent", isStarred: true },
{ id: 2, title: "recent" }
{ id: 1, title: 'starred and recent', isStarred: true },
{ id: 2, title: 'recent' },
])
)
.mockReturnValue(
Promise.resolve([{ id: 1, title: "starred and recent" }])
Promise.resolve([{ id: 1, title: 'starred and recent' }])
);
impressionSrv.getDashboardOpened = jest.fn().mockReturnValue([1, 2]);
return searchSrv.search({ query: "" }).then(res => {
return searchSrv.search({ query: '' }).then(res => {
results = res;
});
});
it("should not show starred in recent", () => {
expect(results[1].title).toBe("Recent");
expect(results[1].items[0].title).toBe("recent");
it('should not show starred in recent', () => {
expect(results[1].title).toBe('Recent');
expect(results[1].items[0].title).toBe('recent');
});
it("should show starred", () => {
expect(results[0].title).toBe("Starred Boards");
expect(results[0].items[0].title).toBe("starred and recent");
it('should show starred', () => {
expect(results[0].title).toBe('Starred Boards');
expect(results[0].items[0].title).toBe('starred and recent');
});
});
describe("with no query string and dashboards with folders returned", () => {
describe('with no query string and dashboards with folders returned', () => {
let results;
beforeEach(() => {
@@ -148,45 +148,45 @@ describe("SearchSrv", () => {
.mockReturnValue(
Promise.resolve([
{
title: "folder1",
type: "dash-folder",
id: 1
title: 'folder1',
type: 'dash-folder',
id: 1,
},
{
title: "dash with no folder",
type: "dash-db",
id: 2
title: 'dash with no folder',
type: 'dash-db',
id: 2,
},
{
title: "dash in folder1 1",
type: "dash-db",
title: 'dash in folder1 1',
type: 'dash-db',
id: 3,
folderId: 1
folderId: 1,
},
{
title: "dash in folder1 2",
type: "dash-db",
title: 'dash in folder1 2',
type: 'dash-db',
id: 4,
folderId: 1
}
folderId: 1,
},
])
);
return searchSrv.search({ query: "" }).then(res => {
return searchSrv.search({ query: '' }).then(res => {
results = res;
});
});
it("should create sections for each folder and root", () => {
it('should create sections for each folder and root', () => {
expect(results).toHaveLength(2);
});
it("should place folders first", () => {
expect(results[0].title).toBe("folder1");
it('should place folders first', () => {
expect(results[0].title).toBe('folder1');
});
});
describe("with query string and dashboards with folders returned", () => {
describe('with query string and dashboards with folders returned', () => {
let results;
beforeEach(() => {
@@ -196,47 +196,47 @@ describe("SearchSrv", () => {
Promise.resolve([
{
id: 2,
title: "dash with no folder",
type: "dash-db"
title: 'dash with no folder',
type: 'dash-db',
},
{
id: 3,
title: "dash in folder1 1",
type: "dash-db",
title: 'dash in folder1 1',
type: 'dash-db',
folderId: 1,
folderTitle: "folder1"
}
folderTitle: 'folder1',
},
])
);
return searchSrv.search({ query: "search" }).then(res => {
return searchSrv.search({ query: 'search' }).then(res => {
results = res;
});
});
it("should not specify folder ids", () => {
it('should not specify folder ids', () => {
expect(backendSrvMock.search.mock.calls[0][0].folderIds).toHaveLength(0);
});
it("should group results by folder", () => {
it('should group results by folder', () => {
expect(results).toHaveLength(2);
});
});
describe("with tags", () => {
describe('with tags', () => {
beforeEach(() => {
backendSrvMock.search = jest.fn();
backendSrvMock.search.mockReturnValue(Promise.resolve([]));
return searchSrv.search({ tag: ["atag"] }).then(() => {});
return searchSrv.search({ tag: ['atag'] }).then(() => {});
});
it("should send tags query to backend search", () => {
it('should send tags query to backend search', () => {
expect(backendSrvMock.search.mock.calls[0][0].tag).toHaveLength(1);
});
});
describe("with starred", () => {
describe('with starred', () => {
beforeEach(() => {
backendSrvMock.search = jest.fn();
backendSrvMock.search.mockReturnValue(Promise.resolve([]));
@@ -244,12 +244,12 @@ describe("SearchSrv", () => {
return searchSrv.search({ starred: true }).then(() => {});
});
it("should send starred query to backend search", () => {
it('should send starred query to backend search', () => {
expect(backendSrvMock.search.mock.calls[0][0].starred).toEqual(true);
});
});
describe("when skipping recent dashboards", () => {
describe('when skipping recent dashboards', () => {
let getRecentDashboardsCalled = false;
beforeEach(() => {
@@ -263,12 +263,12 @@ describe("SearchSrv", () => {
return searchSrv.search({ skipRecent: true }).then(() => {});
});
it("should not fetch recent dashboards", () => {
it('should not fetch recent dashboards', () => {
expect(getRecentDashboardsCalled).toBeFalsy();
});
});
describe("when skipping starred dashboards", () => {
describe('when skipping starred dashboards', () => {
let getStarredCalled = false;
beforeEach(() => {
@@ -283,7 +283,7 @@ describe("SearchSrv", () => {
return searchSrv.search({ skipStarred: true }).then(() => {});
});
it("should not fetch starred dashboards", () => {
it('should not fetch starred dashboards', () => {
expect(getStarredCalled).toBeFalsy();
});
});
+21 -21
View File
@@ -1,40 +1,40 @@
import store from "../store";
import store from '../store';
Object.assign(window, {
localStorage: {
removeItem(key) {
delete window.localStorage[key];
}
}
},
},
});
describe("store", () => {
it("should store", () => {
store.set("key1", "123");
expect(store.get("key1")).toBe("123");
describe('store', () => {
it('should store', () => {
store.set('key1', '123');
expect(store.get('key1')).toBe('123');
});
it("get key when undefined", () => {
expect(store.get("key2")).toBe(undefined);
it('get key when undefined', () => {
expect(store.get('key2')).toBe(undefined);
});
it("check if key exixts", () => {
store.set("key3", "123");
expect(store.exists("key3")).toBe(true);
it('check if key exixts', () => {
store.set('key3', '123');
expect(store.exists('key3')).toBe(true);
});
it("get boolean when no key", () => {
expect(store.getBool("key4", false)).toBe(false);
it('get boolean when no key', () => {
expect(store.getBool('key4', false)).toBe(false);
});
it("get boolean", () => {
store.set("key5", "true");
expect(store.getBool("key5", false)).toBe(true);
it('get boolean', () => {
store.set('key5', 'true');
expect(store.getBool('key5', false)).toBe(true);
});
it("key should be deleted", () => {
store.set("key6", "123");
store.delete("key6");
expect(store.exists("key6")).toBe(false);
it('key should be deleted', () => {
store.set('key6', '123');
store.delete('key6');
expect(store.exists('key6')).toBe(false);
});
});
+8 -8
View File
@@ -1,9 +1,9 @@
import TableModel from "app/core/table_model";
import TableModel from 'app/core/table_model';
describe("when sorting table desc", () => {
describe('when sorting table desc', () => {
var table;
var panel = {
sort: { col: 0, desc: true }
sort: { col: 0, desc: true },
};
beforeEach(() => {
@@ -13,22 +13,22 @@ describe("when sorting table desc", () => {
table.sort(panel.sort);
});
it("should sort by time", () => {
it('should sort by time', () => {
expect(table.rows[0][0]).toBe(105);
expect(table.rows[1][0]).toBe(103);
expect(table.rows[2][0]).toBe(100);
});
it("should mark column being sorted", () => {
it('should mark column being sorted', () => {
expect(table.columns[0].sort).toBe(true);
expect(table.columns[0].desc).toBe(true);
});
});
describe("when sorting table asc", () => {
describe('when sorting table asc', () => {
var table;
var panel = {
sort: { col: 1, desc: false }
sort: { col: 1, desc: false },
};
beforeEach(() => {
@@ -38,7 +38,7 @@ describe("when sorting table asc", () => {
table.sort(panel.sort);
});
it("should sort by time", () => {
it('should sort by time', () => {
expect(table.rows[0][1]).toBe(10);
expect(table.rows[1][1]).toBe(11);
expect(table.rows[2][1]).toBe(15);
+99 -99
View File
@@ -1,308 +1,308 @@
import TimeSeries from "app/core/time_series2";
import TimeSeries from 'app/core/time_series2';
describe("TimeSeries", function() {
describe('TimeSeries', function() {
var points, series;
var yAxisFormats = ["short", "ms"];
var yAxisFormats = ['short', 'ms'];
var testData;
beforeEach(function() {
testData = {
alias: "test",
datapoints: [[1, 2], [null, 3], [10, 4], [8, 5]]
alias: 'test',
datapoints: [[1, 2], [null, 3], [10, 4], [8, 5]],
};
});
describe("when getting flot pairs", function() {
it("with connected style, should ignore nulls", function() {
describe('when getting flot pairs', function() {
it('with connected style, should ignore nulls', function() {
series = new TimeSeries(testData);
points = series.getFlotPairs("connected", yAxisFormats);
points = series.getFlotPairs('connected', yAxisFormats);
expect(points.length).toBe(3);
});
it("with null as zero style, should replace nulls with zero", function() {
it('with null as zero style, should replace nulls with zero', function() {
series = new TimeSeries(testData);
points = series.getFlotPairs("null as zero", yAxisFormats);
points = series.getFlotPairs('null as zero', yAxisFormats);
expect(points.length).toBe(4);
expect(points[1][1]).toBe(0);
});
it("if last is null current should pick next to last", function() {
it('if last is null current should pick next to last', function() {
series = new TimeSeries({
datapoints: [[10, 1], [null, 2]]
datapoints: [[10, 1], [null, 2]],
});
series.getFlotPairs("null", yAxisFormats);
series.getFlotPairs('null', yAxisFormats);
expect(series.stats.current).toBe(10);
});
it("max value should work for negative values", function() {
it('max value should work for negative values', function() {
series = new TimeSeries({
datapoints: [[-10, 1], [-4, 2]]
datapoints: [[-10, 1], [-4, 2]],
});
series.getFlotPairs("null", yAxisFormats);
series.getFlotPairs('null', yAxisFormats);
expect(series.stats.max).toBe(-4);
});
it("average value should ignore nulls", function() {
it('average value should ignore nulls', function() {
series = new TimeSeries(testData);
series.getFlotPairs("null", yAxisFormats);
series.getFlotPairs('null', yAxisFormats);
expect(series.stats.avg).toBe(6.333333333333333);
});
it("the delta value should account for nulls", function() {
it('the delta value should account for nulls', function() {
series = new TimeSeries({
datapoints: [[1, 2], [3, 3], [null, 4], [10, 5], [15, 6]]
datapoints: [[1, 2], [3, 3], [null, 4], [10, 5], [15, 6]],
});
series.getFlotPairs("null", yAxisFormats);
series.getFlotPairs('null', yAxisFormats);
expect(series.stats.delta).toBe(14);
});
it("the delta value should account for nulls on first", function() {
it('the delta value should account for nulls on first', function() {
series = new TimeSeries({
datapoints: [[null, 2], [1, 3], [10, 4], [15, 5]]
datapoints: [[null, 2], [1, 3], [10, 4], [15, 5]],
});
series.getFlotPairs("null", yAxisFormats);
series.getFlotPairs('null', yAxisFormats);
expect(series.stats.delta).toBe(14);
});
it("the delta value should account for nulls on last", function() {
it('the delta value should account for nulls on last', function() {
series = new TimeSeries({
datapoints: [[1, 2], [5, 3], [10, 4], [null, 5]]
datapoints: [[1, 2], [5, 3], [10, 4], [null, 5]],
});
series.getFlotPairs("null", yAxisFormats);
series.getFlotPairs('null', yAxisFormats);
expect(series.stats.delta).toBe(9);
});
it("the delta value should account for resets", function() {
it('the delta value should account for resets', function() {
series = new TimeSeries({
datapoints: [[1, 2], [5, 3], [10, 4], [0, 5], [10, 6]]
datapoints: [[1, 2], [5, 3], [10, 4], [0, 5], [10, 6]],
});
series.getFlotPairs("null", yAxisFormats);
series.getFlotPairs('null', yAxisFormats);
expect(series.stats.delta).toBe(19);
});
it("the delta value should account for resets on last", function() {
it('the delta value should account for resets on last', function() {
series = new TimeSeries({
datapoints: [[1, 2], [2, 3], [10, 4], [8, 5]]
datapoints: [[1, 2], [2, 3], [10, 4], [8, 5]],
});
series.getFlotPairs("null", yAxisFormats);
series.getFlotPairs('null', yAxisFormats);
expect(series.stats.delta).toBe(17);
});
it("the range value should be max - min", function() {
it('the range value should be max - min', function() {
series = new TimeSeries(testData);
series.getFlotPairs("null", yAxisFormats);
series.getFlotPairs('null', yAxisFormats);
expect(series.stats.range).toBe(9);
});
it("first value should ingone nulls", function() {
it('first value should ingone nulls', function() {
series = new TimeSeries(testData);
series.getFlotPairs("null", yAxisFormats);
series.getFlotPairs('null', yAxisFormats);
expect(series.stats.first).toBe(1);
series = new TimeSeries({
datapoints: [[null, 2], [1, 3], [10, 4], [8, 5]]
datapoints: [[null, 2], [1, 3], [10, 4], [8, 5]],
});
series.getFlotPairs("null", yAxisFormats);
series.getFlotPairs('null', yAxisFormats);
expect(series.stats.first).toBe(1);
});
it("with null as zero style, average value should treat nulls as 0", function() {
it('with null as zero style, average value should treat nulls as 0', function() {
series = new TimeSeries(testData);
series.getFlotPairs("null as zero", yAxisFormats);
series.getFlotPairs('null as zero', yAxisFormats);
expect(series.stats.avg).toBe(4.75);
});
it("average value should be null if all values is null", function() {
it('average value should be null if all values is null', function() {
series = new TimeSeries({
datapoints: [[null, 2], [null, 3], [null, 4], [null, 5]]
datapoints: [[null, 2], [null, 3], [null, 4], [null, 5]],
});
series.getFlotPairs("null");
series.getFlotPairs('null');
expect(series.stats.avg).toBe(null);
});
});
describe("When checking if ms resolution is needed", function() {
describe("msResolution with second resolution timestamps", function() {
describe('When checking if ms resolution is needed', function() {
describe('msResolution with second resolution timestamps', function() {
beforeEach(function() {
series = new TimeSeries({
datapoints: [[45, 1234567890], [60, 1234567899]]
datapoints: [[45, 1234567890], [60, 1234567899]],
});
});
it("should set hasMsResolution to false", function() {
it('should set hasMsResolution to false', function() {
expect(series.hasMsResolution).toBe(false);
});
});
describe("msResolution with millisecond resolution timestamps", function() {
describe('msResolution with millisecond resolution timestamps', function() {
beforeEach(function() {
series = new TimeSeries({
datapoints: [[55, 1236547890001], [90, 1234456709000]]
datapoints: [[55, 1236547890001], [90, 1234456709000]],
});
});
it("should show millisecond resolution tooltip", function() {
it('should show millisecond resolution tooltip', function() {
expect(series.hasMsResolution).toBe(true);
});
});
describe("msResolution with millisecond resolution timestamps but with trailing zeroes", function() {
describe('msResolution with millisecond resolution timestamps but with trailing zeroes', function() {
beforeEach(function() {
series = new TimeSeries({
datapoints: [[45, 1234567890000], [60, 1234567899000]]
datapoints: [[45, 1234567890000], [60, 1234567899000]],
});
});
it("should not show millisecond resolution tooltip", function() {
it('should not show millisecond resolution tooltip', function() {
expect(series.hasMsResolution).toBe(false);
});
});
});
describe("can detect if series contains ms precision", function() {
describe('can detect if series contains ms precision', function() {
var fakedata;
beforeEach(function() {
fakedata = testData;
});
it("missing datapoint with ms precision", function() {
it('missing datapoint with ms precision', function() {
fakedata.datapoints[0] = [1337, 1234567890000];
series = new TimeSeries(fakedata);
expect(series.isMsResolutionNeeded()).toBe(false);
});
it("contains datapoint with ms precision", function() {
it('contains datapoint with ms precision', function() {
fakedata.datapoints[0] = [1337, 1236547890001];
series = new TimeSeries(fakedata);
expect(series.isMsResolutionNeeded()).toBe(true);
});
});
describe("series overrides", function() {
describe('series overrides', function() {
var series;
beforeEach(function() {
series = new TimeSeries(testData);
});
describe("fill & points", function() {
describe('fill & points', function() {
beforeEach(function() {
series.alias = "test";
series.applySeriesOverrides([{ alias: "test", fill: 0, points: true }]);
series.alias = 'test';
series.applySeriesOverrides([{ alias: 'test', fill: 0, points: true }]);
});
it("should set fill zero, and enable points", function() {
it('should set fill zero, and enable points', function() {
expect(series.lines.fill).toBe(0.001);
expect(series.points.show).toBe(true);
});
});
describe("series option overrides, bars, true & lines false", function() {
describe('series option overrides, bars, true & lines false', function() {
beforeEach(function() {
series.alias = "test";
series.alias = 'test';
series.applySeriesOverrides([
{ alias: "test", bars: true, lines: false }
{ alias: 'test', bars: true, lines: false },
]);
});
it("should disable lines, and enable bars", function() {
it('should disable lines, and enable bars', function() {
expect(series.lines.show).toBe(false);
expect(series.bars.show).toBe(true);
});
});
describe("series option overrides, linewidth, stack", function() {
describe('series option overrides, linewidth, stack', function() {
beforeEach(function() {
series.alias = "test";
series.alias = 'test';
series.applySeriesOverrides([
{ alias: "test", linewidth: 5, stack: false }
{ alias: 'test', linewidth: 5, stack: false },
]);
});
it("should disable stack, and set lineWidth", function() {
it('should disable stack, and set lineWidth', function() {
expect(series.stack).toBe(false);
expect(series.lines.lineWidth).toBe(5);
});
});
describe("series option overrides, dashes and lineWidth", function() {
describe('series option overrides, dashes and lineWidth', function() {
beforeEach(function() {
series.alias = "test";
series.alias = 'test';
series.applySeriesOverrides([
{ alias: "test", linewidth: 5, dashes: true }
{ alias: 'test', linewidth: 5, dashes: true },
]);
});
it("should enable dashes, set dashes lineWidth to 5 and lines lineWidth to 0", function() {
it('should enable dashes, set dashes lineWidth to 5 and lines lineWidth to 0', function() {
expect(series.dashes.show).toBe(true);
expect(series.dashes.lineWidth).toBe(5);
expect(series.lines.lineWidth).toBe(0);
});
});
describe("series option overrides, fill below to", function() {
describe('series option overrides, fill below to', function() {
beforeEach(function() {
series.alias = "test";
series.applySeriesOverrides([{ alias: "test", fillBelowTo: "min" }]);
series.alias = 'test';
series.applySeriesOverrides([{ alias: 'test', fillBelowTo: 'min' }]);
});
it("should disable line fill and add fillBelowTo", function() {
expect(series.fillBelowTo).toBe("min");
it('should disable line fill and add fillBelowTo', function() {
expect(series.fillBelowTo).toBe('min');
});
});
describe("series option overrides, pointradius, steppedLine", function() {
describe('series option overrides, pointradius, steppedLine', function() {
beforeEach(function() {
series.alias = "test";
series.alias = 'test';
series.applySeriesOverrides([
{ alias: "test", pointradius: 5, steppedLine: true }
{ alias: 'test', pointradius: 5, steppedLine: true },
]);
});
it("should set pointradius, and set steppedLine", function() {
it('should set pointradius, and set steppedLine', function() {
expect(series.points.radius).toBe(5);
expect(series.lines.steps).toBe(true);
});
});
describe("override match on regex", function() {
describe('override match on regex', function() {
beforeEach(function() {
series.alias = "test_01";
series.applySeriesOverrides([{ alias: "/.*01/", lines: false }]);
series.alias = 'test_01';
series.applySeriesOverrides([{ alias: '/.*01/', lines: false }]);
});
it("should match second series", function() {
it('should match second series', function() {
expect(series.lines.show).toBe(false);
});
});
describe("override series y-axis, and z-index", function() {
describe('override series y-axis, and z-index', function() {
beforeEach(function() {
series.alias = "test";
series.applySeriesOverrides([{ alias: "test", yaxis: 2, zindex: 2 }]);
series.alias = 'test';
series.applySeriesOverrides([{ alias: 'test', yaxis: 2, zindex: 2 }]);
});
it("should set yaxis", function() {
it('should set yaxis', function() {
expect(series.yaxis).toBe(2);
});
it("should set zindex", function() {
it('should set zindex', function() {
expect(series.zindex).toBe(2);
});
});
});
describe("value formatter", function() {
describe('value formatter', function() {
var series;
beforeEach(function() {
series = new TimeSeries(testData);
});
it("should format non-numeric values as empty string", function() {
expect(series.formatValue(null)).toBe("");
expect(series.formatValue(undefined)).toBe("");
expect(series.formatValue(NaN)).toBe("");
expect(series.formatValue(Infinity)).toBe("");
expect(series.formatValue(-Infinity)).toBe("");
it('should format non-numeric values as empty string', function() {
expect(series.formatValue(null)).toBe('');
expect(series.formatValue(undefined)).toBe('');
expect(series.formatValue(NaN)).toBe('');
expect(series.formatValue(Infinity)).toBe('');
expect(series.formatValue(-Infinity)).toBe('');
});
});
});
@@ -4,174 +4,174 @@ import {
it,
expect,
angularMocks,
sinon
} from "test/lib/common";
import "app/core/directives/value_select_dropdown";
sinon,
} from 'test/lib/common';
import 'app/core/directives/value_select_dropdown';
describe("SelectDropdownCtrl", function() {
describe('SelectDropdownCtrl', function() {
var scope;
var ctrl;
var tagValuesMap: any = {};
var rootScope;
var q;
beforeEach(angularMocks.module("grafana.core"));
beforeEach(angularMocks.module('grafana.core'));
beforeEach(
angularMocks.inject(function($controller, $rootScope, $q, $httpBackend) {
rootScope = $rootScope;
q = $q;
scope = $rootScope.$new();
ctrl = $controller("ValueSelectDropdownCtrl", { $scope: scope });
ctrl = $controller('ValueSelectDropdownCtrl', { $scope: scope });
ctrl.onUpdated = sinon.spy();
$httpBackend.when("GET", /\.html$/).respond("");
$httpBackend.when('GET', /\.html$/).respond('');
})
);
describe("Given simple variable", function() {
describe('Given simple variable', function() {
beforeEach(function() {
ctrl.variable = {
current: { text: "hej", value: "hej" },
current: { text: 'hej', value: 'hej' },
getValuesForTag: function(key) {
return q.when(tagValuesMap[key]);
}
},
};
ctrl.init();
});
it("Should init labelText and linkText", function() {
expect(ctrl.linkText).to.be("hej");
it('Should init labelText and linkText', function() {
expect(ctrl.linkText).to.be('hej');
});
});
describe("Given variable with tags and dropdown is opened", function() {
describe('Given variable with tags and dropdown is opened', function() {
beforeEach(function() {
ctrl.variable = {
current: { text: "server-1", value: "server-1" },
current: { text: 'server-1', value: 'server-1' },
options: [
{ text: "server-1", value: "server-1", selected: true },
{ text: "server-2", value: "server-2" },
{ text: "server-3", value: "server-3" }
{ text: 'server-1', value: 'server-1', selected: true },
{ text: 'server-2', value: 'server-2' },
{ text: 'server-3', value: 'server-3' },
],
tags: ["key1", "key2", "key3"],
tags: ['key1', 'key2', 'key3'],
getValuesForTag: function(key) {
return q.when(tagValuesMap[key]);
},
multi: true
multi: true,
};
tagValuesMap.key1 = ["server-1", "server-3"];
tagValuesMap.key2 = ["server-2", "server-3"];
tagValuesMap.key3 = ["server-1", "server-2", "server-3"];
tagValuesMap.key1 = ['server-1', 'server-3'];
tagValuesMap.key2 = ['server-2', 'server-3'];
tagValuesMap.key3 = ['server-1', 'server-2', 'server-3'];
ctrl.init();
ctrl.show();
});
it("should init tags model", function() {
it('should init tags model', function() {
expect(ctrl.tags.length).to.be(3);
expect(ctrl.tags[0].text).to.be("key1");
expect(ctrl.tags[0].text).to.be('key1');
});
it("should init options model", function() {
it('should init options model', function() {
expect(ctrl.options.length).to.be(3);
});
it("should init selected values array", function() {
it('should init selected values array', function() {
expect(ctrl.selectedValues.length).to.be(1);
});
it("should set linkText", function() {
expect(ctrl.linkText).to.be("server-1");
it('should set linkText', function() {
expect(ctrl.linkText).to.be('server-1');
});
describe("after adititional value is selected", function() {
describe('after adititional value is selected', function() {
beforeEach(function() {
ctrl.selectValue(ctrl.options[2], {});
ctrl.commitChanges();
});
it("should update link text", function() {
expect(ctrl.linkText).to.be("server-1 + server-3");
it('should update link text', function() {
expect(ctrl.linkText).to.be('server-1 + server-3');
});
});
describe("When tag is selected", function() {
describe('When tag is selected', function() {
beforeEach(function() {
ctrl.selectTag(ctrl.tags[0]);
rootScope.$digest();
ctrl.commitChanges();
});
it("should select tag", function() {
it('should select tag', function() {
expect(ctrl.selectedTags.length).to.be(1);
});
it("should select values", function() {
it('should select values', function() {
expect(ctrl.options[0].selected).to.be(true);
expect(ctrl.options[2].selected).to.be(true);
});
it("link text should not include tag values", function() {
expect(ctrl.linkText).to.be("");
it('link text should not include tag values', function() {
expect(ctrl.linkText).to.be('');
});
describe("and then dropdown is opened and closed without changes", function() {
describe('and then dropdown is opened and closed without changes', function() {
beforeEach(function() {
ctrl.show();
ctrl.commitChanges();
rootScope.$digest();
});
it("should still have selected tag", function() {
it('should still have selected tag', function() {
expect(ctrl.selectedTags.length).to.be(1);
});
});
describe("and then unselected", function() {
describe('and then unselected', function() {
beforeEach(function() {
ctrl.selectTag(ctrl.tags[0]);
rootScope.$digest();
});
it("should deselect tag", function() {
it('should deselect tag', function() {
expect(ctrl.selectedTags.length).to.be(0);
});
});
describe("and then value is unselected", function() {
describe('and then value is unselected', function() {
beforeEach(function() {
ctrl.selectValue(ctrl.options[0], {});
});
it("should deselect tag", function() {
it('should deselect tag', function() {
expect(ctrl.selectedTags.length).to.be(0);
});
});
});
});
describe("Given variable with selected tags", function() {
describe('Given variable with selected tags', function() {
beforeEach(function() {
ctrl.variable = {
current: {
text: "server-1",
value: "server-1",
tags: [{ text: "key1", selected: true }]
text: 'server-1',
value: 'server-1',
tags: [{ text: 'key1', selected: true }],
},
options: [
{ text: "server-1", value: "server-1" },
{ text: "server-2", value: "server-2" },
{ text: "server-3", value: "server-3" }
{ text: 'server-1', value: 'server-1' },
{ text: 'server-2', value: 'server-2' },
{ text: 'server-3', value: 'server-3' },
],
tags: ["key1", "key2", "key3"],
tags: ['key1', 'key2', 'key3'],
getValuesForTag: function(key) {
return q.when(tagValuesMap[key]);
},
multi: true
multi: true,
};
ctrl.init();
ctrl.show();
});
it("should set tag as selected", function() {
it('should set tag as selected', function() {
expect(ctrl.tags[0].selected).to.be(true);
});
});