mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
ShareDrawer: Share Snapshot menu item condition (#89733)
This commit is contained in:
parent
06d5850396
commit
e6e163eaf5
@ -2,10 +2,11 @@ import { render, screen } from '@testing-library/react';
|
||||
|
||||
import { selectors as e2eSelectors } from '@grafana/e2e-selectors';
|
||||
import { SceneGridLayout, SceneTimeRange, VizPanel } from '@grafana/scenes';
|
||||
import { contextSrv } from 'app/core/services/context_srv';
|
||||
|
||||
import { config } from '../../../../core/config';
|
||||
import { DashboardGridItem } from '../../scene/DashboardGridItem';
|
||||
import { DashboardScene } from '../../scene/DashboardScene';
|
||||
import { DashboardScene, DashboardSceneState } from '../../scene/DashboardScene';
|
||||
|
||||
import ShareMenu from './ShareMenu';
|
||||
|
||||
@ -16,26 +17,66 @@ jest.mock('app/core/utils/shortLinks', () => ({
|
||||
}));
|
||||
|
||||
const selector = e2eSelectors.pages.Dashboard.DashNav.newShareButton.menu;
|
||||
|
||||
describe('ShareMenu', () => {
|
||||
afterEach(() => {
|
||||
jest.resetModules();
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should render menu items', async () => {
|
||||
Object.defineProperty(contextSrv, 'isSignedIn', {
|
||||
value: true,
|
||||
});
|
||||
config.featureToggles.publicDashboards = true;
|
||||
config.publicDashboardsEnabled = true;
|
||||
setup();
|
||||
config.snapshotEnabled = true;
|
||||
setup({ meta: { canEdit: true } });
|
||||
|
||||
expect(await screen.findByTestId(selector.shareInternally)).toBeInTheDocument();
|
||||
expect(await screen.findByTestId(selector.shareExternally)).toBeInTheDocument();
|
||||
expect(await screen.findByTestId(selector.shareSnapshot)).toBeInTheDocument();
|
||||
});
|
||||
it('should no share externally when public dashboard is disabled', async () => {
|
||||
it('should not share externally when public dashboard is disabled', async () => {
|
||||
config.featureToggles.publicDashboards = false;
|
||||
config.publicDashboardsEnabled = false;
|
||||
setup();
|
||||
|
||||
expect(await screen.queryByTestId(selector.shareExternally)).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId(selector.shareExternally)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
describe('ShareSnapshot', () => {
|
||||
it('should not share snapshot when user is not signed in', async () => {
|
||||
config.snapshotEnabled = true;
|
||||
Object.defineProperty(contextSrv, 'isSignedIn', {
|
||||
value: false,
|
||||
});
|
||||
setup({ meta: { canEdit: true } });
|
||||
|
||||
expect(screen.queryByTestId(selector.shareSnapshot)).not.toBeInTheDocument();
|
||||
});
|
||||
it('should not share snapshot when snapshot is not enabled', async () => {
|
||||
Object.defineProperty(contextSrv, 'isSignedIn', {
|
||||
value: true,
|
||||
});
|
||||
config.snapshotEnabled = false;
|
||||
setup({ meta: { canEdit: true } });
|
||||
|
||||
expect(screen.queryByTestId(selector.shareSnapshot)).not.toBeInTheDocument();
|
||||
});
|
||||
it('should not share snapshot when dashboard cannot edit', async () => {
|
||||
Object.defineProperty(contextSrv, 'isSignedIn', {
|
||||
value: true,
|
||||
});
|
||||
config.snapshotEnabled = true;
|
||||
setup({ meta: { canEdit: false } });
|
||||
|
||||
expect(screen.queryByTestId(selector.shareSnapshot)).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function setup() {
|
||||
function setup(overrides?: Partial<DashboardSceneState>) {
|
||||
const panel = new VizPanel({
|
||||
title: 'Panel A',
|
||||
pluginId: 'table',
|
||||
@ -58,6 +99,7 @@ function setup() {
|
||||
}),
|
||||
],
|
||||
}),
|
||||
...overrides,
|
||||
});
|
||||
|
||||
render(<ShareMenu dashboard={dashboard} />);
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { selectors as e2eSelectors } from '@grafana/e2e-selectors';
|
||||
import { config } from '@grafana/runtime';
|
||||
import { VizPanel } from '@grafana/scenes';
|
||||
import { Menu } from '@grafana/ui';
|
||||
import { contextSrv } from 'app/core/core';
|
||||
import { t } from 'app/core/internationalization';
|
||||
|
||||
import { isPublicDashboardsEnabled } from '../../../dashboard/components/ShareModal/SharePublicDashboard/SharePublicDashboardUtils';
|
||||
@ -58,12 +60,14 @@ export default function ShareMenu({ dashboard, panel }: { dashboard: DashboardSc
|
||||
onClick={onShareExternallyClick}
|
||||
/>
|
||||
)}
|
||||
<Menu.Item
|
||||
testId={newShareButtonSelector.shareSnapshot}
|
||||
label={t('share-dashboard.menu.share-snapshot-title', 'Share snapshot')}
|
||||
icon="camera"
|
||||
onClick={onShareSnapshotClick}
|
||||
/>
|
||||
{contextSrv.isSignedIn && config.snapshotEnabled && dashboard.canEditDashboard() && (
|
||||
<Menu.Item
|
||||
testId={newShareButtonSelector.shareSnapshot}
|
||||
label={t('share-dashboard.menu.share-snapshot-title', 'Share snapshot')}
|
||||
icon="camera"
|
||||
onClick={onShareSnapshotClick}
|
||||
/>
|
||||
)}
|
||||
</Menu>
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user