|
|
@ -1,21 +1,22 @@ |
|
|
|
// @ts-ignore
|
|
|
|
|
|
|
|
import Plain from 'slate-plain-serializer'; |
|
|
|
import Plain from 'slate-plain-serializer'; |
|
|
|
|
|
|
|
import { Editor as SlateEditor } from 'slate'; |
|
|
|
import LanguageProvider from '../language_provider'; |
|
|
|
import LanguageProvider from '../language_provider'; |
|
|
|
|
|
|
|
import { PrometheusDatasource } from '../datasource'; |
|
|
|
|
|
|
|
import { HistoryItem } from 'app/types'; |
|
|
|
|
|
|
|
import { PromQuery } from '../types'; |
|
|
|
|
|
|
|
|
|
|
|
describe('Language completion provider', () => { |
|
|
|
describe('Language completion provider', () => { |
|
|
|
const datasource = { |
|
|
|
const datasource: PrometheusDatasource = ({ |
|
|
|
metadataRequest: () => ({ data: { data: [] as any[] } }), |
|
|
|
metadataRequest: () => ({ data: { data: [] as any[] } }), |
|
|
|
getTimeRange: () => ({ start: 0, end: 1 }), |
|
|
|
getTimeRange: () => ({ start: 0, end: 1 }), |
|
|
|
}; |
|
|
|
} as any) as PrometheusDatasource; |
|
|
|
|
|
|
|
|
|
|
|
describe('empty query suggestions', () => { |
|
|
|
describe('empty query suggestions', () => { |
|
|
|
it('returns default suggestions on emtpty context', () => { |
|
|
|
it('returns default suggestions on empty context', async () => { |
|
|
|
const instance = new LanguageProvider(datasource); |
|
|
|
const instance = new LanguageProvider(datasource); |
|
|
|
const value = Plain.deserialize(''); |
|
|
|
const value = Plain.deserialize(''); |
|
|
|
const result = instance.provideCompletionItems({ text: '', prefix: '', value, wrapperClasses: [] }); |
|
|
|
const result = await instance.provideCompletionItems({ text: '', prefix: '', value, wrapperClasses: [] }); |
|
|
|
expect(result.context).toBeUndefined(); |
|
|
|
expect(result.context).toBeUndefined(); |
|
|
|
expect(result.refresher).toBeUndefined(); |
|
|
|
|
|
|
|
expect(result.suggestions).toMatchObject([ |
|
|
|
expect(result.suggestions).toMatchObject([ |
|
|
|
{ |
|
|
|
{ |
|
|
|
label: 'Functions', |
|
|
|
label: 'Functions', |
|
|
@ -23,12 +24,11 @@ describe('Language completion provider', () => { |
|
|
|
]); |
|
|
|
]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns default suggestions with metrics on emtpty context when metrics were provided', () => { |
|
|
|
it('returns default suggestions with metrics on empty context when metrics were provided', async () => { |
|
|
|
const instance = new LanguageProvider(datasource, { metrics: ['foo', 'bar'] }); |
|
|
|
const instance = new LanguageProvider(datasource, { metrics: ['foo', 'bar'] }); |
|
|
|
const value = Plain.deserialize(''); |
|
|
|
const value = Plain.deserialize(''); |
|
|
|
const result = instance.provideCompletionItems({ text: '', prefix: '', value, wrapperClasses: [] }); |
|
|
|
const result = await instance.provideCompletionItems({ text: '', prefix: '', value, wrapperClasses: [] }); |
|
|
|
expect(result.context).toBeUndefined(); |
|
|
|
expect(result.context).toBeUndefined(); |
|
|
|
expect(result.refresher).toBeUndefined(); |
|
|
|
|
|
|
|
expect(result.suggestions).toMatchObject([ |
|
|
|
expect(result.suggestions).toMatchObject([ |
|
|
|
{ |
|
|
|
{ |
|
|
|
label: 'Functions', |
|
|
|
label: 'Functions', |
|
|
@ -39,17 +39,21 @@ describe('Language completion provider', () => { |
|
|
|
]); |
|
|
|
]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns default suggestions with history on emtpty context when history was provided', () => { |
|
|
|
it('returns default suggestions with history on empty context when history was provided', async () => { |
|
|
|
const instance = new LanguageProvider(datasource); |
|
|
|
const instance = new LanguageProvider(datasource); |
|
|
|
const value = Plain.deserialize(''); |
|
|
|
const value = Plain.deserialize(''); |
|
|
|
const history = [ |
|
|
|
const history: Array<HistoryItem<PromQuery>> = [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
ts: 0, |
|
|
|
query: { refId: '1', expr: 'metric' }, |
|
|
|
query: { refId: '1', expr: 'metric' }, |
|
|
|
}, |
|
|
|
}, |
|
|
|
]; |
|
|
|
]; |
|
|
|
const result = instance.provideCompletionItems({ text: '', prefix: '', value, wrapperClasses: [] }, { history }); |
|
|
|
const result = await instance.provideCompletionItems( |
|
|
|
|
|
|
|
{ text: '', prefix: '', value, wrapperClasses: [] }, |
|
|
|
|
|
|
|
{ history } |
|
|
|
|
|
|
|
); |
|
|
|
expect(result.context).toBeUndefined(); |
|
|
|
expect(result.context).toBeUndefined(); |
|
|
|
expect(result.refresher).toBeUndefined(); |
|
|
|
|
|
|
|
expect(result.suggestions).toMatchObject([ |
|
|
|
expect(result.suggestions).toMatchObject([ |
|
|
|
{ |
|
|
|
{ |
|
|
|
label: 'History', |
|
|
|
label: 'History', |
|
|
@ -67,17 +71,16 @@ describe('Language completion provider', () => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('range suggestions', () => { |
|
|
|
describe('range suggestions', () => { |
|
|
|
it('returns range suggestions in range context', () => { |
|
|
|
it('returns range suggestions in range context', async () => { |
|
|
|
const instance = new LanguageProvider(datasource); |
|
|
|
const instance = new LanguageProvider(datasource); |
|
|
|
const value = Plain.deserialize('1'); |
|
|
|
const value = Plain.deserialize('1'); |
|
|
|
const result = instance.provideCompletionItems({ |
|
|
|
const result = await instance.provideCompletionItems({ |
|
|
|
text: '1', |
|
|
|
text: '1', |
|
|
|
prefix: '1', |
|
|
|
prefix: '1', |
|
|
|
value, |
|
|
|
value, |
|
|
|
wrapperClasses: ['context-range'], |
|
|
|
wrapperClasses: ['context-range'], |
|
|
|
}); |
|
|
|
}); |
|
|
|
expect(result.context).toBe('context-range'); |
|
|
|
expect(result.context).toBe('context-range'); |
|
|
|
expect(result.refresher).toBeUndefined(); |
|
|
|
|
|
|
|
expect(result.suggestions).toMatchObject([ |
|
|
|
expect(result.suggestions).toMatchObject([ |
|
|
|
{ |
|
|
|
{ |
|
|
|
items: [ |
|
|
|
items: [ |
|
|
@ -96,12 +99,12 @@ describe('Language completion provider', () => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('metric suggestions', () => { |
|
|
|
describe('metric suggestions', () => { |
|
|
|
it('returns metrics and function suggestions in an unknown context', () => { |
|
|
|
it('returns metrics and function suggestions in an unknown context', async () => { |
|
|
|
const instance = new LanguageProvider(datasource, { metrics: ['foo', 'bar'] }); |
|
|
|
const instance = new LanguageProvider(datasource, { metrics: ['foo', 'bar'] }); |
|
|
|
const value = Plain.deserialize('a'); |
|
|
|
let value = Plain.deserialize('a'); |
|
|
|
const result = instance.provideCompletionItems({ text: 'a', prefix: 'a', value, wrapperClasses: [] }); |
|
|
|
value = value.setSelection({ anchor: { offset: 1 }, focus: { offset: 1 } }); |
|
|
|
|
|
|
|
const result = await instance.provideCompletionItems({ text: 'a', prefix: 'a', value, wrapperClasses: [] }); |
|
|
|
expect(result.context).toBeUndefined(); |
|
|
|
expect(result.context).toBeUndefined(); |
|
|
|
expect(result.refresher).toBeUndefined(); |
|
|
|
|
|
|
|
expect(result.suggestions).toMatchObject([ |
|
|
|
expect(result.suggestions).toMatchObject([ |
|
|
|
{ |
|
|
|
{ |
|
|
|
label: 'Functions', |
|
|
|
label: 'Functions', |
|
|
@ -112,12 +115,11 @@ describe('Language completion provider', () => { |
|
|
|
]); |
|
|
|
]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns metrics and function suggestions after a binary operator', () => { |
|
|
|
it('returns metrics and function suggestions after a binary operator', async () => { |
|
|
|
const instance = new LanguageProvider(datasource, { metrics: ['foo', 'bar'] }); |
|
|
|
const instance = new LanguageProvider(datasource, { metrics: ['foo', 'bar'] }); |
|
|
|
const value = Plain.deserialize('*'); |
|
|
|
const value = Plain.deserialize('*'); |
|
|
|
const result = instance.provideCompletionItems({ text: '*', prefix: '', value, wrapperClasses: [] }); |
|
|
|
const result = await instance.provideCompletionItems({ text: '*', prefix: '', value, wrapperClasses: [] }); |
|
|
|
expect(result.context).toBeUndefined(); |
|
|
|
expect(result.context).toBeUndefined(); |
|
|
|
expect(result.refresher).toBeUndefined(); |
|
|
|
|
|
|
|
expect(result.suggestions).toMatchObject([ |
|
|
|
expect(result.suggestions).toMatchObject([ |
|
|
|
{ |
|
|
|
{ |
|
|
|
label: 'Functions', |
|
|
|
label: 'Functions', |
|
|
@ -128,34 +130,30 @@ describe('Language completion provider', () => { |
|
|
|
]); |
|
|
|
]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns no suggestions at the beginning of a non-empty function', () => { |
|
|
|
it('returns no suggestions at the beginning of a non-empty function', async () => { |
|
|
|
const instance = new LanguageProvider(datasource, { metrics: ['foo', 'bar'] }); |
|
|
|
const instance = new LanguageProvider(datasource, { metrics: ['foo', 'bar'] }); |
|
|
|
const value = Plain.deserialize('sum(up)'); |
|
|
|
const value = Plain.deserialize('sum(up)'); |
|
|
|
const range = value.selection.merge({ |
|
|
|
const ed = new SlateEditor({ value }); |
|
|
|
anchorOffset: 4, |
|
|
|
|
|
|
|
}); |
|
|
|
const valueWithSelection = ed.moveForward(4).value; |
|
|
|
const valueWithSelection = value.change().select(range).value; |
|
|
|
const result = await instance.provideCompletionItems({ |
|
|
|
const result = instance.provideCompletionItems({ |
|
|
|
|
|
|
|
text: '', |
|
|
|
text: '', |
|
|
|
prefix: '', |
|
|
|
prefix: '', |
|
|
|
value: valueWithSelection, |
|
|
|
value: valueWithSelection, |
|
|
|
wrapperClasses: [], |
|
|
|
wrapperClasses: [], |
|
|
|
}); |
|
|
|
}); |
|
|
|
expect(result.context).toBeUndefined(); |
|
|
|
expect(result.context).toBeUndefined(); |
|
|
|
expect(result.refresher).toBeUndefined(); |
|
|
|
|
|
|
|
expect(result.suggestions.length).toEqual(0); |
|
|
|
expect(result.suggestions.length).toEqual(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('label suggestions', () => { |
|
|
|
describe('label suggestions', () => { |
|
|
|
it('returns default label suggestions on label context and no metric', () => { |
|
|
|
it('returns default label suggestions on label context and no metric', async () => { |
|
|
|
const instance = new LanguageProvider(datasource); |
|
|
|
const instance = new LanguageProvider(datasource); |
|
|
|
const value = Plain.deserialize('{}'); |
|
|
|
const value = Plain.deserialize('{}'); |
|
|
|
const range = value.selection.merge({ |
|
|
|
const ed = new SlateEditor({ value }); |
|
|
|
anchorOffset: 1, |
|
|
|
const valueWithSelection = ed.moveForward(1).value; |
|
|
|
}); |
|
|
|
const result = await instance.provideCompletionItems({ |
|
|
|
const valueWithSelection = value.change().select(range).value; |
|
|
|
|
|
|
|
const result = instance.provideCompletionItems({ |
|
|
|
|
|
|
|
text: '', |
|
|
|
text: '', |
|
|
|
prefix: '', |
|
|
|
prefix: '', |
|
|
|
wrapperClasses: ['context-labels'], |
|
|
|
wrapperClasses: ['context-labels'], |
|
|
@ -165,14 +163,16 @@ describe('Language completion provider', () => { |
|
|
|
expect(result.suggestions).toEqual([{ items: [{ label: 'job' }, { label: 'instance' }], label: 'Labels' }]); |
|
|
|
expect(result.suggestions).toEqual([{ items: [{ label: 'job' }, { label: 'instance' }], label: 'Labels' }]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns label suggestions on label context and metric', () => { |
|
|
|
it('returns label suggestions on label context and metric', async () => { |
|
|
|
const instance = new LanguageProvider(datasource, { labelKeys: { '{__name__="metric"}': ['bar'] } }); |
|
|
|
const datasources: PrometheusDatasource = ({ |
|
|
|
|
|
|
|
metadataRequest: () => ({ data: { data: [{ __name__: 'metric', bar: 'bazinga' }] as any[] } }), |
|
|
|
|
|
|
|
getTimeRange: () => ({ start: 0, end: 1 }), |
|
|
|
|
|
|
|
} as any) as PrometheusDatasource; |
|
|
|
|
|
|
|
const instance = new LanguageProvider(datasources, { labelKeys: { '{__name__="metric"}': ['bar'] } }); |
|
|
|
const value = Plain.deserialize('metric{}'); |
|
|
|
const value = Plain.deserialize('metric{}'); |
|
|
|
const range = value.selection.merge({ |
|
|
|
const ed = new SlateEditor({ value }); |
|
|
|
anchorOffset: 7, |
|
|
|
const valueWithSelection = ed.moveForward(7).value; |
|
|
|
}); |
|
|
|
const result = await instance.provideCompletionItems({ |
|
|
|
const valueWithSelection = value.change().select(range).value; |
|
|
|
|
|
|
|
const result = instance.provideCompletionItems({ |
|
|
|
|
|
|
|
text: '', |
|
|
|
text: '', |
|
|
|
prefix: '', |
|
|
|
prefix: '', |
|
|
|
wrapperClasses: ['context-labels'], |
|
|
|
wrapperClasses: ['context-labels'], |
|
|
@ -182,16 +182,32 @@ describe('Language completion provider', () => { |
|
|
|
expect(result.suggestions).toEqual([{ items: [{ label: 'bar' }], label: 'Labels' }]); |
|
|
|
expect(result.suggestions).toEqual([{ items: [{ label: 'bar' }], label: 'Labels' }]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns label suggestions on label context but leaves out labels that already exist', () => { |
|
|
|
it('returns label suggestions on label context but leaves out labels that already exist', async () => { |
|
|
|
const instance = new LanguageProvider(datasource, { |
|
|
|
const datasources: PrometheusDatasource = ({ |
|
|
|
labelKeys: { '{job1="foo",job2!="foo",job3=~"foo"}': ['bar', 'job1', 'job2', 'job3'] }, |
|
|
|
metadataRequest: () => ({ |
|
|
|
}); |
|
|
|
data: { |
|
|
|
const value = Plain.deserialize('{job1="foo",job2!="foo",job3=~"foo",}'); |
|
|
|
data: [ |
|
|
|
const range = value.selection.merge({ |
|
|
|
{ |
|
|
|
anchorOffset: 36, |
|
|
|
__name__: 'metric', |
|
|
|
|
|
|
|
bar: 'asdasd', |
|
|
|
|
|
|
|
job1: 'dsadsads', |
|
|
|
|
|
|
|
job2: 'fsfsdfds', |
|
|
|
|
|
|
|
job3: 'dsadsad', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
getTimeRange: () => ({ start: 0, end: 1 }), |
|
|
|
|
|
|
|
} as any) as PrometheusDatasource; |
|
|
|
|
|
|
|
const instance = new LanguageProvider(datasources, { |
|
|
|
|
|
|
|
labelKeys: { |
|
|
|
|
|
|
|
'{job1="foo",job2!="foo",job3=~"foo",__name__="metric"}': ['bar', 'job1', 'job2', 'job3', '__name__'], |
|
|
|
|
|
|
|
}, |
|
|
|
}); |
|
|
|
}); |
|
|
|
const valueWithSelection = value.change().select(range).value; |
|
|
|
const value = Plain.deserialize('{job1="foo",job2!="foo",job3=~"foo",__name__="metric",}'); |
|
|
|
const result = instance.provideCompletionItems({ |
|
|
|
const ed = new SlateEditor({ value }); |
|
|
|
|
|
|
|
const valueWithSelection = ed.moveForward(54).value; |
|
|
|
|
|
|
|
const result = await instance.provideCompletionItems({ |
|
|
|
text: '', |
|
|
|
text: '', |
|
|
|
prefix: '', |
|
|
|
prefix: '', |
|
|
|
wrapperClasses: ['context-labels'], |
|
|
|
wrapperClasses: ['context-labels'], |
|
|
@ -201,15 +217,15 @@ describe('Language completion provider', () => { |
|
|
|
expect(result.suggestions).toEqual([{ items: [{ label: 'bar' }], label: 'Labels' }]); |
|
|
|
expect(result.suggestions).toEqual([{ items: [{ label: 'bar' }], label: 'Labels' }]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns label value suggestions inside a label value context after a negated matching operator', () => { |
|
|
|
it('returns label value suggestions inside a label value context after a negated matching operator', async () => { |
|
|
|
const instance = new LanguageProvider(datasource, { |
|
|
|
const instance = new LanguageProvider(datasource, { |
|
|
|
labelKeys: { '{}': ['label'] }, |
|
|
|
labelKeys: { '{}': ['label'] }, |
|
|
|
labelValues: { '{}': { label: ['a', 'b', 'c'] } }, |
|
|
|
labelValues: { '{}': { label: ['a', 'b', 'c'] } }, |
|
|
|
}); |
|
|
|
}); |
|
|
|
const value = Plain.deserialize('{label!=}'); |
|
|
|
const value = Plain.deserialize('{label!=}'); |
|
|
|
const range = value.selection.merge({ anchorOffset: 8 }); |
|
|
|
const ed = new SlateEditor({ value }); |
|
|
|
const valueWithSelection = value.change().select(range).value; |
|
|
|
const valueWithSelection = ed.moveForward(8).value; |
|
|
|
const result = instance.provideCompletionItems({ |
|
|
|
const result = await instance.provideCompletionItems({ |
|
|
|
text: '!=', |
|
|
|
text: '!=', |
|
|
|
prefix: '', |
|
|
|
prefix: '', |
|
|
|
wrapperClasses: ['context-labels'], |
|
|
|
wrapperClasses: ['context-labels'], |
|
|
@ -225,35 +241,30 @@ describe('Language completion provider', () => { |
|
|
|
]); |
|
|
|
]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns a refresher on label context and unavailable metric', () => { |
|
|
|
it('returns a refresher on label context and unavailable metric', async () => { |
|
|
|
const instance = new LanguageProvider(datasource, { labelKeys: { '{__name__="foo"}': ['bar'] } }); |
|
|
|
const instance = new LanguageProvider(datasource, { labelKeys: { '{__name__="foo"}': ['bar'] } }); |
|
|
|
const value = Plain.deserialize('metric{}'); |
|
|
|
const value = Plain.deserialize('metric{}'); |
|
|
|
const range = value.selection.merge({ |
|
|
|
const ed = new SlateEditor({ value }); |
|
|
|
anchorOffset: 7, |
|
|
|
const valueWithSelection = ed.moveForward(7).value; |
|
|
|
}); |
|
|
|
const result = await instance.provideCompletionItems({ |
|
|
|
const valueWithSelection = value.change().select(range).value; |
|
|
|
|
|
|
|
const result = instance.provideCompletionItems({ |
|
|
|
|
|
|
|
text: '', |
|
|
|
text: '', |
|
|
|
prefix: '', |
|
|
|
prefix: '', |
|
|
|
wrapperClasses: ['context-labels'], |
|
|
|
wrapperClasses: ['context-labels'], |
|
|
|
value: valueWithSelection, |
|
|
|
value: valueWithSelection, |
|
|
|
}); |
|
|
|
}); |
|
|
|
expect(result.context).toBeUndefined(); |
|
|
|
expect(result.context).toBeUndefined(); |
|
|
|
expect(result.refresher).toBeInstanceOf(Promise); |
|
|
|
|
|
|
|
expect(result.suggestions).toEqual([]); |
|
|
|
expect(result.suggestions).toEqual([]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns label values on label context when given a metric and a label key', () => { |
|
|
|
it('returns label values on label context when given a metric and a label key', async () => { |
|
|
|
const instance = new LanguageProvider(datasource, { |
|
|
|
const instance = new LanguageProvider(datasource, { |
|
|
|
labelKeys: { '{__name__="metric"}': ['bar'] }, |
|
|
|
labelKeys: { '{__name__="metric"}': ['bar'] }, |
|
|
|
labelValues: { '{__name__="metric"}': { bar: ['baz'] } }, |
|
|
|
labelValues: { '{__name__="metric"}': { bar: ['baz'] } }, |
|
|
|
}); |
|
|
|
}); |
|
|
|
const value = Plain.deserialize('metric{bar=ba}'); |
|
|
|
const value = Plain.deserialize('metric{bar=ba}'); |
|
|
|
const range = value.selection.merge({ |
|
|
|
const ed = new SlateEditor({ value }); |
|
|
|
anchorOffset: 13, |
|
|
|
const valueWithSelection = ed.moveForward(13).value; |
|
|
|
}); |
|
|
|
const result = await instance.provideCompletionItems({ |
|
|
|
const valueWithSelection = value.change().select(range).value; |
|
|
|
|
|
|
|
const result = instance.provideCompletionItems({ |
|
|
|
|
|
|
|
text: '=ba', |
|
|
|
text: '=ba', |
|
|
|
prefix: 'ba', |
|
|
|
prefix: 'ba', |
|
|
|
wrapperClasses: ['context-labels'], |
|
|
|
wrapperClasses: ['context-labels'], |
|
|
@ -264,14 +275,12 @@ describe('Language completion provider', () => { |
|
|
|
expect(result.suggestions).toEqual([{ items: [{ label: 'baz' }], label: 'Label values for "bar"' }]); |
|
|
|
expect(result.suggestions).toEqual([{ items: [{ label: 'baz' }], label: 'Label values for "bar"' }]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns label suggestions on aggregation context and metric w/ selector', () => { |
|
|
|
it('returns label suggestions on aggregation context and metric w/ selector', async () => { |
|
|
|
const instance = new LanguageProvider(datasource, { labelKeys: { '{__name__="metric",foo="xx"}': ['bar'] } }); |
|
|
|
const instance = new LanguageProvider(datasource, { labelKeys: { '{__name__="metric",foo="xx"}': ['bar'] } }); |
|
|
|
const value = Plain.deserialize('sum(metric{foo="xx"}) by ()'); |
|
|
|
const value = Plain.deserialize('sum(metric{foo="xx"}) by ()'); |
|
|
|
const range = value.selection.merge({ |
|
|
|
const ed = new SlateEditor({ value }); |
|
|
|
anchorOffset: 26, |
|
|
|
const valueWithSelection = ed.moveForward(26).value; |
|
|
|
}); |
|
|
|
const result = await instance.provideCompletionItems({ |
|
|
|
const valueWithSelection = value.change().select(range).value; |
|
|
|
|
|
|
|
const result = instance.provideCompletionItems({ |
|
|
|
|
|
|
|
text: '', |
|
|
|
text: '', |
|
|
|
prefix: '', |
|
|
|
prefix: '', |
|
|
|
wrapperClasses: ['context-aggregation'], |
|
|
|
wrapperClasses: ['context-aggregation'], |
|
|
@ -281,14 +290,12 @@ describe('Language completion provider', () => { |
|
|
|
expect(result.suggestions).toEqual([{ items: [{ label: 'bar' }], label: 'Labels' }]); |
|
|
|
expect(result.suggestions).toEqual([{ items: [{ label: 'bar' }], label: 'Labels' }]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns label suggestions on aggregation context and metric w/o selector', () => { |
|
|
|
it('returns label suggestions on aggregation context and metric w/o selector', async () => { |
|
|
|
const instance = new LanguageProvider(datasource, { labelKeys: { '{__name__="metric"}': ['bar'] } }); |
|
|
|
const instance = new LanguageProvider(datasource, { labelKeys: { '{__name__="metric"}': ['bar'] } }); |
|
|
|
const value = Plain.deserialize('sum(metric) by ()'); |
|
|
|
const value = Plain.deserialize('sum(metric) by ()'); |
|
|
|
const range = value.selection.merge({ |
|
|
|
const ed = new SlateEditor({ value }); |
|
|
|
anchorOffset: 16, |
|
|
|
const valueWithSelection = ed.moveForward(16).value; |
|
|
|
}); |
|
|
|
const result = await instance.provideCompletionItems({ |
|
|
|
const valueWithSelection = value.change().select(range).value; |
|
|
|
|
|
|
|
const result = instance.provideCompletionItems({ |
|
|
|
|
|
|
|
text: '', |
|
|
|
text: '', |
|
|
|
prefix: '', |
|
|
|
prefix: '', |
|
|
|
wrapperClasses: ['context-aggregation'], |
|
|
|
wrapperClasses: ['context-aggregation'], |
|
|
@ -298,15 +305,16 @@ describe('Language completion provider', () => { |
|
|
|
expect(result.suggestions).toEqual([{ items: [{ label: 'bar' }], label: 'Labels' }]); |
|
|
|
expect(result.suggestions).toEqual([{ items: [{ label: 'bar' }], label: 'Labels' }]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns label suggestions inside a multi-line aggregation context', () => { |
|
|
|
it('returns label suggestions inside a multi-line aggregation context', async () => { |
|
|
|
const instance = new LanguageProvider(datasource, { |
|
|
|
const instance = new LanguageProvider(datasource, { |
|
|
|
labelKeys: { '{__name__="metric"}': ['label1', 'label2', 'label3'] }, |
|
|
|
labelKeys: { '{__name__="metric"}': ['label1', 'label2', 'label3'] }, |
|
|
|
}); |
|
|
|
}); |
|
|
|
const value = Plain.deserialize('sum(\nmetric\n)\nby ()'); |
|
|
|
const value = Plain.deserialize('sum(\nmetric\n)\nby ()'); |
|
|
|
const aggregationTextBlock = value.document.getBlocksAsArray()[3]; |
|
|
|
const aggregationTextBlock = value.document.getBlocks().get(3); |
|
|
|
const range = value.selection.moveToStartOf(aggregationTextBlock).merge({ anchorOffset: 4 }); |
|
|
|
const ed = new SlateEditor({ value }); |
|
|
|
const valueWithSelection = value.change().select(range).value; |
|
|
|
ed.moveToStartOfNode(aggregationTextBlock); |
|
|
|
const result = instance.provideCompletionItems({ |
|
|
|
const valueWithSelection = ed.moveForward(4).value; |
|
|
|
|
|
|
|
const result = await instance.provideCompletionItems({ |
|
|
|
text: '', |
|
|
|
text: '', |
|
|
|
prefix: '', |
|
|
|
prefix: '', |
|
|
|
wrapperClasses: ['context-aggregation'], |
|
|
|
wrapperClasses: ['context-aggregation'], |
|
|
@ -321,16 +329,14 @@ describe('Language completion provider', () => { |
|
|
|
]); |
|
|
|
]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns label suggestions inside an aggregation context with a range vector', () => { |
|
|
|
it('returns label suggestions inside an aggregation context with a range vector', async () => { |
|
|
|
const instance = new LanguageProvider(datasource, { |
|
|
|
const instance = new LanguageProvider(datasource, { |
|
|
|
labelKeys: { '{__name__="metric"}': ['label1', 'label2', 'label3'] }, |
|
|
|
labelKeys: { '{__name__="metric"}': ['label1', 'label2', 'label3'] }, |
|
|
|
}); |
|
|
|
}); |
|
|
|
const value = Plain.deserialize('sum(rate(metric[1h])) by ()'); |
|
|
|
const value = Plain.deserialize('sum(rate(metric[1h])) by ()'); |
|
|
|
const range = value.selection.merge({ |
|
|
|
const ed = new SlateEditor({ value }); |
|
|
|
anchorOffset: 26, |
|
|
|
const valueWithSelection = ed.moveForward(26).value; |
|
|
|
}); |
|
|
|
const result = await instance.provideCompletionItems({ |
|
|
|
const valueWithSelection = value.change().select(range).value; |
|
|
|
|
|
|
|
const result = instance.provideCompletionItems({ |
|
|
|
|
|
|
|
text: '', |
|
|
|
text: '', |
|
|
|
prefix: '', |
|
|
|
prefix: '', |
|
|
|
wrapperClasses: ['context-aggregation'], |
|
|
|
wrapperClasses: ['context-aggregation'], |
|
|
@ -345,16 +351,14 @@ describe('Language completion provider', () => { |
|
|
|
]); |
|
|
|
]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns label suggestions inside an aggregation context with a range vector and label', () => { |
|
|
|
it('returns label suggestions inside an aggregation context with a range vector and label', async () => { |
|
|
|
const instance = new LanguageProvider(datasource, { |
|
|
|
const instance = new LanguageProvider(datasource, { |
|
|
|
labelKeys: { '{__name__="metric",label1="value"}': ['label1', 'label2', 'label3'] }, |
|
|
|
labelKeys: { '{__name__="metric",label1="value"}': ['label1', 'label2', 'label3'] }, |
|
|
|
}); |
|
|
|
}); |
|
|
|
const value = Plain.deserialize('sum(rate(metric{label1="value"}[1h])) by ()'); |
|
|
|
const value = Plain.deserialize('sum(rate(metric{label1="value"}[1h])) by ()'); |
|
|
|
const range = value.selection.merge({ |
|
|
|
const ed = new SlateEditor({ value }); |
|
|
|
anchorOffset: 42, |
|
|
|
const valueWithSelection = ed.moveForward(42).value; |
|
|
|
}); |
|
|
|
const result = await instance.provideCompletionItems({ |
|
|
|
const valueWithSelection = value.change().select(range).value; |
|
|
|
|
|
|
|
const result = instance.provideCompletionItems({ |
|
|
|
|
|
|
|
text: '', |
|
|
|
text: '', |
|
|
|
prefix: '', |
|
|
|
prefix: '', |
|
|
|
wrapperClasses: ['context-aggregation'], |
|
|
|
wrapperClasses: ['context-aggregation'], |
|
|
@ -369,16 +373,14 @@ describe('Language completion provider', () => { |
|
|
|
]); |
|
|
|
]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns no suggestions inside an unclear aggregation context using alternate syntax', () => { |
|
|
|
it('returns no suggestions inside an unclear aggregation context using alternate syntax', async () => { |
|
|
|
const instance = new LanguageProvider(datasource, { |
|
|
|
const instance = new LanguageProvider(datasource, { |
|
|
|
labelKeys: { '{__name__="metric"}': ['label1', 'label2', 'label3'] }, |
|
|
|
labelKeys: { '{__name__="metric"}': ['label1', 'label2', 'label3'] }, |
|
|
|
}); |
|
|
|
}); |
|
|
|
const value = Plain.deserialize('sum by ()'); |
|
|
|
const value = Plain.deserialize('sum by ()'); |
|
|
|
const range = value.selection.merge({ |
|
|
|
const ed = new SlateEditor({ value }); |
|
|
|
anchorOffset: 8, |
|
|
|
const valueWithSelection = ed.moveForward(8).value; |
|
|
|
}); |
|
|
|
const result = await instance.provideCompletionItems({ |
|
|
|
const valueWithSelection = value.change().select(range).value; |
|
|
|
|
|
|
|
const result = instance.provideCompletionItems({ |
|
|
|
|
|
|
|
text: '', |
|
|
|
text: '', |
|
|
|
prefix: '', |
|
|
|
prefix: '', |
|
|
|
wrapperClasses: ['context-aggregation'], |
|
|
|
wrapperClasses: ['context-aggregation'], |
|
|
@ -388,16 +390,14 @@ describe('Language completion provider', () => { |
|
|
|
expect(result.suggestions).toEqual([]); |
|
|
|
expect(result.suggestions).toEqual([]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('returns label suggestions inside an aggregation context using alternate syntax', () => { |
|
|
|
it('returns label suggestions inside an aggregation context using alternate syntax', async () => { |
|
|
|
const instance = new LanguageProvider(datasource, { |
|
|
|
const instance = new LanguageProvider(datasource, { |
|
|
|
labelKeys: { '{__name__="metric"}': ['label1', 'label2', 'label3'] }, |
|
|
|
labelKeys: { '{__name__="metric"}': ['label1', 'label2', 'label3'] }, |
|
|
|
}); |
|
|
|
}); |
|
|
|
const value = Plain.deserialize('sum by () (metric)'); |
|
|
|
const value = Plain.deserialize('sum by () (metric)'); |
|
|
|
const range = value.selection.merge({ |
|
|
|
const ed = new SlateEditor({ value }); |
|
|
|
anchorOffset: 8, |
|
|
|
const valueWithSelection = ed.moveForward(8).value; |
|
|
|
}); |
|
|
|
const result = await instance.provideCompletionItems({ |
|
|
|
const valueWithSelection = value.change().select(range).value; |
|
|
|
|
|
|
|
const result = instance.provideCompletionItems({ |
|
|
|
|
|
|
|
text: '', |
|
|
|
text: '', |
|
|
|
prefix: '', |
|
|
|
prefix: '', |
|
|
|
wrapperClasses: ['context-aggregation'], |
|
|
|
wrapperClasses: ['context-aggregation'], |
|
|
|