utils.test.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { REPEAT_DIR_HORIZONTAL } from '../../../core/constants';
  2. import { PanelModel } from './PanelModel';
  3. import { deleteScopeVars, isOnTheSameGridRow } from './utils';
  4. describe('isOnTheSameGridRow', () => {
  5. describe('when source panel is next to a panel', () => {
  6. it('then it should return true', () => {
  7. const sourcePanel = new PanelModel({ gridPos: { x: 0, y: 1, w: 4, h: 4 } });
  8. const otherPanel = new PanelModel({ gridPos: { x: 4, y: 1, w: 4, h: 4 } });
  9. expect(isOnTheSameGridRow(sourcePanel, otherPanel)).toBe(true);
  10. });
  11. });
  12. describe('when source panel is not next to a panel', () => {
  13. it('then it should return false', () => {
  14. const sourcePanel = new PanelModel({ gridPos: { x: 0, y: 1, w: 4, h: 4 } });
  15. const otherPanel = new PanelModel({ gridPos: { x: 4, y: 5, w: 4, h: 4 } });
  16. expect(isOnTheSameGridRow(sourcePanel, otherPanel)).toBe(false);
  17. });
  18. });
  19. describe('when source panel is repeated horizontally', () => {
  20. it('then it should return false', () => {
  21. const sourcePanel = new PanelModel({
  22. gridPos: { x: 0, y: 1, w: 4, h: 4 },
  23. repeatDirection: REPEAT_DIR_HORIZONTAL,
  24. });
  25. const otherPanel = new PanelModel({ gridPos: { x: 4, y: 1, w: 4, h: 4 } });
  26. expect(isOnTheSameGridRow(sourcePanel, otherPanel)).toBe(false);
  27. });
  28. });
  29. });
  30. describe('deleteScopeVars', () => {
  31. describe('when called with a collapsed row with panels', () => {
  32. it('then scopedVars should be deleted on the row and all collapsed panels', () => {
  33. const panel1 = new PanelModel({
  34. id: 1,
  35. type: 'row',
  36. collapsed: true,
  37. scopedVars: { job: { value: 'myjob', text: 'myjob' } },
  38. panels: [
  39. { id: 2, type: 'graph', title: 'Graph', scopedVars: { job: { value: 'myjob', text: 'myjob' } } },
  40. { id: 3, type: 'graph2', title: 'Graph2', scopedVars: { job: { value: 'myjob', text: 'myjob' } } },
  41. ],
  42. });
  43. expect(panel1.scopedVars).toBeDefined();
  44. expect(panel1.panels?.[0].scopedVars).toBeDefined();
  45. expect(panel1.panels?.[1].scopedVars).toBeDefined();
  46. deleteScopeVars([panel1]);
  47. expect(panel1.scopedVars).toBeUndefined();
  48. expect(panel1.panels?.[0].scopedVars).toBeUndefined();
  49. expect(panel1.panels?.[1].scopedVars).toBeUndefined();
  50. });
  51. });
  52. });