Skip to content

Commit

Permalink
Merge branch 'v3' into PMM-12356-user-roles-advisors-alerting
Browse files Browse the repository at this point in the history
  • Loading branch information
matejkubinec committed Feb 24, 2025
2 parents 986103c + 7bdd0f0 commit 4bff8d1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 (
<LinkButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { queryByTestId, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';

import { DataSourceInstanceSettings, DataSourcePluginMeta, PluginMetaInfo, PluginType } from '@grafana/data';
import {
DataSourceInstanceSettings,
DataSourcePluginMeta,
GrafanaConfig,
PluginMetaInfo,
PluginType,
locationUtil,
} from '@grafana/data';
import { config } from '@grafana/runtime';

import { DataSourceModal, DataSourceModalProps } from './DataSourceModal';
Expand Down Expand Up @@ -74,6 +81,12 @@ jest.mock('@grafana/runtime/src/services/dataSourceSrv', () => {
};
});

locationUtil.initialize({
config: { appSubUrl: '/my-sub-path' } as GrafanaConfig,
getTimeRangeForUrl: jest.fn(),
getVariablesUrlParams: jest.fn(),
});

const getListMock = jest.fn();
const getInstanceSettingsMock = jest.fn();
beforeEach(() => {
Expand All @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit 4bff8d1

Please sign in to comment.