1
0

filesummarySpec.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /**
  2. * ownCloud
  3. *
  4. * @author Vincent Petry
  5. * @copyright 2014 Vincent Petry <pvince81@owncloud.com>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  9. * License as published by the Free Software Foundation; either
  10. * version 3 of the License, or any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public
  18. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. /* global FileSummary */
  22. describe('OCA.Files.FileSummary tests', function() {
  23. var FileSummary = OCA.Files.FileSummary;
  24. var $container;
  25. beforeEach(function() {
  26. $container = $('<table><tr></tr></table>').find('tr');
  27. });
  28. afterEach(function() {
  29. $container = null;
  30. });
  31. it('renders summary as text', function() {
  32. var s = new FileSummary($container);
  33. s.setSummary({
  34. totalDirs: 5,
  35. totalFiles: 2,
  36. totalSize: 256000
  37. });
  38. expect($container.hasClass('hidden')).toEqual(false);
  39. expect($container.find('.info').text()).toEqual('5 folders and 2 files');
  40. expect($container.find('.filesize').text()).toEqual('250 KB');
  41. });
  42. it('hides summary when no files or folders', function() {
  43. var s = new FileSummary($container);
  44. s.setSummary({
  45. totalDirs: 0,
  46. totalFiles: 0,
  47. totalSize: 0
  48. });
  49. expect($container.hasClass('hidden')).toEqual(true);
  50. });
  51. it('increases summary when adding files', function() {
  52. var s = new FileSummary($container);
  53. s.setSummary({
  54. totalDirs: 5,
  55. totalFiles: 2,
  56. totalSize: 256000
  57. });
  58. s.add({type: 'file', size: 256000});
  59. s.add({type: 'dir', size: 100});
  60. s.update();
  61. expect($container.hasClass('hidden')).toEqual(false);
  62. expect($container.find('.info').text()).toEqual('6 folders and 3 files');
  63. expect($container.find('.filesize').text()).toEqual('500 KB');
  64. expect(s.summary.totalDirs).toEqual(6);
  65. expect(s.summary.totalFiles).toEqual(3);
  66. expect(s.summary.totalSize).toEqual(512100);
  67. });
  68. it('decreases summary when removing files', function() {
  69. var s = new FileSummary($container);
  70. s.setSummary({
  71. totalDirs: 5,
  72. totalFiles: 2,
  73. totalSize: 256000
  74. });
  75. s.remove({type: 'file', size: 128000});
  76. s.remove({type: 'dir', size: 100});
  77. s.update();
  78. expect($container.hasClass('hidden')).toEqual(false);
  79. expect($container.find('.info').text()).toEqual('4 folders and 1 file');
  80. expect($container.find('.filesize').text()).toEqual('125 KB');
  81. expect(s.summary.totalDirs).toEqual(4);
  82. expect(s.summary.totalFiles).toEqual(1);
  83. expect(s.summary.totalSize).toEqual(127900);
  84. });
  85. it('renders filtered summary as text', function() {
  86. var s = new FileSummary($container);
  87. s.setSummary({
  88. totalDirs: 5,
  89. totalFiles: 2,
  90. totalSize: 256000,
  91. filter: 'foo'
  92. });
  93. expect($container.hasClass('hidden')).toEqual(false);
  94. expect($container.find('.info').text()).toEqual('5 folders and 2 files match \'foo\'');
  95. expect($container.find('.filesize').text()).toEqual('250 KB');
  96. });
  97. it('hides filtered summary when no files or folders', function() {
  98. var s = new FileSummary($container);
  99. s.setSummary({
  100. totalDirs: 0,
  101. totalFiles: 0,
  102. totalSize: 0,
  103. filter: 'foo'
  104. });
  105. expect($container.hasClass('hidden')).toEqual(true);
  106. });
  107. it('increases filtered summary when adding files', function() {
  108. var s = new FileSummary($container);
  109. s.setSummary({
  110. totalDirs: 5,
  111. totalFiles: 2,
  112. totalSize: 256000,
  113. filter: 'foo'
  114. });
  115. s.add({name: 'bar.txt', type: 'file', size: 256000});
  116. s.add({name: 'foo.txt', type: 'file', size: 256001});
  117. s.add({name: 'bar', type: 'dir', size: 100});
  118. s.add({name: 'foo', type: 'dir', size: 102});
  119. s.update();
  120. expect($container.hasClass('hidden')).toEqual(false);
  121. expect($container.find('.info').text()).toEqual('6 folders and 3 files match \'foo\'');
  122. expect($container.find('.filesize').text()).toEqual('500 KB');
  123. expect(s.summary.totalDirs).toEqual(6);
  124. expect(s.summary.totalFiles).toEqual(3);
  125. expect(s.summary.totalSize).toEqual(512103);
  126. });
  127. it('decreases filtered summary when removing files', function() {
  128. var s = new FileSummary($container);
  129. s.setSummary({
  130. totalDirs: 5,
  131. totalFiles: 2,
  132. totalSize: 256000,
  133. filter: 'foo'
  134. });
  135. s.remove({name: 'bar.txt', type: 'file', size: 128000});
  136. s.remove({name: 'foo.txt', type: 'file', size: 127999});
  137. s.remove({name: 'bar', type: 'dir', size: 100});
  138. s.remove({name: 'foo', type: 'dir', size: 98});
  139. s.update();
  140. expect($container.hasClass('hidden')).toEqual(false);
  141. expect($container.find('.info').text()).toEqual('4 folders and 1 file match \'foo\'');
  142. expect($container.find('.filesize').text()).toEqual('125 KB');
  143. expect(s.summary.totalDirs).toEqual(4);
  144. expect(s.summary.totalFiles).toEqual(1);
  145. expect(s.summary.totalSize).toEqual(127903);
  146. });
  147. it('properly sum up pending folder sizes after adding', function() {
  148. var s = new FileSummary($container);
  149. s.setSummary({
  150. totalDirs: 0,
  151. totalFiles: 0,
  152. totalSize: 0
  153. });
  154. s.add({type: 'dir', size: -1});
  155. s.update();
  156. expect($container.hasClass('hidden')).toEqual(false);
  157. expect($container.find('.info').text()).toEqual('1 folder and 0 files');
  158. expect($container.find('.filesize').text()).toEqual('Pending');
  159. expect(s.summary.totalDirs).toEqual(1);
  160. expect(s.summary.totalFiles).toEqual(0);
  161. expect(s.summary.totalSize).toEqual(0);
  162. });
  163. it('properly sum up pending folder sizes after remove', function() {
  164. var s = new FileSummary($container);
  165. s.setSummary({
  166. totalDirs: 0,
  167. totalFiles: 0,
  168. totalSize: 0
  169. });
  170. s.add({type: 'dir', size: -1});
  171. s.remove({type: 'dir', size: -1});
  172. s.update();
  173. expect($container.hasClass('hidden')).toEqual(true);
  174. expect($container.find('.info').text()).toEqual('0 folders and 0 files');
  175. expect($container.find('.filesize').text()).toEqual('0 B');
  176. expect(s.summary.totalDirs).toEqual(0);
  177. expect(s.summary.totalFiles).toEqual(0);
  178. expect(s.summary.totalSize).toEqual(0);
  179. });
  180. });