Chore: Adjust unit tests so they work with react 18 (#64698)

tweak unit tests so they work with react 18
This commit is contained in:
Ashley Harrison
2023-03-14 17:24:04 +00:00
committed by GitHub
parent c29b6c07dc
commit 85e5326040
33 changed files with 452 additions and 409 deletions

View File

@@ -1,4 +1,5 @@
import { fireEvent, render, screen } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { openMenu } from 'react-select-event';
@@ -30,13 +31,16 @@ jest.mock('@grafana/runtime/src/services/dataSourceSrv', () => {
});
describe('QueryEditorRowHeader', () => {
it('Can edit title', () => {
it('Can edit title', async () => {
const scenario = renderScenario({});
screen.getByTestId('query-name-div').click();
await userEvent.click(screen.getByTestId('query-name-div'));
const input = screen.getByTestId('query-name-input');
fireEvent.change(input, { target: { value: 'new name' } });
fireEvent.blur(input);
await userEvent.clear(input);
await userEvent.type(input, 'new name');
// blur the field
await userEvent.click(document.body);
expect(jest.mocked(scenario.props.onChange).mock.calls[0][0].refId).toBe('new name');
});
@@ -44,9 +48,10 @@ describe('QueryEditorRowHeader', () => {
it('Show error when other query with same name exists', async () => {
renderScenario({});
screen.getByTestId('query-name-div').click();
await userEvent.click(screen.getByTestId('query-name-div'));
const input = screen.getByTestId('query-name-input');
fireEvent.change(input, { target: { value: 'B' } });
await userEvent.clear(input);
await userEvent.type(input, 'B');
const alert = await screen.findByRole('alert');
expect(alert.textContent).toBe('Query name already exists');
@@ -55,9 +60,9 @@ describe('QueryEditorRowHeader', () => {
it('Show error when empty name is specified', async () => {
renderScenario({});
screen.getByTestId('query-name-div').click();
await userEvent.click(screen.getByTestId('query-name-div'));
const input = screen.getByTestId('query-name-input');
fireEvent.change(input, { target: { value: '' } });
await userEvent.clear(input);
const alert = await screen.findByRole('alert');
expect(alert.textContent).toBe('An empty query name is not allowed');