DashboardViewStateSrv.test.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import config from 'app/core/config';
  2. import { DashboardViewStateSrv } from './DashboardViewStateSrv';
  3. import { DashboardModel } from '../state/DashboardModel';
  4. describe('when updating view state', () => {
  5. const location = {
  6. replace: jest.fn(),
  7. search: jest.fn(),
  8. };
  9. const $scope = {
  10. appEvent: jest.fn(),
  11. onAppEvent: jest.fn(() => {}),
  12. dashboard: new DashboardModel({
  13. panels: [{ id: 1 }],
  14. }),
  15. };
  16. let viewState;
  17. beforeEach(() => {
  18. config.bootData = {
  19. user: {
  20. orgId: 1,
  21. },
  22. };
  23. });
  24. describe('to fullscreen true and edit true', () => {
  25. beforeEach(() => {
  26. location.search = jest.fn(() => {
  27. return { fullscreen: true, edit: true, panelId: 1 };
  28. });
  29. viewState = new DashboardViewStateSrv($scope, location, {});
  30. });
  31. it('should update querystring and view state', () => {
  32. const updateState = { fullscreen: true, edit: true, panelId: 1 };
  33. viewState.update(updateState);
  34. expect(location.search).toHaveBeenCalledWith({
  35. edit: true,
  36. editview: null,
  37. fullscreen: true,
  38. orgId: 1,
  39. panelId: 1,
  40. });
  41. expect(viewState.dashboard.meta.fullscreen).toBe(true);
  42. expect(viewState.state.fullscreen).toBe(true);
  43. });
  44. });
  45. describe('to fullscreen false', () => {
  46. beforeEach(() => {
  47. viewState = new DashboardViewStateSrv($scope, location, {});
  48. });
  49. it('should remove params from query string', () => {
  50. viewState.update({ fullscreen: true, panelId: 1, edit: true });
  51. viewState.update({ fullscreen: false });
  52. expect(viewState.state.fullscreen).toBe(null);
  53. });
  54. });
  55. });