@@ -4,7 +4,7 @@ import { render, screen } from '@testing-library/react';
44import { DataQuery } from '@grafana/data' ;
55import { RunQueryButtons , RunQueryButtonsProps } from './RunQueryButtons' ;
66
7- const getDefaultProps = ( overrides : Partial < RunQueryButtonsProps < DataQuery > > ) => {
7+ const getDefaultProps = ( overrides ? : Partial < RunQueryButtonsProps < DataQuery > > ) => {
88 return {
99 onRunQuery : jest . fn ( ) ,
1010 onCancelQuery : jest . fn ( ) ,
@@ -28,4 +28,22 @@ describe('RunQueryButtons', () => {
2828 const runButton = screen . getByRole ( 'button' , { name : 'Run' } ) ;
2929 expect ( runButton ) . not . toBeDisabled ( ) ;
3030 } ) ;
31+
32+ it ( 'only renders the `Run` button if onCancelQuery is undefined' , ( ) => {
33+ const props = getDefaultProps ( { onCancelQuery : undefined } ) ;
34+ render ( < RunQueryButtons { ...props } /> ) ;
35+ const runButton = screen . getByRole ( 'button' , { name : 'Run' } ) ;
36+ expect ( runButton ) . toBeInTheDocument ( ) ;
37+ const stopButton = screen . queryByRole ( 'button' , { name : 'Stop' } ) ;
38+ expect ( stopButton ) . not . toBeInTheDocument ( ) ;
39+ } ) ;
40+
41+ it ( 'renders the `Run` and `Stop` buttons if onCancelQuery defined' , ( ) => {
42+ const props = getDefaultProps ( ) ;
43+ render ( < RunQueryButtons { ...props } /> ) ;
44+ const runButton = screen . getByRole ( 'button' , { name : 'Run' } ) ;
45+ expect ( runButton ) . toBeInTheDocument ( ) ;
46+ const stopButton = screen . queryByRole ( 'button' , { name : 'Stop' } ) ;
47+ expect ( stopButton ) . toBeInTheDocument ( ) ;
48+ } ) ;
3149} ) ;
0 commit comments