diff --git a/.betterer.results b/.betterer.results index 53336350c47..7dfbd680c2b 100644 --- a/.betterer.results +++ b/.betterer.results @@ -77,9 +77,6 @@ exports[`no enzyme tests`] = { "public/app/plugins/datasource/cloudwatch/components/ConfigEditor.test.tsx:4057721851": [ [1, 19, 13, "RegExp match", "2409514259"] ], - "public/app/plugins/datasource/loki/components/LokiExploreQueryEditor.test.tsx:2984948507": [ - [0, 26, 13, "RegExp match", "2409514259"] - ], "public/app/plugins/datasource/loki/components/LokiQueryEditor.test.tsx:146069464": [ [0, 19, 13, "RegExp match", "2409514259"] ], diff --git a/public/app/plugins/datasource/loki/components/LokiExploreQueryEditor.test.tsx b/public/app/plugins/datasource/loki/components/LokiExploreQueryEditor.test.tsx index 3effa1a57a4..94f18316adc 100644 --- a/public/app/plugins/datasource/loki/components/LokiExploreQueryEditor.test.tsx +++ b/public/app/plugins/datasource/loki/components/LokiExploreQueryEditor.test.tsx @@ -1,6 +1,5 @@ -import { mount, shallow } from 'enzyme'; +import { render, screen } from '@testing-library/react'; import React from 'react'; -import { act } from 'react-dom/test-utils'; import { LoadingState, PanelData, toUtc, TimeRange, HistoryItem } from '@grafana/data'; import { TemplateSrv } from '@grafana/runtime'; @@ -11,10 +10,15 @@ import { createLokiDatasource } from '../mocks'; import { LokiQuery } from '../types'; import { LokiExploreQueryEditor, Props } from './LokiExploreQueryEditor'; -import { LokiOptionFields } from './LokiOptionFields'; -const setup = (renderMethod: (c: JSX.Element) => ReturnType | ReturnType) => { - const datasource: LokiDatasource = createLokiDatasource({} as unknown as TemplateSrv); +const setup = () => { + const mockTemplateSrv: TemplateSrv = { + getVariables: jest.fn(), + replace: jest.fn(), + containsTemplate: jest.fn(), + updateTimeRange: jest.fn(), + }; + const datasource: LokiDatasource = createLokiDatasource(mockTemplateSrv); datasource.languageProvider = new LokiLanguageProvider(datasource); jest.spyOn(datasource, 'metadataRequest').mockResolvedValue([]); @@ -73,7 +77,7 @@ const setup = (renderMethod: (c: JSX.Element) => ReturnType | Re onRunQuery, }; - return renderMethod(); + render(); }; describe('LokiExploreQueryEditor', () => { @@ -87,16 +91,12 @@ describe('LokiExploreQueryEditor', () => { window.getSelection = originalGetSelection; }); - it('should render component', () => { - const wrapper = setup(shallow); - expect(wrapper).toMatchSnapshot(); + it('should render component without throwing an error', () => { + expect(() => setup()).not.toThrow(); }); it('should render LokiQueryField with ExtraFieldElement when ExploreMode is set to Logs', async () => { - // @ts-ignore strict null error TS2345: Argument of type '() => Promise' is not assignable to parameter of type '() => void | undefined'. - await act(async () => { - const wrapper = setup(mount); - expect(wrapper.find(LokiOptionFields).length).toBe(1); - }); + setup(); + expect(screen.getByLabelText('Loki extra field')).toBeInTheDocument(); }); }); diff --git a/public/app/plugins/datasource/loki/components/__snapshots__/LokiExploreQueryEditor.test.tsx.snap b/public/app/plugins/datasource/loki/components/__snapshots__/LokiExploreQueryEditor.test.tsx.snap deleted file mode 100644 index 3f153c25092..00000000000 --- a/public/app/plugins/datasource/loki/components/__snapshots__/LokiExploreQueryEditor.test.tsx.snap +++ /dev/null @@ -1,353 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`LokiExploreQueryEditor should render component 1`] = ` - - } - data={ - Object { - "request": Object { - "app": "Grafana", - "dashboardId": 1, - "interval": "1s", - "intervalMs": 1000, - "panelId": 1, - "range": Object { - "from": "2020-01-01T00:00:00.000Z", - "raw": Object { - "from": "2020-01-01T00:00:00.000Z", - "to": "2020-01-02T00:00:00.000Z", - }, - "to": "2020-01-02T00:00:00.000Z", - }, - "requestId": "1", - "scopedVars": Object {}, - "startTime": 0, - "targets": Array [], - "timezone": "GMT", - }, - "series": Array [], - "state": "NotStarted", - "timeRange": Object { - "from": "2020-01-01T00:00:00.000Z", - "raw": Object { - "from": "2020-01-01T00:00:00.000Z", - "to": "2020-01-02T00:00:00.000Z", - }, - "to": "2020-01-02T00:00:00.000Z", - }, - } - } - data-testid="loki-editor-explore" - datasource={ - LokiDatasource { - "annotations": Object { - "QueryEditor": Object { - "$$typeof": Symbol(react.memo), - "compare": null, - "type": [Function], - }, - }, - "getLogRowContext": [Function], - "id": 0, - "instanceSettings": Object { - "access": "direct", - "id": 0, - "jsonData": Object { - "maxLines": "20", - }, - "meta": Object { - "baseUrl": "", - "id": "id", - "info": Object { - "author": Object { - "name": "Test", - }, - "description": "", - "links": Array [], - "logos": Object { - "large": "", - "small": "", - }, - "screenshots": Array [], - "updated": "", - "version": "", - }, - "module": "", - "name": "name", - "type": "datasource", - }, - "name": "", - "readOnly": false, - "type": "", - "uid": "", - "url": "myloggingurl", - }, - "languageProvider": LokiLanguageProvider { - "cleanText": [Function], - "datasource": [Circular], - "fetchSeries": [Function], - "fetchSeriesLabels": [Function], - "getBeginningCompletionItems": [Function], - "getPipeCompletionItem": [Function], - "getTermCompletionItems": [Function], - "labelFetchTs": 0, - "labelKeys": Array [], - "labelsCache": LRUCache { - "allowStale": false, - "disposeAfter": null, - "disposed": null, - "fetchContext": undefined, - "fetchMethod": null, - "free": Stack { - "heap": Uint8Array [ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - ], - "length": 0, - }, - "head": 0, - "initialFill": 1, - "keyList": Array [ - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - ], - "keyMap": Map {}, - "max": 10, - "maxSize": 0, - "next": Uint8Array [ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - ], - "noDeleteOnFetchRejection": false, - "noDeleteOnStaleGet": false, - "noDisposeOnSet": false, - "noUpdateTTL": false, - "prev": Uint8Array [ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - ], - "size": 0, - "sizeCalculation": undefined, - "tail": 0, - "ttl": 0, - "ttlAutopurge": false, - "ttlResolution": 1, - "updateAgeOnGet": false, - "updateAgeOnHas": false, - "valList": Array [ - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - ], - }, - "lookupsDisabled": false, - "request": [Function], - "seriesCache": LRUCache { - "allowStale": false, - "disposeAfter": null, - "disposed": null, - "fetchContext": undefined, - "fetchMethod": null, - "free": Stack { - "heap": Uint8Array [ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - ], - "length": 0, - }, - "head": 0, - "initialFill": 1, - "keyList": Array [ - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - ], - "keyMap": Map {}, - "max": 10, - "maxSize": 0, - "next": Uint8Array [ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - ], - "noDeleteOnFetchRejection": false, - "noDeleteOnStaleGet": false, - "noDisposeOnSet": false, - "noUpdateTTL": false, - "prev": Uint8Array [ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - ], - "size": 0, - "sizeCalculation": undefined, - "tail": 0, - "ttl": 0, - "ttlAutopurge": false, - "ttlResolution": 1, - "updateAgeOnGet": false, - "updateAgeOnHas": false, - "valList": Array [ - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - ], - }, - "start": [Function], - "started": false, - }, - "maxLines": 20, - "meta": Object { - "baseUrl": "", - "id": "id", - "info": Object { - "author": Object { - "name": "Test", - }, - "description": "", - "links": Array [], - "logos": Object { - "large": "", - "small": "", - }, - "screenshots": Array [], - "updated": "", - "version": "", - }, - "module": "", - "name": "name", - "type": "datasource", - }, - "metadataRequest": [MockFunction], - "name": "", - "prepareLogRowContextQueryTarget": [Function], - "runLiveQuery": [Function], - "streamOptionsProvider": [Function], - "streams": LiveStreams { - "streams": Object {}, - }, - "templateSrv": Object {}, - "timeSrv": Object { - "timeRange": [Function], - }, - "type": "", - "uid": "", - "variables": LokiVariableSupport { - "datasource": [Circular], - "editor": [Function], - "query": [Function], - }, - } - } - history={Array []} - onBlur={[Function]} - onChange={[MockFunction]} - onRunQuery={[MockFunction]} - query={ - Object { - "expr": "", - "maxLines": 0, - "refId": "A", - } - } - range={ - Object { - "from": "2020-01-01T00:00:00.000Z", - "raw": Object { - "from": "2020-01-01T00:00:00.000Z", - "to": "2020-01-02T00:00:00.000Z", - }, - "to": "2020-01-02T00:00:00.000Z", - } - } -/> -`;