Commit 74b4d2ef by Marcus Efraimsson Committed by GitHub

Merge pull request #12704 from dehrax/12224-completer

Karma to Jest: completer
parents 1c4dd6f2 27c08134
import { describe, it, sinon, expect } from 'test/lib/common';
import helpers from 'test/specs/helpers';
import { PromCompleter } from '../completer'; import { PromCompleter } from '../completer';
import { PrometheusDatasource } from '../datasource'; import { PrometheusDatasource } from '../datasource';
import { BackendSrv } from 'app/core/services/backend_srv';
jest.mock('../datasource');
jest.mock('app/core/services/backend_srv');
describe('Prometheus editor completer', function() { describe('Prometheus editor completer', function() {
var ctx = new helpers.ServiceTestContext(); //beforeEach(ctx.providePhase(['templateSrv']));
beforeEach(ctx.providePhase(['templateSrv']));
function getSessionStub(data) { function getSessionStub(data) {
return { return {
getTokenAt: sinon.stub().returns(data.currentToken), getTokenAt: jest.fn(() => data.currentToken),
getTokens: sinon.stub().returns(data.tokens), getTokens: jest.fn(() => data.tokens),
getLine: sinon.stub().returns(data.line), getLine: jest.fn(() => data.line),
}; };
} }
let editor = {}; let editor = {};
let datasourceStub = <PrometheusDatasource>{
performInstantQuery: sinon let backendSrv = <BackendSrv>{};
.stub() let datasourceStub = new PrometheusDatasource({}, {}, backendSrv, {}, {});
.withArgs({ expr: '{__name__="node_cpu"' })
.returns( datasourceStub.performInstantQuery = jest.fn(() =>
Promise.resolve({ Promise.resolve({
data: { data: {
data: { data: {
result: [ result: [
{ {
metric: { metric: {
job: 'node', job: 'node',
instance: 'localhost:9100', instance: 'localhost:9100',
}, },
},
],
}, },
}, ],
}) },
), },
performSuggestQuery: sinon })
.stub() );
.withArgs('node', true) datasourceStub.performSuggestQuery = jest.fn(() => Promise.resolve(['node_cpu']));
.returns(Promise.resolve(['node_cpu'])),
};
let templateSrv = { let templateSrv = {
variables: [ variables: [
...@@ -62,9 +57,9 @@ describe('Prometheus editor completer', function() { ...@@ -62,9 +57,9 @@ describe('Prometheus editor completer', function() {
}); });
return completer.getCompletions(editor, session, { row: 0, column: 10 }, '[', (s, res) => { return completer.getCompletions(editor, session, { row: 0, column: 10 }, '[', (s, res) => {
expect(res[0].caption).to.eql('$__interval'); expect(res[0].caption).toEqual('$__interval');
expect(res[0].value).to.eql('[$__interval'); expect(res[0].value).toEqual('[$__interval');
expect(res[0].meta).to.eql('range vector'); expect(res[0].meta).toEqual('range vector');
}); });
}); });
}); });
...@@ -93,7 +88,7 @@ describe('Prometheus editor completer', function() { ...@@ -93,7 +88,7 @@ describe('Prometheus editor completer', function() {
}); });
return completer.getCompletions(editor, session, { row: 0, column: 10 }, 'j', (s, res) => { return completer.getCompletions(editor, session, { row: 0, column: 10 }, 'j', (s, res) => {
expect(res[0].meta).to.eql('label name'); expect(res[0].meta).toEqual('label name');
}); });
}); });
}); });
...@@ -125,7 +120,7 @@ describe('Prometheus editor completer', function() { ...@@ -125,7 +120,7 @@ describe('Prometheus editor completer', function() {
}); });
return completer.getCompletions(editor, session, { row: 0, column: 23 }, 'j', (s, res) => { return completer.getCompletions(editor, session, { row: 0, column: 23 }, 'j', (s, res) => {
expect(res[0].meta).to.eql('label name'); expect(res[0].meta).toEqual('label name');
}); });
}); });
}); });
...@@ -156,7 +151,7 @@ describe('Prometheus editor completer', function() { ...@@ -156,7 +151,7 @@ describe('Prometheus editor completer', function() {
}); });
return completer.getCompletions(editor, session, { row: 0, column: 15 }, 'n', (s, res) => { return completer.getCompletions(editor, session, { row: 0, column: 15 }, 'n', (s, res) => {
expect(res[0].meta).to.eql('label value'); expect(res[0].meta).toEqual('label value');
}); });
}); });
}); });
...@@ -192,7 +187,7 @@ describe('Prometheus editor completer', function() { ...@@ -192,7 +187,7 @@ describe('Prometheus editor completer', function() {
}); });
return completer.getCompletions(editor, session, { row: 0, column: 23 }, 'm', (s, res) => { return completer.getCompletions(editor, session, { row: 0, column: 23 }, 'm', (s, res) => {
expect(res[0].meta).to.eql('label name'); expect(res[0].meta).toEqual('label name');
}); });
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment