mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 20:59:35 +08:00
prettier: change to single quoting
This commit is contained in:
@ -3,20 +3,20 @@ import {
|
||||
beforeEach,
|
||||
it,
|
||||
expect,
|
||||
angularMocks
|
||||
} from "test/lib/common";
|
||||
import moment from "moment";
|
||||
import helpers from "test/specs/helpers";
|
||||
import { PostgresDatasource } from "../datasource";
|
||||
import { CustomVariable } from "app/features/templating/custom_variable";
|
||||
angularMocks,
|
||||
} from 'test/lib/common';
|
||||
import moment from 'moment';
|
||||
import helpers from 'test/specs/helpers';
|
||||
import { PostgresDatasource } from '../datasource';
|
||||
import { CustomVariable } from 'app/features/templating/custom_variable';
|
||||
|
||||
describe("PostgreSQLDatasource", function() {
|
||||
describe('PostgreSQLDatasource', function() {
|
||||
var ctx = new helpers.ServiceTestContext();
|
||||
var instanceSettings = { name: "postgresql" };
|
||||
var instanceSettings = { name: 'postgresql' };
|
||||
|
||||
beforeEach(angularMocks.module("grafana.core"));
|
||||
beforeEach(angularMocks.module("grafana.services"));
|
||||
beforeEach(ctx.providePhase(["backendSrv"]));
|
||||
beforeEach(angularMocks.module('grafana.core'));
|
||||
beforeEach(angularMocks.module('grafana.services'));
|
||||
beforeEach(ctx.providePhase(['backendSrv']));
|
||||
|
||||
beforeEach(
|
||||
angularMocks.inject(function($q, $rootScope, $httpBackend, $injector) {
|
||||
@ -24,26 +24,26 @@ describe("PostgreSQLDatasource", function() {
|
||||
ctx.$httpBackend = $httpBackend;
|
||||
ctx.$rootScope = $rootScope;
|
||||
ctx.ds = $injector.instantiate(PostgresDatasource, {
|
||||
instanceSettings: instanceSettings
|
||||
instanceSettings: instanceSettings,
|
||||
});
|
||||
$httpBackend.when("GET", /\.html$/).respond("");
|
||||
$httpBackend.when('GET', /\.html$/).respond('');
|
||||
})
|
||||
);
|
||||
|
||||
describe("When performing annotationQuery", function() {
|
||||
describe('When performing annotationQuery', function() {
|
||||
let results;
|
||||
|
||||
const annotationName = "MyAnno";
|
||||
const annotationName = 'MyAnno';
|
||||
|
||||
const options = {
|
||||
annotation: {
|
||||
name: annotationName,
|
||||
rawQuery: "select time, title, text, tags from table;"
|
||||
rawQuery: 'select time, title, text, tags from table;',
|
||||
},
|
||||
range: {
|
||||
from: moment(1432288354),
|
||||
to: moment(1432288401)
|
||||
}
|
||||
to: moment(1432288401),
|
||||
},
|
||||
};
|
||||
|
||||
const response = {
|
||||
@ -52,16 +52,16 @@ describe("PostgreSQLDatasource", function() {
|
||||
refId: annotationName,
|
||||
tables: [
|
||||
{
|
||||
columns: [{ text: "time" }, { text: "text" }, { text: "tags" }],
|
||||
columns: [{ text: 'time' }, { text: 'text' }, { text: 'tags' }],
|
||||
rows: [
|
||||
[1432288355, "some text", "TagA,TagB"],
|
||||
[1432288390, "some text2", " TagB , TagC"],
|
||||
[1432288400, "some text3"]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
[1432288355, 'some text', 'TagA,TagB'],
|
||||
[1432288390, 'some text2', ' TagB , TagC'],
|
||||
[1432288400, 'some text3'],
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
@ -74,42 +74,42 @@ describe("PostgreSQLDatasource", function() {
|
||||
ctx.$rootScope.$apply();
|
||||
});
|
||||
|
||||
it("should return annotation list", function() {
|
||||
it('should return annotation list', function() {
|
||||
expect(results.length).to.be(3);
|
||||
|
||||
expect(results[0].text).to.be("some text");
|
||||
expect(results[0].tags[0]).to.be("TagA");
|
||||
expect(results[0].tags[1]).to.be("TagB");
|
||||
expect(results[0].text).to.be('some text');
|
||||
expect(results[0].tags[0]).to.be('TagA');
|
||||
expect(results[0].tags[1]).to.be('TagB');
|
||||
|
||||
expect(results[1].tags[0]).to.be("TagB");
|
||||
expect(results[1].tags[1]).to.be("TagC");
|
||||
expect(results[1].tags[0]).to.be('TagB');
|
||||
expect(results[1].tags[1]).to.be('TagC');
|
||||
|
||||
expect(results[2].tags.length).to.be(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("When performing metricFindQuery", function() {
|
||||
describe('When performing metricFindQuery', function() {
|
||||
let results;
|
||||
const query = "select * from atable";
|
||||
const query = 'select * from atable';
|
||||
const response = {
|
||||
results: {
|
||||
tempvar: {
|
||||
meta: {
|
||||
rowCount: 3
|
||||
rowCount: 3,
|
||||
},
|
||||
refId: "tempvar",
|
||||
refId: 'tempvar',
|
||||
tables: [
|
||||
{
|
||||
columns: [{ text: "title" }, { text: "text" }],
|
||||
columns: [{ text: 'title' }, { text: 'text' }],
|
||||
rows: [
|
||||
["aTitle", "some text"],
|
||||
["aTitle2", "some text2"],
|
||||
["aTitle3", "some text3"]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
['aTitle', 'some text'],
|
||||
['aTitle2', 'some text2'],
|
||||
['aTitle3', 'some text3'],
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
@ -122,35 +122,35 @@ describe("PostgreSQLDatasource", function() {
|
||||
ctx.$rootScope.$apply();
|
||||
});
|
||||
|
||||
it("should return list of all column values", function() {
|
||||
it('should return list of all column values', function() {
|
||||
expect(results.length).to.be(6);
|
||||
expect(results[0].text).to.be("aTitle");
|
||||
expect(results[5].text).to.be("some text3");
|
||||
expect(results[0].text).to.be('aTitle');
|
||||
expect(results[5].text).to.be('some text3');
|
||||
});
|
||||
});
|
||||
|
||||
describe("When performing metricFindQuery with key, value columns", function() {
|
||||
describe('When performing metricFindQuery with key, value columns', function() {
|
||||
let results;
|
||||
const query = "select * from atable";
|
||||
const query = 'select * from atable';
|
||||
const response = {
|
||||
results: {
|
||||
tempvar: {
|
||||
meta: {
|
||||
rowCount: 3
|
||||
rowCount: 3,
|
||||
},
|
||||
refId: "tempvar",
|
||||
refId: 'tempvar',
|
||||
tables: [
|
||||
{
|
||||
columns: [{ text: "__value" }, { text: "__text" }],
|
||||
columns: [{ text: '__value' }, { text: '__text' }],
|
||||
rows: [
|
||||
["value1", "aTitle"],
|
||||
["value2", "aTitle2"],
|
||||
["value3", "aTitle3"]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
['value1', 'aTitle'],
|
||||
['value2', 'aTitle2'],
|
||||
['value3', 'aTitle3'],
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
@ -163,33 +163,37 @@ describe("PostgreSQLDatasource", function() {
|
||||
ctx.$rootScope.$apply();
|
||||
});
|
||||
|
||||
it("should return list of as text, value", function() {
|
||||
it('should return list of as text, value', function() {
|
||||
expect(results.length).to.be(3);
|
||||
expect(results[0].text).to.be("aTitle");
|
||||
expect(results[0].value).to.be("value1");
|
||||
expect(results[2].text).to.be("aTitle3");
|
||||
expect(results[2].value).to.be("value3");
|
||||
expect(results[0].text).to.be('aTitle');
|
||||
expect(results[0].value).to.be('value1');
|
||||
expect(results[2].text).to.be('aTitle3');
|
||||
expect(results[2].value).to.be('value3');
|
||||
});
|
||||
});
|
||||
|
||||
describe("When performing metricFindQuery with key, value columns and with duplicate keys", function() {
|
||||
describe('When performing metricFindQuery with key, value columns and with duplicate keys', function() {
|
||||
let results;
|
||||
const query = "select * from atable";
|
||||
const query = 'select * from atable';
|
||||
const response = {
|
||||
results: {
|
||||
tempvar: {
|
||||
meta: {
|
||||
rowCount: 3
|
||||
rowCount: 3,
|
||||
},
|
||||
refId: "tempvar",
|
||||
refId: 'tempvar',
|
||||
tables: [
|
||||
{
|
||||
columns: [{ text: "__text" }, { text: "__value" }],
|
||||
rows: [["aTitle", "same"], ["aTitle", "same"], ["aTitle", "diff"]]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
columns: [{ text: '__text' }, { text: '__value' }],
|
||||
rows: [
|
||||
['aTitle', 'same'],
|
||||
['aTitle', 'same'],
|
||||
['aTitle', 'diff'],
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
@ -202,49 +206,49 @@ describe("PostgreSQLDatasource", function() {
|
||||
ctx.$rootScope.$apply();
|
||||
});
|
||||
|
||||
it("should return list of unique keys", function() {
|
||||
it('should return list of unique keys', function() {
|
||||
expect(results.length).to.be(1);
|
||||
expect(results[0].text).to.be("aTitle");
|
||||
expect(results[0].value).to.be("same");
|
||||
expect(results[0].text).to.be('aTitle');
|
||||
expect(results[0].value).to.be('same');
|
||||
});
|
||||
});
|
||||
|
||||
describe("When interpolating variables", () => {
|
||||
describe('When interpolating variables', () => {
|
||||
beforeEach(function() {
|
||||
ctx.variable = new CustomVariable({}, {});
|
||||
});
|
||||
|
||||
describe("and value is a string", () => {
|
||||
it("should return an unquoted value", () => {
|
||||
expect(ctx.ds.interpolateVariable("abc", ctx.variable)).to.eql("abc");
|
||||
describe('and value is a string', () => {
|
||||
it('should return an unquoted value', () => {
|
||||
expect(ctx.ds.interpolateVariable('abc', ctx.variable)).to.eql('abc');
|
||||
});
|
||||
});
|
||||
|
||||
describe("and value is a number", () => {
|
||||
it("should return an unquoted value", () => {
|
||||
describe('and value is a number', () => {
|
||||
it('should return an unquoted value', () => {
|
||||
expect(ctx.ds.interpolateVariable(1000, ctx.variable)).to.eql(1000);
|
||||
});
|
||||
});
|
||||
|
||||
describe("and value is an array of strings", () => {
|
||||
it("should return comma separated quoted values", () => {
|
||||
describe('and value is an array of strings', () => {
|
||||
it('should return comma separated quoted values', () => {
|
||||
expect(
|
||||
ctx.ds.interpolateVariable(["a", "b", "c"], ctx.variable)
|
||||
ctx.ds.interpolateVariable(['a', 'b', 'c'], ctx.variable)
|
||||
).to.eql("'a','b','c'");
|
||||
});
|
||||
});
|
||||
|
||||
describe("and variable allows multi-value and is a string", () => {
|
||||
it("should return a quoted value", () => {
|
||||
describe('and variable allows multi-value and is a string', () => {
|
||||
it('should return a quoted value', () => {
|
||||
ctx.variable.multi = true;
|
||||
expect(ctx.ds.interpolateVariable("abc", ctx.variable)).to.eql("'abc'");
|
||||
expect(ctx.ds.interpolateVariable('abc', ctx.variable)).to.eql("'abc'");
|
||||
});
|
||||
});
|
||||
|
||||
describe("and variable allows all and is a string", () => {
|
||||
it("should return a quoted value", () => {
|
||||
describe('and variable allows all and is a string', () => {
|
||||
it('should return a quoted value', () => {
|
||||
ctx.variable.includeAll = true;
|
||||
expect(ctx.ds.interpolateVariable("abc", ctx.variable)).to.eql("'abc'");
|
||||
expect(ctx.ds.interpolateVariable('abc', ctx.variable)).to.eql("'abc'");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user