From a23bacc3e2444851b04345ba4f7f1ed65326d031 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Wed, 19 Jan 2022 14:19:45 +0100 Subject: [PATCH] Dashboard: Prevent Mixed datasources using the test datasource crashing (#44128) (#44215) * Special case mixed datasources... :/ * Revert "Special case mixed datasources... :/" This reverts commit dd0e3ea4a8f67786ba369050ff3a571c7b0378b3. * Ensure testdata persists datasource when switching scenario * Add a unit test to prevent regressions * kick drone (cherry picked from commit d4d306d825f2c194b19eb0535a953a89f6a1fb57) Co-authored-by: Ashley Harrison --- .../datasource/testdata/QueryEditor.test.tsx | 17 +++++++++++++++++ .../plugins/datasource/testdata/QueryEditor.tsx | 1 + 2 files changed, 18 insertions(+) diff --git a/public/app/plugins/datasource/testdata/QueryEditor.test.tsx b/public/app/plugins/datasource/testdata/QueryEditor.test.tsx index dcc2bbb6438..6a7108053c6 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 f2e082914ee..da4314cff9a 100644 --- a/public/app/plugins/datasource/testdata/QueryEditor.tsx +++ b/public/app/plugins/datasource/testdata/QueryEditor.tsx @@ -81,6 +81,7 @@ export const QueryEditor = ({ query, datasource, onChange, onRunQuery }: Props) scenarioId: item.value!, refId: query.refId, alias: query.alias, + datasource: query.datasource, }; if (scenario.stringInput) {