From 515673809e226933c1e44247e82efadc029bfee6 Mon Sep 17 00:00:00 2001 From: yaellec Date: Tue, 2 Aug 2022 14:25:38 +0200 Subject: [PATCH] Fix tests --- .../VariableEditor/VariableEditor.test.tsx | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/VariableEditor/VariableEditor.test.tsx b/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/VariableEditor/VariableEditor.test.tsx index 176766b6f69..c8f153a16d5 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/VariableEditor/VariableEditor.test.tsx +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/VariableEditor/VariableEditor.test.tsx @@ -40,20 +40,6 @@ const defaultProps = { }), }; -const ARGqueryProps = { - ...defaultProps, - query: { - refId: 'A', - queryType: AzureQueryType.AzureResourceGraph, - azureResourceGraph: { - query: 'Resources | distinct type', - resultFormat: 'table', - }, - subscriptions: ['Subscription1', 'Subscription2'], - subscription: 'id', - }, -}; - describe('VariableEditor:', () => { it('can view a legacy Grafana query function', async () => { const onChange = jest.fn(); @@ -98,8 +84,24 @@ describe('VariableEditor:', () => { }); describe('Azure Resource Graph queries:', () => { + const ARGqueryProps = (onChange?: (query: AzureMonitorQuery) => void) => ({ + query: { + refId: 'A', + queryType: AzureQueryType.AzureResourceGraph, + azureResourceGraph: { + query: 'Resources | distinct type', + resultFormat: 'table', + }, + subscriptions: ['sub'], + }, + onChange: onChange || jest.fn(), + datasource: createMockDatasource({ + getSubscriptions: jest.fn().mockResolvedValue([{ text: 'Primary Subscription', value: 'sub' }]), + }), + }); + it('should render', async () => { - render(); + render(); await waitFor(() => screen.queryByTestId('mockeditor')); expect(screen.queryByLabelText('Subscriptions')).toBeInTheDocument(); expect(screen.queryByLabelText('Select subscription')).not.toBeInTheDocument(); @@ -112,16 +114,18 @@ describe('VariableEditor:', () => { it('should call on change if the query changes', async () => { const onChange = jest.fn(); - render(); + render(); await waitFor(() => screen.queryByTestId('mockeditor')); expect(screen.queryByTestId('mockeditor')).toBeInTheDocument(); await userEvent.type(screen.getByTestId('mockeditor'), '{backspace}'); expect(onChange).toHaveBeenCalledWith({ - ...ARGqueryProps.query, + refId: 'A', + queryType: AzureQueryType.AzureResourceGraph, azureResourceGraph: { - ...ARGqueryProps.query.azureResourceGraph, query: 'Resources | distinct typ', + resultFormat: 'table', }, + subscriptions: ['sub'], }); }); });