From f79b790ef68cb05f5ac6373c8c75aa99fec0b366 Mon Sep 17 00:00:00 2001 From: Michael Huynh Date: Sat, 3 Nov 2018 08:07:08 +0800 Subject: [PATCH] Add tests covering alternate syntax for aggregation contexts Related: #13690 --- .../specs/language_provider.test.ts | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/public/app/plugins/datasource/prometheus/specs/language_provider.test.ts b/public/app/plugins/datasource/prometheus/specs/language_provider.test.ts index 20e148efd57..784a8b59739 100644 --- a/public/app/plugins/datasource/prometheus/specs/language_provider.test.ts +++ b/public/app/plugins/datasource/prometheus/specs/language_provider.test.ts @@ -269,5 +269,48 @@ describe('Language completion provider', () => { }, ]); }); + + it('returns no suggestions inside an unclear aggregation context using alternate syntax', () => { + const instance = new LanguageProvider(datasource, { + labelKeys: { '{__name__="metric"}': ['label1', 'label2', 'label3'] }, + }); + const value = Plain.deserialize('sum by ()'); + const range = value.selection.merge({ + anchorOffset: 8, + }); + const valueWithSelection = value.change().select(range).value; + const result = instance.provideCompletionItems({ + text: '', + prefix: '', + wrapperClasses: ['context-aggregation'], + value: valueWithSelection, + }); + expect(result.context).toBe('context-aggregation'); + expect(result.suggestions).toEqual([]); + }); + + it('returns label suggestions inside an aggregation context using alternate syntax', () => { + const instance = new LanguageProvider(datasource, { + labelKeys: { '{__name__="metric"}': ['label1', 'label2', 'label3'] }, + }); + const value = Plain.deserialize('sum by () (metric)'); + const range = value.selection.merge({ + anchorOffset: 8, + }); + const valueWithSelection = value.change().select(range).value; + const result = instance.provideCompletionItems({ + text: '', + prefix: '', + wrapperClasses: ['context-aggregation'], + value: valueWithSelection, + }); + expect(result.context).toBe('context-aggregation'); + expect(result.suggestions).toEqual([ + { + items: [{ label: 'label1' }, { label: 'label2' }, { label: 'label3' }], + label: 'Labels', + }, + ]); + }); }); });