From 45698720482fd943905e3680b08a30fe283168e7 Mon Sep 17 00:00:00 2001 From: kay delaney <45561153+kaydelaney@users.noreply.github.com> Date: Mon, 7 Oct 2024 10:02:01 +0100 Subject: [PATCH] Chore: Add tests for HelpWizard (#94271) --- .../inspect/HelpWizard/HelpWizard.test.tsx | 58 ++++++++++++++++++- .../inspect/HelpWizard/HelpWizard.tsx | 4 +- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/public/app/features/dashboard-scene/inspect/HelpWizard/HelpWizard.test.tsx b/public/app/features/dashboard-scene/inspect/HelpWizard/HelpWizard.test.tsx index da8dd9998f7..276c71f61dd 100644 --- a/public/app/features/dashboard-scene/inspect/HelpWizard/HelpWizard.test.tsx +++ b/public/app/features/dashboard-scene/inspect/HelpWizard/HelpWizard.test.tsx @@ -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 { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks'; +import { config } from '@grafana/runtime'; import { SceneQueryRunner, SceneTimeRange, VizPanel, VizPanelMenu } from '@grafana/scenes'; +import { contextSrv } from 'app/core/services/context_srv'; import { DashboardScene } from '../../scene/DashboardScene'; import { VizPanelLinks, VizPanelLinksMenu } from '../../scene/PanelLinks'; @@ -11,12 +14,65 @@ import { DefaultGridLayoutManager } from '../../scene/layout-default/DefaultGrid import { HelpWizard } from './HelpWizard'; +jest.mock('./utils.ts', () => ({ + ...jest.requireActual('./utils.ts'), + getGithubMarkdown: () => new Uint8Array(1024 * 1024).toString(), +})); + async function setup() { const { panel } = await buildTestScene(); panel.getPlugin = () => getPanelPlugin({ skipDataQuery: false }); return render( {}} />); } + +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', () => { it('Can render', async () => { setup(); diff --git a/public/app/features/dashboard-scene/inspect/HelpWizard/HelpWizard.tsx b/public/app/features/dashboard-scene/inspect/HelpWizard/HelpWizard.tsx index 59662f7c513..960df0696da 100644 --- a/public/app/features/dashboard-scene/inspect/HelpWizard/HelpWizard.tsx +++ b/public/app/features/dashboard-scene/inspect/HelpWizard/HelpWizard.tsx @@ -69,7 +69,7 @@ export function HelpWizard({ panel, onClose }: Props) { return (