mirror of
https://github.com/grafana/grafana.git
synced 2025-09-26 16:23:48 +08:00
update LokiExploreQueryEditor test to RTL (#54644)
This commit is contained in:
@ -77,9 +77,6 @@ exports[`no enzyme tests`] = {
|
|||||||
"public/app/plugins/datasource/cloudwatch/components/ConfigEditor.test.tsx:4057721851": [
|
"public/app/plugins/datasource/cloudwatch/components/ConfigEditor.test.tsx:4057721851": [
|
||||||
[1, 19, 13, "RegExp match", "2409514259"]
|
[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": [
|
"public/app/plugins/datasource/loki/components/LokiQueryEditor.test.tsx:146069464": [
|
||||||
[0, 19, 13, "RegExp match", "2409514259"]
|
[0, 19, 13, "RegExp match", "2409514259"]
|
||||||
],
|
],
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { mount, shallow } from 'enzyme';
|
import { render, screen } from '@testing-library/react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { act } from 'react-dom/test-utils';
|
|
||||||
|
|
||||||
import { LoadingState, PanelData, toUtc, TimeRange, HistoryItem } from '@grafana/data';
|
import { LoadingState, PanelData, toUtc, TimeRange, HistoryItem } from '@grafana/data';
|
||||||
import { TemplateSrv } from '@grafana/runtime';
|
import { TemplateSrv } from '@grafana/runtime';
|
||||||
@ -11,10 +10,15 @@ import { createLokiDatasource } from '../mocks';
|
|||||||
import { LokiQuery } from '../types';
|
import { LokiQuery } from '../types';
|
||||||
|
|
||||||
import { LokiExploreQueryEditor, Props } from './LokiExploreQueryEditor';
|
import { LokiExploreQueryEditor, Props } from './LokiExploreQueryEditor';
|
||||||
import { LokiOptionFields } from './LokiOptionFields';
|
|
||||||
|
|
||||||
const setup = (renderMethod: (c: JSX.Element) => ReturnType<typeof shallow> | ReturnType<typeof mount>) => {
|
const setup = () => {
|
||||||
const datasource: LokiDatasource = createLokiDatasource({} as unknown as TemplateSrv);
|
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);
|
datasource.languageProvider = new LokiLanguageProvider(datasource);
|
||||||
jest.spyOn(datasource, 'metadataRequest').mockResolvedValue([]);
|
jest.spyOn(datasource, 'metadataRequest').mockResolvedValue([]);
|
||||||
|
|
||||||
@ -73,7 +77,7 @@ const setup = (renderMethod: (c: JSX.Element) => ReturnType<typeof shallow> | Re
|
|||||||
onRunQuery,
|
onRunQuery,
|
||||||
};
|
};
|
||||||
|
|
||||||
return renderMethod(<LokiExploreQueryEditor {...props} />);
|
render(<LokiExploreQueryEditor {...props} />);
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('LokiExploreQueryEditor', () => {
|
describe('LokiExploreQueryEditor', () => {
|
||||||
@ -87,16 +91,12 @@ describe('LokiExploreQueryEditor', () => {
|
|||||||
window.getSelection = originalGetSelection;
|
window.getSelection = originalGetSelection;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render component', () => {
|
it('should render component without throwing an error', () => {
|
||||||
const wrapper = setup(shallow);
|
expect(() => setup()).not.toThrow();
|
||||||
expect(wrapper).toMatchSnapshot();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render LokiQueryField with ExtraFieldElement when ExploreMode is set to Logs', async () => {
|
it('should render LokiQueryField with ExtraFieldElement when ExploreMode is set to Logs', async () => {
|
||||||
// @ts-ignore strict null error TS2345: Argument of type '() => Promise<void>' is not assignable to parameter of type '() => void | undefined'.
|
setup();
|
||||||
await act(async () => {
|
expect(screen.getByLabelText('Loki extra field')).toBeInTheDocument();
|
||||||
const wrapper = setup(mount);
|
|
||||||
expect(wrapper.find(LokiOptionFields).length).toBe(1);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,353 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`LokiExploreQueryEditor should render component 1`] = `
|
|
||||||
<LokiQueryField
|
|
||||||
ExtraFieldElement={
|
|
||||||
<LokiOptionFields
|
|
||||||
lineLimitValue="0"
|
|
||||||
onChange={[MockFunction]}
|
|
||||||
onRunQuery={[MockFunction]}
|
|
||||||
query={
|
|
||||||
Object {
|
|
||||||
"expr": "",
|
|
||||||
"maxLines": 0,
|
|
||||||
"refId": "A",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resolution={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",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
`;
|
|
Reference in New Issue
Block a user