viewstate_srv.test.ts 1.8 KB

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