Files
Ashley Harrison d832bde270 Upgrade @testing-library/user-event to v14 (#47898)
* Update dependency @testing-library/user-event to v14

* everything is async...

* everything is async pt.2

* Fix cascader tests

* hack the yarn.lock file to remove the old version of @testing-library/dom

* some more fixes!

* MOAR FIXES

* more fixes

* remove a bunch of places where we're wrapping in act()

* down to 7 failing tests...

* Fix arrow tests

* Fix rest of NavBarItem tests

* Fix last tests

* Use {Enter} instead of {enter}

* Revert "Use {Enter} instead of {enter}"

This reverts commit e72453bb522245cbc2acd0736929fbb351ad070a.

* remove some unused act imports

* Fix LibraryPanelsSearch tests

* more stable test

* More consistent test...

Co-authored-by: Renovate Bot <bot@renovateapp.com>
2022-04-21 13:15:21 +01:00

56 lines
2.1 KiB
TypeScript

import React from 'react';
import { render, screen, getAllByRole, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { LokiQueryBuilder } from './LokiQueryBuilder';
import { LokiDatasource } from '../../datasource';
import { LokiOperationId, LokiVisualQuery } from '../types';
import { PanelData } from '@grafana/data';
const defaultQuery: LokiVisualQuery = {
labels: [{ op: '=', label: 'baz', value: 'bar' }],
operations: [],
};
describe('LokiQueryBuilder', () => {
it('tries to load labels when no labels are selected', async () => {
const { datasource } = setup();
datasource.languageProvider.fetchSeriesLabels = jest.fn().mockReturnValue({ job: ['a'], instance: ['b'] });
await userEvent.click(screen.getByLabelText('Add'));
const labels = screen.getByText(/Labels/);
const selects = getAllByRole(labels.parentElement!.parentElement!.parentElement!, 'combobox');
await userEvent.click(selects[3]);
await waitFor(() => expect(screen.getByText('job')).toBeInTheDocument());
});
it('shows error for query with operations and no stream selector', async () => {
setup({ labels: [], operations: [{ id: LokiOperationId.Logfmt, params: [] }] });
expect(screen.getByText('You need to specify at least 1 label filter (stream selector)')).toBeInTheDocument();
});
it('shows no error for query with empty __line_contains operation and no stream selector', async () => {
setup({ labels: [], operations: [{ id: LokiOperationId.LineContains, params: [''] }] });
expect(screen.queryByText('You need to specify at least 1 label filter (stream selector)')).not.toBeInTheDocument();
});
});
function setup(query: LokiVisualQuery = defaultQuery, data?: PanelData) {
const datasource = new LokiDatasource(
{
url: '',
jsonData: {},
meta: {} as any,
} as any,
undefined,
undefined
);
const props = {
datasource,
onRunQuery: () => {},
onChange: () => {},
data,
};
const { container } = render(<LokiQueryBuilder {...props} query={query} />);
return { datasource, container };
}