mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* Convert QueryOperationAction test to RTL * Convert QueryOperationAction to RTL * Convert QueryOperationAction test to RTL
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import React from 'react';
|
|
|
|
import { selectors } from '@grafana/e2e-selectors';
|
|
|
|
import { QueryOperationAction, QueryOperationActionProps } from './QueryOperationAction';
|
|
|
|
const setup = (propOverrides?: Partial<QueryOperationActionProps>) => {
|
|
const props: QueryOperationActionProps = {
|
|
icon: 'panel-add',
|
|
title: 'test',
|
|
onClick: jest.fn(),
|
|
disabled: false,
|
|
...propOverrides,
|
|
};
|
|
|
|
render(<QueryOperationAction {...props} />);
|
|
};
|
|
|
|
describe('QueryOperationAction tests', () => {
|
|
it('should render component', () => {
|
|
setup();
|
|
|
|
expect(
|
|
screen.getByRole('button', { name: selectors.components.QueryEditorRow.actionButton('test') })
|
|
).toBeInTheDocument();
|
|
});
|
|
|
|
it('should call on click handler', async () => {
|
|
const clickSpy = jest.fn();
|
|
setup({ disabled: false, onClick: clickSpy });
|
|
|
|
expect(clickSpy).not.toHaveBeenCalled();
|
|
const queryButton = screen.getByRole('button', { name: selectors.components.QueryEditorRow.actionButton('test') });
|
|
|
|
await userEvent.click(queryButton);
|
|
|
|
expect(clickSpy).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should not call on click handler when disabled', async () => {
|
|
const clickSpy = jest.fn();
|
|
setup({ disabled: true, onClick: clickSpy });
|
|
|
|
expect(clickSpy).not.toHaveBeenCalled();
|
|
const queryButton = screen.getByRole('button', { name: selectors.components.QueryEditorRow.actionButton('test') });
|
|
|
|
await userEvent.click(queryButton);
|
|
|
|
expect(clickSpy).not.toHaveBeenCalled();
|
|
});
|
|
});
|