DashNavTimeControls.test.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { render } from '@testing-library/react';
  2. import React from 'react';
  3. import { getDashboardModel } from '../../../../../test/helpers/getDashboardModel';
  4. import { DashboardModel } from '../../state/DashboardModel';
  5. import { DashNavTimeControls } from './DashNavTimeControls';
  6. describe('DashNavTimeControls', () => {
  7. let dashboardModel: DashboardModel;
  8. beforeEach(() => {
  9. const json = {
  10. panels: [
  11. {
  12. datasource: null,
  13. gridPos: {
  14. h: 3,
  15. w: 24,
  16. x: 0,
  17. y: 8,
  18. },
  19. id: 1,
  20. type: 'welcome',
  21. },
  22. ],
  23. refresh: '',
  24. templating: {
  25. list: [],
  26. },
  27. };
  28. dashboardModel = getDashboardModel(json);
  29. });
  30. it('renders RefreshPicker with run button in panel view', () => {
  31. const container = render(
  32. <DashNavTimeControls dashboard={dashboardModel} onChangeTimeZone={jest.fn()} key="time-controls" />
  33. );
  34. expect(container.queryByLabelText(/Refresh dashboard/i)).toBeInTheDocument();
  35. });
  36. it('renders RefreshPicker with interval button in panel view', () => {
  37. const container = render(
  38. <DashNavTimeControls dashboard={dashboardModel} onChangeTimeZone={jest.fn()} key="time-controls" />
  39. );
  40. expect(container.queryByLabelText(/Choose refresh time interval/i)).toBeInTheDocument();
  41. });
  42. it('should not render RefreshPicker interval button in panel edit', () => {
  43. const panel: any = { destroy: jest.fn(), isEditing: true };
  44. dashboardModel.startRefresh = jest.fn();
  45. dashboardModel.panelInEdit = panel;
  46. const container = render(
  47. <DashNavTimeControls dashboard={dashboardModel} onChangeTimeZone={jest.fn()} key="time-controls" />
  48. );
  49. expect(container.queryByLabelText(/Choose refresh time interval/i)).not.toBeInTheDocument();
  50. });
  51. it('should render RefreshPicker run button in panel edit', () => {
  52. const panel: any = { destroy: jest.fn(), isEditing: true };
  53. dashboardModel.startRefresh = jest.fn();
  54. dashboardModel.panelInEdit = panel;
  55. const container = render(
  56. <DashNavTimeControls dashboard={dashboardModel} onChangeTimeZone={jest.fn()} key="time-controls" />
  57. );
  58. expect(container.queryByLabelText(/Refresh dashboard/i)).toBeInTheDocument();
  59. });
  60. });