diff --git a/public/app/features/datasources/components/picker/AddNewDataSourceButton.tsx b/public/app/features/datasources/components/picker/AddNewDataSourceButton.tsx index bc7bf9508c531..76b81dfcde7b1 100644 --- a/public/app/features/datasources/components/picker/AddNewDataSourceButton.tsx +++ b/public/app/features/datasources/components/picker/AddNewDataSourceButton.tsx @@ -1,5 +1,6 @@ import React from 'react'; +import { locationUtil } from '@grafana/data'; import { LinkButton, ButtonVariant } from '@grafana/ui'; import { contextSrv } from 'app/core/core'; import { Trans } from 'app/core/internationalization'; @@ -13,7 +14,7 @@ interface AddNewDataSourceButtonProps { export function AddNewDataSourceButton({ variant, onClick }: AddNewDataSourceButtonProps) { const hasCreateRights = contextSrv.hasPermission(AccessControlAction.DataSourcesCreate); - const newDataSourceURL = CONNECTIONS_ROUTES.DataSourcesNew; + const newDataSourceURL = locationUtil.assureBaseUrl(CONNECTIONS_ROUTES.DataSourcesNew); return ( { }; }); +locationUtil.initialize({ + config: { appSubUrl: '/my-sub-path' } as GrafanaConfig, + getTimeRangeForUrl: jest.fn(), + getVariablesUrlParams: jest.fn(), +}); + const getListMock = jest.fn(); const getInstanceSettingsMock = jest.fn(); beforeEach(() => { @@ -96,6 +109,10 @@ describe('DataSourceDropdown', () => { await user.keyboard('foobarbaz'); //Search for a DS that should not exist expect(screen.queryAllByText('Configure a new data source')).toHaveLength(2); + screen.queryAllByRole('link').forEach((link) => { + // It should point to the new data source page including any sub url configured + expect(link).toHaveAttribute('href', '/my-sub-path/connections/datasources/new'); + }); }); it('only displays the file drop area when the ff is enabled', async () => { diff --git a/public/app/features/datasources/components/picker/DataSourcePicker.test.tsx b/public/app/features/datasources/components/picker/DataSourcePicker.test.tsx index c13140a43c3e8..260490312c2c1 100644 --- a/public/app/features/datasources/components/picker/DataSourcePicker.test.tsx +++ b/public/app/features/datasources/components/picker/DataSourcePicker.test.tsx @@ -3,7 +3,14 @@ import userEvent from '@testing-library/user-event'; import { UserEvent } from '@testing-library/user-event/dist/types/setup/setup'; import React from 'react'; -import { DataSourceInstanceSettings, DataSourcePluginMeta, PluginMetaInfo, PluginType } from '@grafana/data'; +import { + DataSourceInstanceSettings, + DataSourcePluginMeta, + GrafanaConfig, + PluginMetaInfo, + PluginType, + locationUtil, +} from '@grafana/data'; import { selectors } from '@grafana/e2e-selectors'; import { ModalRoot, ModalsProvider } from '@grafana/ui'; import config from 'app/core/config'; @@ -52,6 +59,12 @@ async function setupOpenDropdown(user: UserEvent, props: DataSourcePickerProps) await user.click(searchBox!); } +locationUtil.initialize({ + config: { appSubUrl: '/my-sub-path' } as GrafanaConfig, + getVariablesUrlParams: jest.fn(), + getTimeRangeForUrl: jest.fn(), +}); + jest.mock('@grafana/runtime', () => { const actual = jest.requireActual('@grafana/runtime'); return { @@ -282,6 +295,8 @@ describe('DataSourcePicker', () => { await user.keyboard('foobarbaz'); //Search for a DS that should not exist expect(await screen.findByText('Configure a new data source')).toBeInTheDocument(); + // It should point to the new data source page including any sub url configured + expect(screen.getByRole('link')).toHaveAttribute('href', '/my-sub-path/connections/datasources/new'); }); it('should call onChange with the default query when add csv is clicked', async () => {