mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: clean up console warning from Metric Stat Editor tests (#46662)
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import React from 'react';
|
||||
import { cleanup, fireEvent, render, screen, act } from '@testing-library/react';
|
||||
import { fireEvent, render, screen, act, waitFor } from '@testing-library/react';
|
||||
import selectEvent from 'react-select-event';
|
||||
import { setupMockedDataSource } from '../../__mocks__/CloudWatchDataSource';
|
||||
import '@testing-library/jest-dom';
|
||||
import { CloudWatchMetricsQuery } from '../../types';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { MetricStatEditor } from '..';
|
||||
@@ -36,68 +35,68 @@ const props = {
|
||||
onRunQuery: jest.fn(),
|
||||
};
|
||||
|
||||
afterEach(cleanup);
|
||||
|
||||
describe('MetricStatEditor', () => {
|
||||
describe('statistics field', () => {
|
||||
test.each([['Average', 'p23.23', 'p34', '$statistic']])('should accept valid values', (statistic) => {
|
||||
test.each([['Average', 'p23.23', 'p34', '$statistic']])('should accept valid values', async (statistic) => {
|
||||
const onChange = jest.fn();
|
||||
const onRunQuery = jest.fn();
|
||||
props.datasource.getVariables = jest.fn().mockReturnValue(['$statistic']);
|
||||
|
||||
render(<MetricStatEditor {...props} onChange={onChange} onRunQuery={onRunQuery} />);
|
||||
|
||||
const statisticElement = screen.getByLabelText('Statistic');
|
||||
const statisticElement = await screen.findByLabelText('Statistic');
|
||||
expect(statisticElement).toBeInTheDocument();
|
||||
|
||||
userEvent.type(statisticElement!, statistic);
|
||||
fireEvent.keyDown(statisticElement!, { keyCode: 13 });
|
||||
userEvent.type(statisticElement, statistic);
|
||||
fireEvent.keyDown(statisticElement, { keyCode: 13 });
|
||||
expect(onChange).toHaveBeenCalledWith({ ...props.query, statistic });
|
||||
expect(onRunQuery).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test.each([['CustomStat', 'p23,23', '$statistic']])('should not accept invalid values', (statistic) => {
|
||||
test.each([['CustomStat', 'p23,23', '$statistic']])('should not accept invalid values', async (statistic) => {
|
||||
const onChange = jest.fn();
|
||||
const onRunQuery = jest.fn();
|
||||
|
||||
render(<MetricStatEditor {...props} onChange={onChange} onRunQuery={onRunQuery} />);
|
||||
|
||||
const statisticElement = screen.getByLabelText('Statistic');
|
||||
const statisticElement = await screen.findByLabelText('Statistic');
|
||||
expect(statisticElement).toBeInTheDocument();
|
||||
|
||||
userEvent.type(statisticElement!, statistic);
|
||||
fireEvent.keyDown(statisticElement!, { keyCode: 13 });
|
||||
userEvent.type(statisticElement, statistic);
|
||||
fireEvent.keyDown(statisticElement, { keyCode: 13 });
|
||||
expect(onChange).not.toHaveBeenCalled();
|
||||
expect(onRunQuery).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('expressions', () => {
|
||||
it('should display match exact switch is not set', () => {
|
||||
it('should display match exact switch is not set', async () => {
|
||||
render(<MetricStatEditor {...props} />);
|
||||
expect(screen.getByText('Match exact')).toBeInTheDocument();
|
||||
expect(await screen.findByText('Match exact')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should display match exact switch if prop is set to false', () => {
|
||||
it('should display match exact switch if prop is set to false', async () => {
|
||||
render(<MetricStatEditor {...props} disableExpressions={false} />);
|
||||
expect(screen.getByText('Match exact')).toBeInTheDocument();
|
||||
expect(await screen.findByText('Match exact')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should not display match exact switch if prop is set to true', async () => {
|
||||
render(<MetricStatEditor {...props} disableExpressions={true} />);
|
||||
expect(screen.queryByText('Match exact')).toBeNull();
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByText('Match exact')).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('match exact', () => {
|
||||
it('should be checked when value is true', () => {
|
||||
it('should be checked when value is true', async () => {
|
||||
render(<MetricStatEditor {...props} disableExpressions={false} />);
|
||||
expect(screen.getByLabelText('Match exact - optional')).toBeChecked();
|
||||
expect(await screen.findByLabelText('Match exact - optional')).toBeChecked();
|
||||
});
|
||||
|
||||
it('should be unchecked when value is false', () => {
|
||||
it('should be unchecked when value is false', async () => {
|
||||
render(<MetricStatEditor {...props} query={{ ...props.query, matchExact: false }} disableExpressions={false} />);
|
||||
expect(screen.getByLabelText('Match exact - optional')).not.toBeChecked();
|
||||
expect(await screen.findByLabelText('Match exact - optional')).not.toBeChecked();
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user