filesummarySpec.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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('.dirinfo').text()).toEqual('5 folders');
  40. expect($container.find('.fileinfo').text()).toEqual('2 files');
  41. expect($container.find('.filesize').text()).toEqual('250 KB');
  42. });
  43. it('hides summary when no files or folders', function() {
  44. var s = new FileSummary($container);
  45. s.setSummary({
  46. totalDirs: 0,
  47. totalFiles: 0,
  48. totalSize: 0
  49. });
  50. expect($container.hasClass('hidden')).toEqual(true);
  51. });
  52. it('increases summary when adding files', function() {
  53. var s = new FileSummary($container);
  54. s.setSummary({
  55. totalDirs: 5,
  56. totalFiles: 2,
  57. totalSize: 256000
  58. });
  59. s.add({type: 'file', size: 256000});
  60. s.add({type: 'dir', size: 100});
  61. s.update();
  62. expect($container.hasClass('hidden')).toEqual(false);
  63. expect($container.find('.dirinfo').text()).toEqual('6 folders');
  64. expect($container.find('.fileinfo').text()).toEqual('3 files');
  65. expect($container.find('.filesize').text()).toEqual('500 KB');
  66. expect(s.summary.totalDirs).toEqual(6);
  67. expect(s.summary.totalFiles).toEqual(3);
  68. expect(s.summary.totalSize).toEqual(512100);
  69. });
  70. it('decreases summary when removing files', function() {
  71. var s = new FileSummary($container);
  72. s.setSummary({
  73. totalDirs: 5,
  74. totalFiles: 2,
  75. totalSize: 256000
  76. });
  77. s.remove({type: 'file', size: 128000});
  78. s.remove({type: 'dir', size: 100});
  79. s.update();
  80. expect($container.hasClass('hidden')).toEqual(false);
  81. expect($container.find('.dirinfo').text()).toEqual('4 folders');
  82. expect($container.find('.fileinfo').text()).toEqual('1 file');
  83. expect($container.find('.filesize').text()).toEqual('125 KB');
  84. expect(s.summary.totalDirs).toEqual(4);
  85. expect(s.summary.totalFiles).toEqual(1);
  86. expect(s.summary.totalSize).toEqual(127900);
  87. });
  88. it('renders filtered summary as text', function() {
  89. var s = new FileSummary($container);
  90. s.setSummary({
  91. totalDirs: 5,
  92. totalFiles: 2,
  93. totalSize: 256000,
  94. filter: 'foo'
  95. });
  96. expect($container.hasClass('hidden')).toEqual(false);
  97. expect($container.find('.dirinfo').text()).toEqual('5 folders');
  98. expect($container.find('.fileinfo').text()).toEqual('2 files');
  99. expect($container.find('.filter').text()).toEqual(' match \'foo\'');
  100. expect($container.find('.filesize').text()).toEqual('250 KB');
  101. });
  102. it('hides filtered summary when no files or folders', function() {
  103. var s = new FileSummary($container);
  104. s.setSummary({
  105. totalDirs: 0,
  106. totalFiles: 0,
  107. totalSize: 0,
  108. filter: 'foo'
  109. });
  110. expect($container.hasClass('hidden')).toEqual(true);
  111. });
  112. it('increases filtered summary when adding files', function() {
  113. var s = new FileSummary($container);
  114. s.setSummary({
  115. totalDirs: 5,
  116. totalFiles: 2,
  117. totalSize: 256000,
  118. filter: 'foo'
  119. });
  120. s.add({name: 'bar.txt', type: 'file', size: 256000});
  121. s.add({name: 'foo.txt', type: 'file', size: 256001});
  122. s.add({name: 'bar', type: 'dir', size: 100});
  123. s.add({name: 'foo', type: 'dir', size: 102});
  124. s.update();
  125. expect($container.hasClass('hidden')).toEqual(false);
  126. expect($container.find('.dirinfo').text()).toEqual('6 folders');
  127. expect($container.find('.fileinfo').text()).toEqual('3 files');
  128. expect($container.find('.filter').text()).toEqual(' match \'foo\'');
  129. expect($container.find('.filesize').text()).toEqual('500 KB');
  130. expect(s.summary.totalDirs).toEqual(6);
  131. expect(s.summary.totalFiles).toEqual(3);
  132. expect(s.summary.totalSize).toEqual(512103);
  133. });
  134. it('decreases filtered summary when removing files', function() {
  135. var s = new FileSummary($container);
  136. s.setSummary({
  137. totalDirs: 5,
  138. totalFiles: 2,
  139. totalSize: 256000,
  140. filter: 'foo'
  141. });
  142. s.remove({name: 'bar.txt', type: 'file', size: 128000});
  143. s.remove({name: 'foo.txt', type: 'file', size: 127999});
  144. s.remove({name: 'bar', type: 'dir', size: 100});
  145. s.remove({name: 'foo', type: 'dir', size: 98});
  146. s.update();
  147. expect($container.hasClass('hidden')).toEqual(false);
  148. expect($container.find('.dirinfo').text()).toEqual('4 folders');
  149. expect($container.find('.fileinfo').text()).toEqual('1 file');
  150. expect($container.find('.filter').text()).toEqual(' match \'foo\'');
  151. expect($container.find('.filesize').text()).toEqual('125 KB');
  152. expect(s.summary.totalDirs).toEqual(4);
  153. expect(s.summary.totalFiles).toEqual(1);
  154. expect(s.summary.totalSize).toEqual(127903);
  155. });
  156. it('properly sum up pending folder sizes after adding', function() {
  157. var s = new FileSummary($container);
  158. s.setSummary({
  159. totalDirs: 0,
  160. totalFiles: 0,
  161. totalSize: 0
  162. });
  163. s.add({type: 'dir', size: -1});
  164. s.update();
  165. expect($container.hasClass('hidden')).toEqual(false);
  166. expect($container.find('.dirinfo').text()).toEqual('1 folder');
  167. expect($container.find('.fileinfo').hasClass('hidden')).toEqual(true);
  168. expect($container.find('.filesize').text()).toEqual('Pending');
  169. expect(s.summary.totalDirs).toEqual(1);
  170. expect(s.summary.totalFiles).toEqual(0);
  171. expect(s.summary.totalSize).toEqual(0);
  172. });
  173. it('properly sum up pending folder sizes after remove', function() {
  174. var s = new FileSummary($container);
  175. s.setSummary({
  176. totalDirs: 0,
  177. totalFiles: 0,
  178. totalSize: 0
  179. });
  180. s.add({type: 'dir', size: -1});
  181. s.remove({type: 'dir', size: -1});
  182. s.update();
  183. expect($container.hasClass('hidden')).toEqual(true);
  184. expect(s.summary.totalDirs).toEqual(0);
  185. expect(s.summary.totalFiles).toEqual(0);
  186. expect(s.summary.totalSize).toEqual(0);
  187. });
  188. describe('hidden files', function() {
  189. var config;
  190. var summary;
  191. beforeEach(function() {
  192. config = new OC.Backbone.Model();
  193. summary = new FileSummary($container, {
  194. config: config
  195. });
  196. });
  197. it('renders hidden count section when hidden files are hidden', function() {
  198. config.set('showhidden', false);
  199. summary.add({name: 'abc', type: 'file', size: 256000});
  200. summary.add({name: 'def', type: 'dir', size: 100});
  201. summary.add({name: '.hidden', type: 'dir', size: 512000});
  202. summary.update();
  203. expect($container.hasClass('hidden')).toEqual(false);
  204. expect($container.find('.dirinfo').text()).toEqual('2 folders');
  205. expect($container.find('.fileinfo').text()).toEqual('1 file');
  206. expect($container.find('.hiddeninfo').hasClass('hidden')).toEqual(false);
  207. expect($container.find('.hiddeninfo').text()).toEqual(' (including 1 hidden)');
  208. expect($container.find('.filesize').text()).toEqual('750 KB');
  209. });
  210. it('does not render hidden count section when hidden files exist but are visible', function() {
  211. config.set('showhidden', true);
  212. summary.add({name: 'abc', type: 'file', size: 256000});
  213. summary.add({name: 'def', type: 'dir', size: 100});
  214. summary.add({name: '.hidden', type: 'dir', size: 512000});
  215. summary.update();
  216. expect($container.hasClass('hidden')).toEqual(false);
  217. expect($container.find('.dirinfo').text()).toEqual('2 folders');
  218. expect($container.find('.fileinfo').text()).toEqual('1 file');
  219. expect($container.find('.hiddeninfo').hasClass('hidden')).toEqual(true);
  220. expect($container.find('.filesize').text()).toEqual('750 KB');
  221. });
  222. it('does not render hidden count section when no hidden files exist', function() {
  223. config.set('showhidden', false);
  224. summary.add({name: 'abc', type: 'file', size: 256000});
  225. summary.add({name: 'def', type: 'dir', size: 100});
  226. summary.update();
  227. expect($container.hasClass('hidden')).toEqual(false);
  228. expect($container.find('.dirinfo').text()).toEqual('1 folder');
  229. expect($container.find('.fileinfo').text()).toEqual('1 file');
  230. expect($container.find('.hiddeninfo').hasClass('hidden')).toEqual(true);
  231. expect($container.find('.filesize').text()).toEqual('250 KB');
  232. });
  233. });
  234. });