2022-07-07 12:03:02 -05:00
|
|
|
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
2022-04-22 08:33:13 -05:00
|
|
|
import _, { DebouncedFunc } from 'lodash'; // eslint-disable-line lodash/import-scope
|
|
|
|
import React from 'react';
|
2022-04-18 13:05:10 -05:00
|
|
|
import { act } from 'react-dom/test-utils';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
|
|
|
import { ExploreId } from '../../../../types';
|
2022-04-18 13:05:10 -05:00
|
|
|
import { setupMockedDataSource } from '../__mocks__/CloudWatchDataSource';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2022-10-21 02:13:32 -05:00
|
|
|
import CloudWatchLogsQueryField from './LogsQueryField';
|
2020-05-14 13:41:38 -05:00
|
|
|
|
2021-08-11 03:10:41 -05:00
|
|
|
jest
|
|
|
|
.spyOn(_, 'debounce')
|
2022-03-31 04:19:33 -05:00
|
|
|
.mockImplementation((func: (...args: any) => any, wait?: number) => func as DebouncedFunc<typeof func>);
|
2020-05-06 10:54:24 -05:00
|
|
|
|
|
|
|
describe('CloudWatchLogsQueryField', () => {
|
2022-04-18 13:05:10 -05:00
|
|
|
it('runs onRunQuery on blur of Log Groups', async () => {
|
|
|
|
const onRunQuery = jest.fn();
|
|
|
|
const ds = setupMockedDataSource();
|
|
|
|
|
|
|
|
render(
|
|
|
|
<CloudWatchLogsQueryField
|
|
|
|
absoluteRange={{ from: 1, to: 10 }}
|
|
|
|
exploreId={ExploreId.left}
|
|
|
|
datasource={ds.datasource}
|
|
|
|
query={{} as any}
|
|
|
|
onRunQuery={onRunQuery}
|
|
|
|
onChange={() => {}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const multiSelect = screen.getByLabelText('Log Groups');
|
|
|
|
await act(async () => {
|
|
|
|
fireEvent.blur(multiSelect);
|
|
|
|
});
|
|
|
|
expect(onRunQuery).toHaveBeenCalled();
|
|
|
|
});
|
2022-07-07 12:03:02 -05:00
|
|
|
|
|
|
|
it('loads defaultLogGroups', async () => {
|
|
|
|
const onRunQuery = jest.fn();
|
|
|
|
const ds = setupMockedDataSource();
|
2022-09-19 01:50:41 -05:00
|
|
|
ds.datasource.logsQueryRunner.defaultLogGroups = ['foo'];
|
2022-07-07 12:03:02 -05:00
|
|
|
|
|
|
|
render(
|
|
|
|
<CloudWatchLogsQueryField
|
|
|
|
absoluteRange={{ from: 1, to: 10 }}
|
|
|
|
exploreId={ExploreId.left}
|
|
|
|
datasource={ds.datasource}
|
|
|
|
query={{} as any}
|
|
|
|
onRunQuery={onRunQuery}
|
|
|
|
onChange={() => {}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(screen.getByText('foo')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
2020-05-06 10:54:24 -05:00
|
|
|
});
|