The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/plugins/datasource/influxdb/specs/query_ctrl.test.ts

180 lines
6.2 KiB

8 years ago
import '../query_ctrl';
8 years ago
import { uiSegmentSrv } from 'app/core/services/segment_srv';
8 years ago
import { InfluxQueryCtrl } from '../query_ctrl';
import InfluxDatasource from '../datasource';
8 years ago
8 years ago
describe('InfluxDBQueryCtrl', () => {
const ctx = {} as any;
8 years ago
8 years ago
beforeEach(() => {
InfluxQueryCtrl.prototype.datasource = ({
8 years ago
metricFindQuery: () => Promise.resolve([]),
} as unknown) as InfluxDatasource;
8 years ago
InfluxQueryCtrl.prototype.target = { target: {} };
8 years ago
InfluxQueryCtrl.prototype.panelCtrl = {
panel: {
8 years ago
targets: [InfluxQueryCtrl.prototype.target],
8 years ago
},
8 years ago
refresh: () => {},
8 years ago
};
8 years ago
ctx.ctrl = new InfluxQueryCtrl(
{},
{} as any,
{} as any,
//@ts-ignore
new uiSegmentSrv({ trustAsHtml: (html: any) => html }, { highlightVariablesAsHtml: () => {} })
8 years ago
);
8 years ago
});
8 years ago
describe('init', () => {
it('should init tagSegments', () => {
8 years ago
expect(ctx.ctrl.tagSegments.length).toBe(1);
});
8 years ago
it('should init measurementSegment', () => {
8 years ago
expect(ctx.ctrl.measurementSegment.value).toBe('select measurement');
});
});
8 years ago
describe('when first tag segment is updated', () => {
beforeEach(() => {
8 years ago
ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0);
});
8 years ago
it('should update tag key', () => {
8 years ago
expect(ctx.ctrl.target.tags[0].key).toBe('asd');
expect(ctx.ctrl.tagSegments[0].type).toBe('key');
});
8 years ago
it('should add tagSegments', () => {
8 years ago
expect(ctx.ctrl.tagSegments.length).toBe(3);
});
});
8 years ago
describe('when last tag value segment is updated', () => {
beforeEach(() => {
8 years ago
ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0);
ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2);
});
8 years ago
it('should update tag value', () => {
8 years ago
expect(ctx.ctrl.target.tags[0].value).toBe('server1');
});
8 years ago
it('should set tag operator', () => {
8 years ago
expect(ctx.ctrl.target.tags[0].operator).toBe('=');
});
8 years ago
it('should add plus button for another filter', () => {
8 years ago
expect(ctx.ctrl.tagSegments[3].fake).toBe(true);
});
});
8 years ago
describe('when last tag value segment is updated to regex', () => {
beforeEach(() => {
8 years ago
ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0);
ctx.ctrl.tagSegmentUpdated({ value: '/server.*/', type: 'value' }, 2);
});
8 years ago
it('should update operator', () => {
8 years ago
expect(ctx.ctrl.tagSegments[1].value).toBe('=~');
expect(ctx.ctrl.target.tags[0].operator).toBe('=~');
});
});
8 years ago
describe('when second tag key is added', () => {
beforeEach(() => {
8 years ago
ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0);
ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2);
ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3);
});
8 years ago
it('should update tag key', () => {
8 years ago
expect(ctx.ctrl.target.tags[1].key).toBe('key2');
});
8 years ago
it('should add AND segment', () => {
8 years ago
expect(ctx.ctrl.tagSegments[3].value).toBe('AND');
});
});
8 years ago
describe('when condition is changed', () => {
beforeEach(() => {
8 years ago
ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0);
ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2);
ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3);
ctx.ctrl.tagSegmentUpdated({ value: 'OR', type: 'condition' }, 3);
});
8 years ago
it('should update tag condition', () => {
8 years ago
expect(ctx.ctrl.target.tags[1].condition).toBe('OR');
});
8 years ago
it('should update AND segment', () => {
8 years ago
expect(ctx.ctrl.tagSegments[3].value).toBe('OR');
expect(ctx.ctrl.tagSegments.length).toBe(7);
});
});
8 years ago
describe('when deleting first tag filter after value is selected', () => {
beforeEach(() => {
8 years ago
ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0);
ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2);
ctx.ctrl.tagSegmentUpdated(ctx.ctrl.removeTagFilterSegment, 0);
});
8 years ago
it('should remove tags', () => {
8 years ago
expect(ctx.ctrl.target.tags.length).toBe(0);
});
8 years ago
it('should remove all segment after 2 and replace with plus button', () => {
8 years ago
expect(ctx.ctrl.tagSegments.length).toBe(1);
expect(ctx.ctrl.tagSegments[0].type).toBe('plus-button');
});
});
8 years ago
describe('when deleting second tag value before second tag value is complete', () => {
beforeEach(() => {
8 years ago
ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0);
ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2);
ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3);
ctx.ctrl.tagSegmentUpdated(ctx.ctrl.removeTagFilterSegment, 4);
});
8 years ago
it('should remove all segment after 2 and replace with plus button', () => {
8 years ago
expect(ctx.ctrl.tagSegments.length).toBe(4);
expect(ctx.ctrl.tagSegments[3].type).toBe('plus-button');
});
});
8 years ago
describe('when deleting second tag value before second tag value is complete', () => {
beforeEach(() => {
8 years ago
ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0);
ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2);
ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3);
ctx.ctrl.tagSegmentUpdated(ctx.ctrl.removeTagFilterSegment, 4);
});
8 years ago
it('should remove all segment after 2 and replace with plus button', () => {
8 years ago
expect(ctx.ctrl.tagSegments.length).toBe(4);
expect(ctx.ctrl.tagSegments[3].type).toBe('plus-button');
});
});
8 years ago
describe('when deleting second tag value after second tag filter is complete', () => {
beforeEach(() => {
8 years ago
ctx.ctrl.tagSegmentUpdated({ value: 'asd', type: 'plus-button' }, 0);
ctx.ctrl.tagSegmentUpdated({ value: 'server1', type: 'value' }, 2);
ctx.ctrl.tagSegmentUpdated({ value: 'key2', type: 'plus-button' }, 3);
ctx.ctrl.tagSegmentUpdated({ value: 'value', type: 'value' }, 6);
ctx.ctrl.tagSegmentUpdated(ctx.ctrl.removeTagFilterSegment, 4);
});
8 years ago
it('should remove all segment after 2 and replace with plus button', () => {
8 years ago
expect(ctx.ctrl.tagSegments.length).toBe(4);
expect(ctx.ctrl.tagSegments[3].type).toBe('plus-button');
});
});
});