mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Add tests for HelpWizard (#94271)
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
import userEvent from '@testing-library/user-event';
|
||||||
|
import { render, screen } from 'test/test-utils';
|
||||||
|
|
||||||
import { FieldType, getDefaultTimeRange, LoadingState, toDataFrame } from '@grafana/data';
|
import { FieldType, getDefaultTimeRange, LoadingState, toDataFrame } from '@grafana/data';
|
||||||
import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks';
|
import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks';
|
||||||
|
import { config } from '@grafana/runtime';
|
||||||
import { SceneQueryRunner, SceneTimeRange, VizPanel, VizPanelMenu } from '@grafana/scenes';
|
import { SceneQueryRunner, SceneTimeRange, VizPanel, VizPanelMenu } from '@grafana/scenes';
|
||||||
|
import { contextSrv } from 'app/core/services/context_srv';
|
||||||
|
|
||||||
import { DashboardScene } from '../../scene/DashboardScene';
|
import { DashboardScene } from '../../scene/DashboardScene';
|
||||||
import { VizPanelLinks, VizPanelLinksMenu } from '../../scene/PanelLinks';
|
import { VizPanelLinks, VizPanelLinksMenu } from '../../scene/PanelLinks';
|
||||||
@@ -11,12 +14,65 @@ import { DefaultGridLayoutManager } from '../../scene/layout-default/DefaultGrid
|
|||||||
|
|
||||||
import { HelpWizard } from './HelpWizard';
|
import { HelpWizard } from './HelpWizard';
|
||||||
|
|
||||||
|
jest.mock('./utils.ts', () => ({
|
||||||
|
...jest.requireActual('./utils.ts'),
|
||||||
|
getGithubMarkdown: () => new Uint8Array(1024 * 1024).toString(),
|
||||||
|
}));
|
||||||
|
|
||||||
async function setup() {
|
async function setup() {
|
||||||
const { panel } = await buildTestScene();
|
const { panel } = await buildTestScene();
|
||||||
panel.getPlugin = () => getPanelPlugin({ skipDataQuery: false });
|
panel.getPlugin = () => getPanelPlugin({ skipDataQuery: false });
|
||||||
|
|
||||||
return render(<HelpWizard panel={panel} onClose={() => {}} />);
|
return render(<HelpWizard panel={panel} onClose={() => {}} />);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
describe('HelpWizard', () => {
|
||||||
|
it('should render support bundle info if user has support bundle access', async () => {
|
||||||
|
config.supportBundlesEnabled = true;
|
||||||
|
jest.spyOn(contextSrv, 'hasPermission').mockReturnValue(true);
|
||||||
|
|
||||||
|
setup();
|
||||||
|
expect(await screen.findByText(/You can also retrieve a support bundle/)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not render support bundle info if user does not have support bundle access', async () => {
|
||||||
|
config.supportBundlesEnabled = false;
|
||||||
|
setup();
|
||||||
|
|
||||||
|
expect(screen.queryByText('You can also retrieve a support bundle')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show error as alert', async () => {
|
||||||
|
setup();
|
||||||
|
await userEvent.click(await screen.findByTestId('data-testid Tab Data'));
|
||||||
|
await userEvent.click((await screen.findAllByText('Copy to clipboard'))[0]);
|
||||||
|
expect(await screen.findByText(/Snapshot is too large/)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('support tab', () => {
|
||||||
|
it('should render', async () => {
|
||||||
|
setup();
|
||||||
|
expect(await screen.findByText(/Modify the original data to hide sensitive information/)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('data tab', () => {
|
||||||
|
it('should show "copy to clipboard" button if template is "GitHub comment"', async () => {
|
||||||
|
setup();
|
||||||
|
await userEvent.click(await screen.findByTestId('data-testid Tab Data'));
|
||||||
|
expect(await screen.findByText('Copy to clipboard')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show download button for other templates', async () => {
|
||||||
|
setup();
|
||||||
|
await userEvent.click(await screen.findByTestId('data-testid Tab Data'));
|
||||||
|
await userEvent.click(await screen.findByRole('combobox'));
|
||||||
|
await userEvent.click(await screen.findByText(/Panel support snapshot/));
|
||||||
|
expect(await screen.findByText(/^Download/)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('SupportSnapshot', () => {
|
describe('SupportSnapshot', () => {
|
||||||
it('Can render', async () => {
|
it('Can render', async () => {
|
||||||
setup();
|
setup();
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export function HelpWizard({ panel, onClose }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Drawer
|
<Drawer
|
||||||
title={`Get help with this panel`}
|
title="Get help with this panel"
|
||||||
size="lg"
|
size="lg"
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
subtitle={
|
subtitle={
|
||||||
@@ -150,7 +150,7 @@ export function HelpWizard({ panel, onClose }: Props) {
|
|||||||
<>
|
<>
|
||||||
<Field
|
<Field
|
||||||
label="Randomize data"
|
label="Randomize data"
|
||||||
description="Modify the original data to hide sensitve information. Note the lengths will stay the same, and duplicate values will be equal."
|
description="Modify the original data to hide sensitive information. Note the lengths will stay the same, and duplicate values will be equal."
|
||||||
>
|
>
|
||||||
<Stack>
|
<Stack>
|
||||||
<InlineSwitch
|
<InlineSwitch
|
||||||
|
|||||||
Reference in New Issue
Block a user