dashboard_list_ctrl.jest.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. import {DashboardListCtrl} from '../dashboard_list_ctrl';
  2. import q from 'q';
  3. describe('DashboardListCtrl', () => {
  4. let ctrl;
  5. describe('when fetching dashboards', () => {
  6. describe('and dashboard has parent that is not in search result', () => {
  7. beforeEach(() => {
  8. const response = [
  9. {
  10. id: 399,
  11. title: "Dashboard Test",
  12. uri: "db/dashboard-test",
  13. type: "dash-db",
  14. tags: [],
  15. isStarred: false,
  16. folderId: 410,
  17. folderTitle: "afolder",
  18. folderSlug: "afolder"
  19. }
  20. ];
  21. ctrl = new DashboardListCtrl({search: () => q.resolve(response)}, {getNav: () => {}}, q);
  22. return ctrl.getDashboards();
  23. });
  24. it('should add the missing parent folder to the result', () => {
  25. expect(ctrl.dashboards.length).toEqual(2);
  26. expect(ctrl.dashboards[0].id).toEqual(410);
  27. expect(ctrl.dashboards[1].id).toEqual(399);
  28. });
  29. });
  30. beforeEach(() => {
  31. const response = [
  32. {
  33. id: 410,
  34. title: "afolder",
  35. uri: "db/afolder",
  36. type: "dash-folder",
  37. tags: [],
  38. isStarred: false
  39. },
  40. {
  41. id: 3,
  42. title: "something else",
  43. uri: "db/something-else",
  44. type: "dash-db",
  45. tags: [],
  46. isStarred: false,
  47. },
  48. {
  49. id: 399,
  50. title: "Dashboard Test",
  51. uri: "db/dashboard-test",
  52. type: "dash-db",
  53. tags: [],
  54. isStarred: false,
  55. folderId: 410,
  56. folderTitle: "afolder",
  57. folderSlug: "afolder"
  58. }
  59. ];
  60. ctrl = new DashboardListCtrl({search: () => q.resolve(response)}, {getNav: () => {}}, null);
  61. return ctrl.getDashboards();
  62. });
  63. it('should group them in folders', () => {
  64. expect(ctrl.dashboards.length).toEqual(3);
  65. expect(ctrl.dashboards[0].id).toEqual(410);
  66. expect(ctrl.dashboards[1].id).toEqual(399);
  67. expect(ctrl.dashboards[2].id).toEqual(3);
  68. });
  69. });
  70. describe('when selecting dashboards', () => {
  71. let ctrl;
  72. beforeEach(() => {
  73. ctrl = new DashboardListCtrl({search: () => q.resolve([])}, {getNav: () => {}}, null);
  74. });
  75. describe('and no dashboards are selected', () => {
  76. beforeEach(() => {
  77. ctrl.dashboards = [
  78. {id: 1, type: 'dash-folder'},
  79. {id: 2, type: 'dash-db'}
  80. ];
  81. ctrl.selectionChanged();
  82. });
  83. it('should disable Move To button', () => {
  84. expect(ctrl.canMove).toBeFalsy();
  85. });
  86. it('should disable delete button', () => {
  87. expect(ctrl.canDelete).toBeFalsy();
  88. });
  89. });
  90. describe('and one dashboard in root is selected', () => {
  91. beforeEach(() => {
  92. ctrl.dashboards = [
  93. {id: 1, type: 'dash-folder'},
  94. {id: 2, type: 'dash-db', checked: true}
  95. ];
  96. ctrl.selectionChanged();
  97. });
  98. it('should enable Move To button', () => {
  99. expect(ctrl.canMove).toBeTruthy();
  100. });
  101. it('should enable delete button', () => {
  102. expect(ctrl.canDelete).toBeTruthy();
  103. });
  104. });
  105. describe('and one child dashboard is selected', () => {
  106. beforeEach(() => {
  107. ctrl.dashboards = [
  108. {id: 1, type: 'dash-folder'},
  109. {id: 2, type: 'dash-child', checked: true}
  110. ];
  111. ctrl.selectionChanged();
  112. });
  113. it('should enable Move To button', () => {
  114. expect(ctrl.canMove).toBeTruthy();
  115. });
  116. it('should enable delete button', () => {
  117. expect(ctrl.canDelete).toBeTruthy();
  118. });
  119. });
  120. describe('and one child dashboard and one dashboard is selected', () => {
  121. beforeEach(() => {
  122. ctrl.dashboards = [
  123. {id: 1, type: 'dash-folder'},
  124. {id: 2, type: 'dash-child', checked: true}
  125. ];
  126. ctrl.selectionChanged();
  127. });
  128. it('should enable Move To button', () => {
  129. expect(ctrl.canMove).toBeTruthy();
  130. });
  131. it('should enable delete button', () => {
  132. expect(ctrl.canDelete).toBeTruthy();
  133. });
  134. });
  135. describe('and one child dashboard and one folder is selected', () => {
  136. beforeEach(() => {
  137. ctrl.dashboards = [
  138. {id: 1, type: 'dash-folder', checked: true},
  139. {id: 2, type: 'dash-child', checked: true}
  140. ];
  141. ctrl.selectionChanged();
  142. });
  143. it('should disable Move To button', () => {
  144. expect(ctrl.canMove).toBeFalsy();
  145. });
  146. it('should enable delete button', () => {
  147. expect(ctrl.canDelete).toBeTruthy();
  148. });
  149. });
  150. });
  151. describe('when deleting dashboards', () => {
  152. beforeEach(() => {
  153. ctrl = new DashboardListCtrl({search: () => q.resolve([])}, {getNav: () => {}}, q);
  154. ctrl.dashboards = [
  155. {id: 1, type: 'dash-folder', checked: true},
  156. {id: 2, type: 'dash-child', checked: true, folderId: 1},
  157. {id: 3, type: 'dash-db', checked: true}
  158. ];
  159. });
  160. it('should filter out children if parent is selected', () => {
  161. const toBeDeleted = ctrl.getDashboardsToDelete();
  162. expect(toBeDeleted.length).toEqual(2);
  163. expect(toBeDeleted[0].id).toEqual(1);
  164. expect(toBeDeleted[1].id).toEqual(3);
  165. });
  166. });
  167. });