playlist_edit_ctrl.test.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import '../playlist_edit_ctrl';
  2. import { PlaylistEditCtrl } from '../playlist_edit_ctrl';
  3. describe('PlaylistEditCtrl', () => {
  4. let ctx: any;
  5. beforeEach(() => {
  6. const navModelSrv = {
  7. getNav: () => {
  8. return { breadcrumbs: [], node: {} };
  9. },
  10. };
  11. ctx = new PlaylistEditCtrl(null, null, null, { current: { params: {} } }, navModelSrv);
  12. ctx.dashboardresult = [{ id: 2, title: 'dashboard: 2' }, { id: 3, title: 'dashboard: 3' }];
  13. ctx.tagresult = [{ term: 'graphite', count: 1 }, { term: 'nyc', count: 2 }];
  14. });
  15. describe('searchresult returns 2 dashboards, ', () => {
  16. it('found dashboard should be 2', () => {
  17. expect(ctx.dashboardresult.length).toBe(2);
  18. });
  19. it('filtred result should be 2', () => {
  20. ctx.filterFoundPlaylistItems();
  21. expect(ctx.filteredDashboards.length).toBe(2);
  22. expect(ctx.filteredTags.length).toBe(2);
  23. });
  24. describe('adds one dashboard to playlist, ', () => {
  25. beforeEach(() => {
  26. ctx.addPlaylistItem({ id: 2, title: 'dashboard: 2' });
  27. ctx.addTagPlaylistItem({ term: 'graphite' });
  28. ctx.filterFoundPlaylistItems();
  29. });
  30. it('playlistitems should be increased by one', () => {
  31. expect(ctx.playlistItems.length).toBe(2);
  32. });
  33. it('filtred playlistitems should be reduced by one', () => {
  34. expect(ctx.filteredDashboards.length).toBe(1);
  35. expect(ctx.filteredTags.length).toBe(1);
  36. });
  37. it('found dashboard should be 2', () => {
  38. expect(ctx.dashboardresult.length).toBe(2);
  39. });
  40. describe('removes one dashboard from playlist, ', () => {
  41. beforeEach(() => {
  42. ctx.removePlaylistItem(ctx.playlistItems[0]);
  43. ctx.removePlaylistItem(ctx.playlistItems[0]);
  44. ctx.filterFoundPlaylistItems();
  45. });
  46. it('playlistitems should be increased by one', () => {
  47. expect(ctx.playlistItems.length).toBe(0);
  48. });
  49. it('found dashboard should be 2', () => {
  50. expect(ctx.dashboardresult.length).toBe(2);
  51. expect(ctx.filteredDashboards.length).toBe(2);
  52. expect(ctx.filteredTags.length).toBe(2);
  53. expect(ctx.tagresult.length).toBe(2);
  54. });
  55. });
  56. });
  57. });
  58. });