viewstate_srv_specs.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. describe('when updating view state', function() {
  5. var viewState, location;
  6. var timeSrv = {};
  7. var templateSrv = {};
  8. var contextSrv = {
  9. user: {
  10. orgId: 19,
  11. },
  12. };
  13. beforeEach(function() {
  14. config.bootData = {
  15. user: {
  16. orgId: 1,
  17. },
  18. };
  19. });
  20. beforeEach(angularMocks.module('grafana.services'));
  21. beforeEach(
  22. angularMocks.module(function($provide) {
  23. $provide.value('timeSrv', timeSrv);
  24. $provide.value('templateSrv', templateSrv);
  25. $provide.value('contextSrv', contextSrv);
  26. })
  27. );
  28. beforeEach(
  29. angularMocks.inject(function(dashboardViewStateSrv, $location, $rootScope) {
  30. $rootScope.onAppEvent = function() {};
  31. $rootScope.dashboard = {
  32. meta: {},
  33. panels: [],
  34. };
  35. viewState = dashboardViewStateSrv.create($rootScope);
  36. location = $location;
  37. })
  38. );
  39. describe('to fullscreen true and edit true', function() {
  40. it('should update querystring and view state', function() {
  41. var updateState = { fullscreen: true, edit: true, panelId: 1 };
  42. viewState.update(updateState);
  43. expect(location.search()).to.eql({
  44. fullscreen: true,
  45. edit: true,
  46. panelId: 1,
  47. orgId: 1,
  48. });
  49. expect(viewState.dashboard.meta.fullscreen).to.be(true);
  50. expect(viewState.state.fullscreen).to.be(true);
  51. });
  52. });
  53. describe('to fullscreen false', function() {
  54. it('should remove params from query string', function() {
  55. viewState.update({ fullscreen: true, panelId: 1, edit: true });
  56. viewState.update({ fullscreen: false });
  57. expect(viewState.dashboard.meta.fullscreen).to.be(false);
  58. expect(viewState.state.fullscreen).to.be(null);
  59. });
  60. });
  61. });