diff --git a/public/app/plugins/datasource/testdata/QueryEditor.test.tsx b/public/app/plugins/datasource/testdata/QueryEditor.test.tsx index 86921d98762..8060ffae023 100644 --- a/public/app/plugins/datasource/testdata/QueryEditor.test.tsx +++ b/public/app/plugins/datasource/testdata/QueryEditor.test.tsx @@ -82,4 +82,21 @@ describe('Test Datasource Query Editor', () => { expect(screen.getByLabelText('Spread')).toHaveValue(3.5); expect(screen.getByLabelText('Bands')).toHaveValue(1); }); + + it('persists the datasource from the query when switching scenario', async () => { + const mockDatasource = { + type: 'test', + uid: 'foo', + }; + setup({ + query: { + ...defaultQuery, + datasource: mockDatasource, + }, + }); + let select = (await screen.findByText('Scenario')).nextSibling!.firstChild!; + await fireEvent.keyDown(select, { keyCode: 40 }); + await userEvent.click(screen.getByText('Grafana API')); + expect(mockOnChange).toHaveBeenCalledWith(expect.objectContaining({ datasource: mockDatasource })); + }); }); diff --git a/public/app/plugins/datasource/testdata/QueryEditor.tsx b/public/app/plugins/datasource/testdata/QueryEditor.tsx index e851ce4d9af..4fb6a95d343 100644 --- a/public/app/plugins/datasource/testdata/QueryEditor.tsx +++ b/public/app/plugins/datasource/testdata/QueryEditor.tsx @@ -82,6 +82,7 @@ export const QueryEditor = ({ query, datasource, onChange, onRunQuery }: Props) scenarioId: item.value!, refId: query.refId, alias: query.alias, + datasource: query.datasource, }; if (scenario.stringInput) {