|
|
|
@ -10,8 +10,6 @@ import { makeLogsQueryResponse, makeMetricsQueryResponse } from './spec/helper/q |
|
|
|
|
import { setupExplore, tearDown, waitForExplore } from './spec/helper/setup'; |
|
|
|
|
import { splitOpen } from './state/main'; |
|
|
|
|
|
|
|
|
|
type Mock = jest.Mock; |
|
|
|
|
|
|
|
|
|
jest.mock('app/core/core', () => { |
|
|
|
|
return { |
|
|
|
|
contextSrv: { |
|
|
|
@ -70,7 +68,7 @@ describe('Wrapper', () => { |
|
|
|
|
}), |
|
|
|
|
}; |
|
|
|
|
const { datasources } = setupExplore({ urlParams }); |
|
|
|
|
(datasources.loki.query as Mock).mockReturnValueOnce(makeLogsQueryResponse()); |
|
|
|
|
jest.mocked(datasources.loki.query).mockReturnValueOnce(makeLogsQueryResponse()); |
|
|
|
|
|
|
|
|
|
// Make sure we render the logs panel
|
|
|
|
|
await screen.findByText(/^Logs$/); |
|
|
|
@ -89,7 +87,7 @@ describe('Wrapper', () => { |
|
|
|
|
|
|
|
|
|
// We called the data source query method once
|
|
|
|
|
expect(datasources.loki.query).toBeCalledTimes(1); |
|
|
|
|
expect((datasources.loki.query as Mock).mock.calls[0][0]).toMatchObject({ |
|
|
|
|
expect(jest.mocked(datasources.loki.query).mock.calls[0][0]).toMatchObject({ |
|
|
|
|
targets: [{ expr: '{ label="value"}' }], |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
@ -97,11 +95,11 @@ describe('Wrapper', () => { |
|
|
|
|
it('handles url change and runs the new query', async () => { |
|
|
|
|
const urlParams = { left: JSON.stringify(['now-1h', 'now', 'loki', { expr: '{ label="value"}' }]) }; |
|
|
|
|
const { datasources } = setupExplore({ urlParams }); |
|
|
|
|
(datasources.loki.query as Mock).mockReturnValueOnce(makeLogsQueryResponse()); |
|
|
|
|
jest.mocked(datasources.loki.query).mockReturnValueOnce(makeLogsQueryResponse()); |
|
|
|
|
// Wait for rendering the logs
|
|
|
|
|
await screen.findByText(/custom log line/i); |
|
|
|
|
|
|
|
|
|
(datasources.loki.query as Mock).mockReturnValueOnce(makeLogsQueryResponse('different log')); |
|
|
|
|
jest.mocked(datasources.loki.query).mockReturnValueOnce(makeLogsQueryResponse('different log')); |
|
|
|
|
|
|
|
|
|
locationService.partial({ |
|
|
|
|
left: JSON.stringify(['now-1h', 'now', 'loki', { expr: '{ label="different"}' }]), |
|
|
|
@ -116,12 +114,12 @@ describe('Wrapper', () => { |
|
|
|
|
it('handles url change and runs the new query with different datasource', async () => { |
|
|
|
|
const urlParams = { left: JSON.stringify(['now-1h', 'now', 'loki', { expr: '{ label="value"}' }]) }; |
|
|
|
|
const { datasources } = setupExplore({ urlParams }); |
|
|
|
|
(datasources.loki.query as Mock).mockReturnValueOnce(makeLogsQueryResponse()); |
|
|
|
|
jest.mocked(datasources.loki.query).mockReturnValueOnce(makeLogsQueryResponse()); |
|
|
|
|
// Wait for rendering the logs
|
|
|
|
|
await screen.findByText(/custom log line/i); |
|
|
|
|
await screen.findByText(`loki Editor input: { label="value"}`); |
|
|
|
|
|
|
|
|
|
(datasources.elastic.query as Mock).mockReturnValueOnce(makeMetricsQueryResponse()); |
|
|
|
|
jest.mocked(datasources.elastic.query).mockReturnValueOnce(makeMetricsQueryResponse()); |
|
|
|
|
|
|
|
|
|
locationService.partial({ |
|
|
|
|
left: JSON.stringify(['now-1h', 'now', 'elastic', { expr: 'other query' }]), |
|
|
|
@ -136,7 +134,7 @@ describe('Wrapper', () => { |
|
|
|
|
it('handles changing the datasource manually', async () => { |
|
|
|
|
const urlParams = { left: JSON.stringify(['now-1h', 'now', 'loki', { expr: '{ label="value"}', refId: 'A' }]) }; |
|
|
|
|
const { datasources } = setupExplore({ urlParams }); |
|
|
|
|
(datasources.loki.query as Mock).mockReturnValueOnce(makeLogsQueryResponse()); |
|
|
|
|
jest.mocked(datasources.loki.query).mockReturnValueOnce(makeLogsQueryResponse()); |
|
|
|
|
await waitForExplore(); |
|
|
|
|
await changeDatasource('elastic'); |
|
|
|
|
|
|
|
|
@ -178,8 +176,8 @@ describe('Wrapper', () => { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const { datasources } = setupExplore({ urlParams }); |
|
|
|
|
(datasources.loki.query as Mock).mockReturnValueOnce(makeLogsQueryResponse()); |
|
|
|
|
(datasources.elastic.query as Mock).mockReturnValueOnce(makeLogsQueryResponse()); |
|
|
|
|
jest.mocked(datasources.loki.query).mockReturnValueOnce(makeLogsQueryResponse()); |
|
|
|
|
jest.mocked(datasources.elastic.query).mockReturnValueOnce(makeLogsQueryResponse()); |
|
|
|
|
|
|
|
|
|
// Make sure we render the logs panel
|
|
|
|
|
await waitFor(() => { |
|
|
|
@ -203,12 +201,12 @@ describe('Wrapper', () => { |
|
|
|
|
|
|
|
|
|
// We called the data source query method once
|
|
|
|
|
expect(datasources.loki.query).toBeCalledTimes(1); |
|
|
|
|
expect((datasources.loki.query as Mock).mock.calls[0][0]).toMatchObject({ |
|
|
|
|
expect(jest.mocked(datasources.loki.query).mock.calls[0][0]).toMatchObject({ |
|
|
|
|
targets: [{ expr: '{ label="value"}' }], |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
expect(datasources.elastic.query).toBeCalledTimes(1); |
|
|
|
|
expect((datasources.elastic.query as Mock).mock.calls[0][0]).toMatchObject({ |
|
|
|
|
expect(jest.mocked(datasources.elastic.query).mock.calls[0][0]).toMatchObject({ |
|
|
|
|
targets: [{ expr: 'error' }], |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
@ -233,8 +231,8 @@ describe('Wrapper', () => { |
|
|
|
|
left: JSON.stringify(['now-1h', 'now', 'loki', { expr: '{ label="value"}' }]), |
|
|
|
|
}; |
|
|
|
|
const { datasources } = setupExplore({ urlParams }); |
|
|
|
|
(datasources.loki.query as Mock).mockReturnValue(makeLogsQueryResponse()); |
|
|
|
|
(datasources.elastic.query as Mock).mockReturnValue(makeLogsQueryResponse()); |
|
|
|
|
jest.mocked(datasources.loki.query).mockReturnValue(makeLogsQueryResponse()); |
|
|
|
|
jest.mocked(datasources.elastic.query).mockReturnValue(makeLogsQueryResponse()); |
|
|
|
|
|
|
|
|
|
locationService.partial({ |
|
|
|
|
left: JSON.stringify(['now-1h', 'now', 'loki', { expr: '{ label="value"}' }]), |
|
|
|
@ -251,8 +249,8 @@ describe('Wrapper', () => { |
|
|
|
|
left: JSON.stringify(['now-1h', 'now', 'loki', { expr: '{ label="value"}' }]), |
|
|
|
|
}; |
|
|
|
|
const { datasources, store } = setupExplore({ urlParams }); |
|
|
|
|
(datasources.loki.query as Mock).mockReturnValue(makeLogsQueryResponse()); |
|
|
|
|
(datasources.elastic.query as Mock).mockReturnValue(makeLogsQueryResponse()); |
|
|
|
|
jest.mocked(datasources.loki.query).mockReturnValue(makeLogsQueryResponse()); |
|
|
|
|
jest.mocked(datasources.elastic.query).mockReturnValue(makeLogsQueryResponse()); |
|
|
|
|
|
|
|
|
|
// This is mainly to wait for render so that the left pane state is initialized as that is needed for splitOpen
|
|
|
|
|
// to work
|
|
|
|
@ -270,7 +268,7 @@ describe('Wrapper', () => { |
|
|
|
|
left: JSON.stringify(['now-1h', 'now', 'loki', { expr: '{ label="value"}' }]), |
|
|
|
|
}; |
|
|
|
|
const { datasources } = setupExplore({ urlParams }); |
|
|
|
|
(datasources.loki.query as Mock).mockReturnValue(makeLogsQueryResponse()); |
|
|
|
|
jest.mocked(datasources.loki.query).mockReturnValue(makeLogsQueryResponse()); |
|
|
|
|
// This is mainly to wait for render so that the left pane state is initialized as that is needed for the title
|
|
|
|
|
// to include the datasource
|
|
|
|
|
await screen.findByText(`loki Editor input: { label="value"}`); |
|
|
|
@ -282,8 +280,8 @@ describe('Wrapper', () => { |
|
|
|
|
left: JSON.stringify(['now-1h', 'now', 'loki', { expr: '{ label="value"}' }]), |
|
|
|
|
}; |
|
|
|
|
const { datasources, store } = setupExplore({ urlParams }); |
|
|
|
|
(datasources.loki.query as Mock).mockReturnValue(makeLogsQueryResponse()); |
|
|
|
|
(datasources.elastic.query as Mock).mockReturnValue(makeLogsQueryResponse()); |
|
|
|
|
jest.mocked(datasources.loki.query).mockReturnValue(makeLogsQueryResponse()); |
|
|
|
|
jest.mocked(datasources.elastic.query).mockReturnValue(makeLogsQueryResponse()); |
|
|
|
|
|
|
|
|
|
// This is mainly to wait for render so that the left pane state is initialized as that is needed for splitOpen
|
|
|
|
|
// to work
|
|
|
|
|