SharePublicDashboard.test.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { fireEvent, render, screen, waitFor } from '@testing-library/react';
  2. import React from 'react';
  3. import config from 'app/core/config';
  4. import { DashboardModel, PanelModel } from 'app/features/dashboard/state';
  5. import { ShareModal } from './ShareModal';
  6. jest.mock('app/core/core', () => {
  7. return {
  8. contextSrv: {
  9. hasPermission: () => true,
  10. },
  11. appEvents: {
  12. subscribe: () => {
  13. return {
  14. unsubscribe: () => {},
  15. };
  16. },
  17. emit: () => {},
  18. },
  19. };
  20. });
  21. describe('SharePublic', () => {
  22. let originalBootData: any;
  23. beforeAll(() => {
  24. originalBootData = config.bootData;
  25. config.appUrl = 'http://dashboards.grafana.com/';
  26. config.bootData = {
  27. user: {
  28. orgId: 1,
  29. },
  30. } as any;
  31. });
  32. afterAll(() => {
  33. config.bootData = originalBootData;
  34. });
  35. it('does not render share panel when public dashboards feature is disabled', () => {
  36. const mockDashboard = new DashboardModel({
  37. uid: 'mockDashboardUid',
  38. });
  39. const mockPanel = new PanelModel({
  40. id: 'mockPanelId',
  41. });
  42. render(<ShareModal panel={mockPanel} dashboard={mockDashboard} onDismiss={() => {}} />);
  43. expect(screen.getByRole('tablist')).toHaveTextContent('Link');
  44. expect(screen.getByRole('tablist')).not.toHaveTextContent('Public Dashboard');
  45. });
  46. it('renders share panel when public dashboards feature is enabled', async () => {
  47. config.featureToggles.publicDashboards = true;
  48. const mockDashboard = new DashboardModel({
  49. uid: 'mockDashboardUid',
  50. });
  51. const mockPanel = new PanelModel({
  52. id: 'mockPanelId',
  53. });
  54. render(<ShareModal panel={mockPanel} dashboard={mockDashboard} onDismiss={() => {}} />);
  55. await waitFor(() => screen.getByText('Link'));
  56. expect(screen.getByRole('tablist')).toHaveTextContent('Link');
  57. expect(screen.getByRole('tablist')).toHaveTextContent('Public Dashboard');
  58. fireEvent.click(screen.getByText('Public Dashboard'));
  59. await waitFor(() => screen.getByText('Enabled'));
  60. });
  61. });