mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix "copy link" not including full URL (#88210)
This commit is contained in:
parent
26a01c42a6
commit
859b3ff78b
@ -3,7 +3,7 @@ import React from 'react';
|
|||||||
import { render, screen, userEvent } from 'test/test-utils';
|
import { render, screen, userEvent } from 'test/test-utils';
|
||||||
import { byLabelText } from 'testing-library-selector';
|
import { byLabelText } from 'testing-library-selector';
|
||||||
|
|
||||||
import { setPluginExtensionsHook } from '@grafana/runtime';
|
import { config, setPluginExtensionsHook } from '@grafana/runtime';
|
||||||
import { contextSrv } from 'app/core/services/context_srv';
|
import { contextSrv } from 'app/core/services/context_srv';
|
||||||
import { RuleActionsButtons } from 'app/features/alerting/unified/components/rules/RuleActionsButtons';
|
import { RuleActionsButtons } from 'app/features/alerting/unified/components/rules/RuleActionsButtons';
|
||||||
import { setupMswServer } from 'app/features/alerting/unified/mockApi';
|
import { setupMswServer } from 'app/features/alerting/unified/mockApi';
|
||||||
@ -57,6 +57,12 @@ setPluginExtensionsHook(() => ({
|
|||||||
isLoading: false,
|
isLoading: false,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const clickCopyLink = async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
|
await user.click(await ui.moreButton.find());
|
||||||
|
await user.click(await screen.findByText(/copy link/i));
|
||||||
|
};
|
||||||
|
|
||||||
describe('RuleActionsButtons', () => {
|
describe('RuleActionsButtons', () => {
|
||||||
it('renders correct options for grafana managed rule', async () => {
|
it('renders correct options for grafana managed rule', async () => {
|
||||||
const user = userEvent.setup();
|
const user = userEvent.setup();
|
||||||
@ -123,4 +129,34 @@ describe('RuleActionsButtons', () => {
|
|||||||
|
|
||||||
expect(screen.queryByText(/delete/i)).not.toBeInTheDocument();
|
expect(screen.queryByText(/delete/i)).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('copy link', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
grantAllPermissions();
|
||||||
|
config.appUrl = 'http://localhost:3000/';
|
||||||
|
config.appSubUrl = '/sub';
|
||||||
|
});
|
||||||
|
|
||||||
|
it('copies correct URL for grafana managed alert rule', async () => {
|
||||||
|
const mockRule = getGrafanaRule({ rulerRule: mockGrafanaRulerRule({ uid: 'foo', provenance: 'file' }) });
|
||||||
|
|
||||||
|
render(<RuleActionsButtons rule={mockRule} rulesSource="grafana" />);
|
||||||
|
|
||||||
|
await clickCopyLink();
|
||||||
|
|
||||||
|
expect(await navigator.clipboard.readText()).toBe('http://localhost:3000/sub/alerting/grafana/foo/view');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('copies correct URL for cloud rule', async () => {
|
||||||
|
const mockRule = getCloudRule();
|
||||||
|
|
||||||
|
render(<RuleActionsButtons rule={mockRule} rulesSource="grafana" />);
|
||||||
|
|
||||||
|
await clickCopyLink();
|
||||||
|
|
||||||
|
expect(await navigator.clipboard.readText()).toBe(
|
||||||
|
'http://localhost:3000/sub/alerting/Prometheus-2/mockRule/find'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -61,7 +61,7 @@ export function createShareLink(ruleSource: RulesSource, rule: CombinedRule): st
|
|||||||
`/alerting/${encodeURIComponent(ruleSource.name)}/${encodeURIComponent(escapePathSeparators(rule.name))}/find`
|
`/alerting/${encodeURIComponent(ruleSource.name)}/${encodeURIComponent(escapePathSeparators(rule.name))}/find`
|
||||||
);
|
);
|
||||||
} else if (isGrafanaRulerRule(rule.rulerRule)) {
|
} else if (isGrafanaRulerRule(rule.rulerRule)) {
|
||||||
return createUrl(`/alerting/grafana/${rule.rulerRule.grafana_alert.uid}/view`);
|
return createAbsoluteUrl(`/alerting/grafana/${rule.rulerRule.grafana_alert.uid}/view`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -15,9 +15,7 @@ export function createAbsoluteUrl(
|
|||||||
const searchParamsString = searchParams.toString();
|
const searchParamsString = searchParams.toString();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const baseUrl = new URL(config.appSubUrl, config.appUrl);
|
const baseUrl = new URL(config.appSubUrl + path, config.appUrl);
|
||||||
baseUrl.pathname = path;
|
|
||||||
|
|
||||||
return `${baseUrl.href}${searchParamsString ? `?${searchParamsString}` : ''}`;
|
return `${baseUrl.href}${searchParamsString ? `?${searchParamsString}` : ''}`;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return createUrl(path, queryParams);
|
return createUrl(path, queryParams);
|
||||||
|
Loading…
Reference in New Issue
Block a user