mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Remove dependency in test files on selectOptionInTest (#80546)
* Loki: Remove dependecy in test files on selectOptionInTest * Remove await waitFor(() => where not needed
This commit is contained in:
parent
67d77e76be
commit
b97170b01e
@ -1,7 +1,7 @@
|
|||||||
import { act, render, screen, waitFor } from '@testing-library/react';
|
import { act, render, screen, waitFor } from '@testing-library/react';
|
||||||
import userEvent from '@testing-library/user-event';
|
import userEvent from '@testing-library/user-event';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { selectOptionInTest } from 'test/helpers/selectOptionInTest';
|
import { select } from 'react-select-event';
|
||||||
|
|
||||||
import { LogRowModel, dateTime } from '@grafana/data';
|
import { LogRowModel, dateTime } from '@grafana/data';
|
||||||
|
|
||||||
@ -136,8 +136,8 @@ describe('LokiContextUi', () => {
|
|||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(props.logContextProvider.getInitContextFilters).toHaveBeenCalled();
|
expect(props.logContextProvider.getInitContextFilters).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
const select = await screen.findAllByRole('combobox');
|
const selects = await screen.findAllByRole('combobox');
|
||||||
await selectOptionInTest(select[0], 'label1="value1"');
|
await select(selects[0], 'label1="value1"', { container: document.body });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('finds label3 as a parsed label', async () => {
|
it('finds label3 as a parsed label', async () => {
|
||||||
@ -146,8 +146,8 @@ describe('LokiContextUi', () => {
|
|||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(props.logContextProvider.getInitContextFilters).toHaveBeenCalled();
|
expect(props.logContextProvider.getInitContextFilters).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
const select = await screen.findAllByRole('combobox');
|
const selects = await screen.findAllByRole('combobox');
|
||||||
await selectOptionInTest(select[1], 'label3="value3"');
|
await select(selects[1], 'label3="value3"', { container: document.body });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calls updateFilter when selecting a label', async () => {
|
it('calls updateFilter when selecting a label', async () => {
|
||||||
@ -158,7 +158,7 @@ describe('LokiContextUi', () => {
|
|||||||
expect(props.logContextProvider.getInitContextFilters).toHaveBeenCalled();
|
expect(props.logContextProvider.getInitContextFilters).toHaveBeenCalled();
|
||||||
expect(screen.getAllByRole('combobox')).toHaveLength(2);
|
expect(screen.getAllByRole('combobox')).toHaveLength(2);
|
||||||
});
|
});
|
||||||
await selectOptionInTest(screen.getAllByRole('combobox')[1], 'label3="value3"');
|
await select(screen.getAllByRole('combobox')[1], 'label3="value3"', { container: document.body });
|
||||||
act(() => {
|
act(() => {
|
||||||
jest.runAllTimers();
|
jest.runAllTimers();
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { render, screen, waitFor } from '@testing-library/react';
|
import { render, screen, waitFor } from '@testing-library/react';
|
||||||
import userEvent from '@testing-library/user-event';
|
import userEvent from '@testing-library/user-event';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { selectOptionInTest } from 'test/helpers/selectOptionInTest';
|
import { select } from 'react-select-event';
|
||||||
|
|
||||||
import { TemplateSrv } from '@grafana/runtime';
|
import { TemplateSrv } from '@grafana/runtime';
|
||||||
|
|
||||||
@ -34,8 +34,7 @@ describe('LokiVariableQueryEditor', () => {
|
|||||||
render(<LokiVariableQueryEditor {...props} onChange={onChange} />);
|
render(<LokiVariableQueryEditor {...props} onChange={onChange} />);
|
||||||
|
|
||||||
expect(onChange).not.toHaveBeenCalled();
|
expect(onChange).not.toHaveBeenCalled();
|
||||||
|
await select(screen.getByLabelText('Query type'), 'Label names', { container: document.body });
|
||||||
await selectOptionInTest(screen.getByLabelText('Query type'), 'Label names');
|
|
||||||
|
|
||||||
expect(onChange).toHaveBeenCalledWith({
|
expect(onChange).toHaveBeenCalledWith({
|
||||||
type: LokiVariableQueryType.LabelNames,
|
type: LokiVariableQueryType.LabelNames,
|
||||||
@ -51,8 +50,8 @@ describe('LokiVariableQueryEditor', () => {
|
|||||||
|
|
||||||
expect(onChange).not.toHaveBeenCalled();
|
expect(onChange).not.toHaveBeenCalled();
|
||||||
|
|
||||||
await selectOptionInTest(screen.getByLabelText('Query type'), 'Label values');
|
await waitFor(() => select(screen.getByLabelText('Query type'), 'Label values', { container: document.body }));
|
||||||
await selectOptionInTest(screen.getByLabelText('Label'), 'luna');
|
await select(screen.getByLabelText('Label'), 'luna', { container: document.body });
|
||||||
await userEvent.type(screen.getByLabelText('Stream selector'), 'stream');
|
await userEvent.type(screen.getByLabelText('Stream selector'), 'stream');
|
||||||
|
|
||||||
await waitFor(() => expect(screen.getByDisplayValue('stream')).toBeInTheDocument());
|
await waitFor(() => expect(screen.getByDisplayValue('stream')).toBeInTheDocument());
|
||||||
@ -72,8 +71,8 @@ describe('LokiVariableQueryEditor', () => {
|
|||||||
render(<LokiVariableQueryEditor {...props} onChange={onChange} />);
|
render(<LokiVariableQueryEditor {...props} onChange={onChange} />);
|
||||||
|
|
||||||
expect(onChange).not.toHaveBeenCalled();
|
expect(onChange).not.toHaveBeenCalled();
|
||||||
|
await waitFor(() => select(screen.getByLabelText('Query type'), 'Label values', { container: document.body }));
|
||||||
|
|
||||||
await selectOptionInTest(screen.getByLabelText('Query type'), 'Label values');
|
|
||||||
await userEvent.type(screen.getByLabelText('Label'), 'sol{enter}');
|
await userEvent.type(screen.getByLabelText('Label'), 'sol{enter}');
|
||||||
await userEvent.type(screen.getByLabelText('Stream selector'), 'stream');
|
await userEvent.type(screen.getByLabelText('Stream selector'), 'stream');
|
||||||
|
|
||||||
@ -120,9 +119,8 @@ describe('LokiVariableQueryEditor', () => {
|
|||||||
|
|
||||||
test('Label options are not lost when selecting one', async () => {
|
test('Label options are not lost when selecting one', async () => {
|
||||||
const { rerender } = render(<LokiVariableQueryEditor {...props} onChange={() => {}} />);
|
const { rerender } = render(<LokiVariableQueryEditor {...props} onChange={() => {}} />);
|
||||||
|
await waitFor(() => select(screen.getByLabelText('Query type'), 'Label values', { container: document.body }));
|
||||||
await selectOptionInTest(screen.getByLabelText('Query type'), 'Label values');
|
await select(screen.getByLabelText('Label'), 'luna', { container: document.body });
|
||||||
await selectOptionInTest(screen.getByLabelText('Label'), 'luna');
|
|
||||||
|
|
||||||
const updatedQuery = {
|
const updatedQuery = {
|
||||||
refId: 'test',
|
refId: 'test',
|
||||||
@ -131,8 +129,8 @@ describe('LokiVariableQueryEditor', () => {
|
|||||||
};
|
};
|
||||||
rerender(<LokiVariableQueryEditor {...props} query={updatedQuery} onChange={() => {}} />);
|
rerender(<LokiVariableQueryEditor {...props} query={updatedQuery} onChange={() => {}} />);
|
||||||
|
|
||||||
await selectOptionInTest(screen.getByLabelText('Label'), 'moon');
|
await select(screen.getByLabelText('Label'), 'moon', { container: document.body });
|
||||||
await selectOptionInTest(screen.getByLabelText('Label'), 'luna');
|
await select(screen.getByLabelText('Label'), 'luna', { container: document.body });
|
||||||
await screen.findByText('luna');
|
await screen.findByText('luna');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { dateTime } from '@grafana/data';
|
import { dateTime } from '@grafana/data';
|
||||||
import { Monaco, monacoTypes } from '@grafana/ui/src';
|
import { Monaco, monacoTypes } from '@grafana/ui';
|
||||||
|
|
||||||
import LokiLanguageProvider from '../../../LanguageProvider';
|
import LokiLanguageProvider from '../../../LanguageProvider';
|
||||||
import { createLokiDatasource } from '../../../__mocks__/datasource';
|
import { createLokiDatasource } from '../../../__mocks__/datasource';
|
||||||
|
Loading…
Reference in New Issue
Block a user