Utils.tests.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /* eslint-env mocha */
  2. import sinon from 'sinon';
  3. import { expect } from 'chai';
  4. import { Random } from 'meteor/random';
  5. import '../utils';
  6. describe('Utils', function () {
  7. beforeEach(function () {
  8. sinon.stub(Utils, 'reload').callsFake(() => { });
  9. });
  10. afterEach(function () {
  11. window.localStorage.removeItem(boardView);
  12. sinon.restore();
  13. });
  14. const boardView = 'boardView';
  15. describe(Utils.setBoardView.name, function () {
  16. it('sets the board view if the user exists', function (done) {
  17. const viewId = Random.id();
  18. const user = {
  19. setBoardView: (view) => {
  20. expect(view).to.equal(viewId);
  21. done();
  22. },
  23. };
  24. sinon.stub(Meteor, 'user').callsFake(() => user);
  25. Utils.setBoardView(viewId);
  26. expect(window.localStorage.getItem(boardView)).to.equal(viewId);
  27. });
  28. it('sets a specific view if no user exists but a view is defined', function () {
  29. const views = [
  30. 'board-view-swimlanes',
  31. 'board-view-lists',
  32. 'board-view-cal'
  33. ];
  34. sinon.stub(Meteor, 'user').callsFake(() => { });
  35. views.forEach(viewName => {
  36. Utils.setBoardView(viewName);
  37. expect(window.localStorage.getItem(boardView)).to.equal(viewName);
  38. });
  39. });
  40. it('sets a default view if no user and no view are given', function () {
  41. sinon.stub(Meteor, 'user').callsFake(() => { });
  42. Utils.setBoardView();
  43. expect(window.localStorage.getItem(boardView)).to.equal('board-view-swimlanes');
  44. });
  45. });
  46. describe(Utils.unsetBoardView.name, function () {
  47. it('removes the boardview from localStoage', function () {
  48. window.localStorage.setItem(boardView, Random.id());
  49. window.localStorage.setItem('collapseSwimlane', Random.id());
  50. Utils.unsetBoardView();
  51. expect(window.localStorage.getItem(boardView)).to.equal(null);
  52. expect(window.localStorage.getItem('collapseSwimlane')).to.equal(null);
  53. });
  54. });
  55. describe(Utils.boardView.name, function () {
  56. it('returns the user\'s board view if a user exists', function () {
  57. const viewId = Random.id();
  58. const user = {};
  59. sinon.stub(Meteor, 'user').callsFake(() => user);
  60. expect(Utils.boardView()).to.equal(undefined);
  61. const boardView = Random.id();
  62. user.profile = { boardView };
  63. expect(Utils.boardView()).to.equal(boardView);
  64. });
  65. it('returns the current defined view', function () {
  66. const views = [
  67. 'board-view-swimlanes',
  68. 'board-view-lists',
  69. 'board-view-cal'
  70. ];
  71. sinon.stub(Meteor, 'user').callsFake(() => { });
  72. views.forEach(viewName => {
  73. window.localStorage.setItem(boardView, viewName);
  74. expect(Utils.boardView()).to.equal(viewName);
  75. });
  76. });
  77. it('returns a default if nothing is set', function () {
  78. sinon.stub(Meteor, 'user').callsFake(() => { });
  79. expect(Utils.boardView()).to.equal('board-view-swimlanes');
  80. expect(window.localStorage.getItem(boardView)).to.equal('board-view-swimlanes');
  81. });
  82. });
  83. describe(Utils.myCardsSort.name, function () {
  84. it('has no tests yet');
  85. });
  86. describe(Utils.myCardsSortToggle.name, function () {
  87. it('has no tests yet');
  88. });
  89. describe(Utils.setMyCardsSort.name, function () {
  90. it('has no tests yet');
  91. });
  92. describe(Utils.archivedBoardIds.name, function () {
  93. it('has no tests yet');
  94. });
  95. describe(Utils.dueCardsView.name, function () {
  96. it('has no tests yet');
  97. });
  98. describe(Utils.setDueCardsView.name, function () {
  99. it('has no tests yet');
  100. });
  101. describe(Utils.goBoardId.name, function () {
  102. it('has no tests yet');
  103. });
  104. describe(Utils.goCardId.name, function () {
  105. it('has no tests yet');
  106. });
  107. describe(Utils.processUploadedAttachment.name, function () {
  108. it('has no tests yet');
  109. });
  110. describe(Utils.shrinkImage.name, function () {
  111. it('has no tests yet');
  112. });
  113. describe(Utils.capitalize.name, function () {
  114. it('has no tests yet');
  115. });
  116. describe(Utils.isMiniScreen.name, function () {
  117. it('has no tests yet');
  118. });
  119. describe(Utils.isShowDesktopDragHandles.name, function () {
  120. it('has no tests yet');
  121. });
  122. describe(Utils.isTouchScreenOrShowDesktopDragHandles.name, function () {
  123. it('has no tests yet');
  124. });
  125. describe(Utils.calculateIndexData.name, function () {
  126. it('has no tests yet');
  127. });
  128. describe(Utils.calculateIndex.name, function () {
  129. it('has no tests yet');
  130. });
  131. describe(Utils.manageCustomUI.name, function () {
  132. it('has no tests yet');
  133. });
  134. describe(Utils.setCustomUI.name, function () {
  135. it('has no tests yet');
  136. });
  137. describe(Utils.setMatomo.name, function () {
  138. it('has no tests yet');
  139. });
  140. describe(Utils.manageMatomo.name, function () {
  141. it('has no tests yet');
  142. });
  143. describe(Utils.getTriggerActionDesc.name, function () {
  144. it('has no tests yet');
  145. });
  146. });