Loki: Remove imported test utility function from Prometheus (#78901)

Loki: Remove import from prometheus test utility
This commit is contained in:
Ivana Huckova 2023-12-12 12:54:56 +01:00 committed by GitHub
parent eff9374a63
commit 953d0d4c70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 24 deletions

View File

@ -1,8 +1,7 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { addOperation } from 'app/plugins/datasource/prometheus/querybuilder/shared/OperationList.testUtils';
import { createLokiDatasource } from '../../mocks';
import { LokiQueryBuilderContainer } from './LokiQueryBuilderContainer';
@ -32,3 +31,19 @@ describe('LokiQueryBuilderContainer', () => {
});
});
});
async function addOperation(section: string, op: string) {
const addOperationButton = screen.getByTitle('Add operation');
expect(addOperationButton).toBeInTheDocument();
await userEvent.click(addOperationButton);
const sectionItem = await screen.findByTitle(section);
expect(sectionItem).toBeInTheDocument();
// Weirdly the await userEvent.click doesn't work here, it reports the item has pointer-events: none. Don't see that
// anywhere when debugging so not sure what style is it picking up.
await userEvent.click(sectionItem.children[0], { pointerEventsCheck: 0 });
const opItem = screen.getByTitle(op);
expect(opItem).toBeInTheDocument();
// Weirdly the await userEvent.click doesn't work here, it reports the item has pointer-events: none. Don't see that
// anywhere when debugging so not sure what style is it picking up.
await userEvent.click(opItem, { pointerEventsCheck: 0 });
}

View File

@ -9,7 +9,7 @@ import PromQlLanguageProvider from '../../language_provider';
import { EmptyLanguageProviderMock } from '../../language_provider.mock';
import { PromQuery } from '../../types';
import { getOperationParamId } from '../operationUtils';
import { addOperation } from '../shared/OperationList.testUtils';
import { addOperationInQueryBuilder } from '../testUtils';
import { PromQueryBuilderContainer } from './PromQueryBuilderContainer';
@ -18,7 +18,7 @@ describe('PromQueryBuilderContainer', () => {
const { props } = setup({ expr: 'rate(metric_test{job="testjob"}[$__rate_interval])' });
expect(screen.getByText('metric_test')).toBeInTheDocument();
await addOperation('Range functions', 'Rate');
await addOperationInQueryBuilder('Range functions', 'Rate');
expect(props.onChange).toBeCalledWith({
expr: 'rate(metric_test{job="testjob"}[$__rate_interval])',
refId: 'A',

View File

@ -9,10 +9,10 @@ import PromQlLanguageProvider from '../../language_provider';
import { EmptyLanguageProviderMock } from '../../language_provider.mock';
import { PromOptions } from '../../types';
import { promQueryModeller } from '../PromQueryModeller';
import { addOperationInQueryBuilder } from '../testUtils';
import { PromVisualQuery } from '../types';
import { OperationList } from './OperationList';
import { addOperation } from './OperationList.testUtils';
const defaultQuery: PromVisualQuery = {
metric: 'random_metric',
@ -50,7 +50,7 @@ describe('OperationList', () => {
it('adds an operation', async () => {
const { onChange } = setup();
await addOperation('Aggregations', 'Min');
await addOperationInQueryBuilder('Aggregations', 'Min');
expect(onChange).toBeCalledWith({
labels: [{ label: 'instance', op: '=', value: 'localhost:9090' }],
metric: 'random_metric',

View File

@ -1,18 +0,0 @@
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
export async function addOperation(section: string, op: string) {
const addOperationButton = screen.getByTitle('Add operation');
expect(addOperationButton).toBeInTheDocument();
await userEvent.click(addOperationButton);
const sectionItem = await screen.findByTitle(section);
expect(sectionItem).toBeInTheDocument();
// Weirdly the await userEvent.click doesn't work here, it reports the item has pointer-events: none. Don't see that
// anywhere when debugging so not sure what style is it picking up.
await userEvent.click(sectionItem.children[0], { pointerEventsCheck: 0 });
const opItem = screen.getByTitle(op);
expect(opItem).toBeInTheDocument();
// Weirdly the await userEvent.click doesn't work here, it reports the item has pointer-events: none. Don't see that
// anywhere when debugging so not sure what style is it picking up.
await userEvent.click(opItem, { pointerEventsCheck: 0 });
}

View File

@ -1,4 +1,5 @@
import { screen, getAllByRole } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
export function getLabelSelects(index = 0) {
const labels = screen.getByText(/Label filters/);
@ -8,3 +9,19 @@ export function getLabelSelects(index = 0) {
value: selects[3 * index + 2],
};
}
export async function addOperationInQueryBuilder(section: string, op: string) {
const addOperationButton = screen.getByTitle('Add operation');
expect(addOperationButton).toBeInTheDocument();
await userEvent.click(addOperationButton);
const sectionItem = await screen.findByTitle(section);
expect(sectionItem).toBeInTheDocument();
// Weirdly the await userEvent.click doesn't work here, it reports the item has pointer-events: none. Don't see that
// anywhere when debugging so not sure what style is it picking up.
await userEvent.click(sectionItem.children[0], { pointerEventsCheck: 0 });
const opItem = screen.getByTitle(op);
expect(opItem).toBeInTheDocument();
// Weirdly the await userEvent.click doesn't work here, it reports the item has pointer-events: none. Don't see that
// anywhere when debugging so not sure what style is it picking up.
await userEvent.click(opItem, { pointerEventsCheck: 0 });
}