filesummarySpec.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /**
  2. * @copyright 2014 Vincent Petry <pvince81@owncloud.com>
  3. *
  4. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. * @author Vincent Petry <vincent@nextcloud.com>
  8. *
  9. * @license AGPL-3.0-or-later
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. describe('OCA.Files.FileSummary tests', function() {
  26. var FileSummary = OCA.Files.FileSummary;
  27. var $container;
  28. beforeEach(function() {
  29. $container = $('<table><tr></tr></table>').find('tr');
  30. });
  31. afterEach(function() {
  32. $container = null;
  33. });
  34. it('renders summary as text', function() {
  35. var s = new FileSummary($container);
  36. s.setSummary({
  37. totalDirs: 5,
  38. totalFiles: 2,
  39. totalSize: 256000
  40. });
  41. expect($container.hasClass('hidden')).toEqual(false);
  42. expect($container.find('.dirinfo').text()).toEqual('5 folders');
  43. expect($container.find('.fileinfo').text()).toEqual('2 files');
  44. expect($container.find('.filesize').text()).toEqual('250 KB');
  45. });
  46. it('hides summary when no files or folders', function() {
  47. var s = new FileSummary($container);
  48. s.setSummary({
  49. totalDirs: 0,
  50. totalFiles: 0,
  51. totalSize: 0
  52. });
  53. expect($container.hasClass('hidden')).toEqual(true);
  54. });
  55. it('increases summary when adding files', function() {
  56. var s = new FileSummary($container);
  57. s.setSummary({
  58. totalDirs: 5,
  59. totalFiles: 2,
  60. totalSize: 256000
  61. });
  62. s.add({type: 'file', size: 256000});
  63. s.add({type: 'dir', size: 100});
  64. s.update();
  65. expect($container.hasClass('hidden')).toEqual(false);
  66. expect($container.find('.dirinfo').text()).toEqual('6 folders');
  67. expect($container.find('.fileinfo').text()).toEqual('3 files');
  68. expect($container.find('.filesize').text()).toEqual('500 KB');
  69. expect(s.summary.totalDirs).toEqual(6);
  70. expect(s.summary.totalFiles).toEqual(3);
  71. expect(s.summary.totalSize).toEqual(512100);
  72. });
  73. it('decreases summary when removing files', function() {
  74. var s = new FileSummary($container);
  75. s.setSummary({
  76. totalDirs: 5,
  77. totalFiles: 2,
  78. totalSize: 256000
  79. });
  80. s.remove({type: 'file', size: 128000});
  81. s.remove({type: 'dir', size: 100});
  82. s.update();
  83. expect($container.hasClass('hidden')).toEqual(false);
  84. expect($container.find('.dirinfo').text()).toEqual('4 folders');
  85. expect($container.find('.fileinfo').text()).toEqual('1 file');
  86. expect($container.find('.filesize').text()).toEqual('125 KB');
  87. expect(s.summary.totalDirs).toEqual(4);
  88. expect(s.summary.totalFiles).toEqual(1);
  89. expect(s.summary.totalSize).toEqual(127900);
  90. });
  91. it('renders filtered summary as text', function() {
  92. var s = new FileSummary($container);
  93. s.setSummary({
  94. totalDirs: 5,
  95. totalFiles: 2,
  96. totalSize: 256000,
  97. filter: 'foo'
  98. });
  99. expect($container.hasClass('hidden')).toEqual(false);
  100. expect($container.find('.dirinfo').text()).toEqual('5 folders');
  101. expect($container.find('.fileinfo').text()).toEqual('2 files');
  102. expect($container.find('.filter').text()).toEqual(' match "foo"');
  103. expect($container.find('.filesize').text()).toEqual('250 KB');
  104. });
  105. it('hides filtered summary when no files or folders', function() {
  106. var s = new FileSummary($container);
  107. s.setSummary({
  108. totalDirs: 0,
  109. totalFiles: 0,
  110. totalSize: 0,
  111. filter: 'foo'
  112. });
  113. expect($container.hasClass('hidden')).toEqual(true);
  114. });
  115. it('increases filtered summary when adding files', function() {
  116. var s = new FileSummary($container);
  117. s.setSummary({
  118. totalDirs: 5,
  119. totalFiles: 2,
  120. totalSize: 256000,
  121. filter: 'foo'
  122. });
  123. s.add({name: 'bar.txt', type: 'file', size: 256000});
  124. s.add({name: 'foo.txt', type: 'file', size: 256001});
  125. s.add({name: 'bar', type: 'dir', size: 100});
  126. s.add({name: 'foo', type: 'dir', size: 102});
  127. s.update();
  128. expect($container.hasClass('hidden')).toEqual(false);
  129. expect($container.find('.dirinfo').text()).toEqual('6 folders');
  130. expect($container.find('.fileinfo').text()).toEqual('3 files');
  131. expect($container.find('.filter').text()).toEqual(' match "foo"');
  132. expect($container.find('.filesize').text()).toEqual('500 KB');
  133. expect(s.summary.totalDirs).toEqual(6);
  134. expect(s.summary.totalFiles).toEqual(3);
  135. expect(s.summary.totalSize).toEqual(512103);
  136. });
  137. it('decreases filtered summary when removing files', function() {
  138. var s = new FileSummary($container);
  139. s.setSummary({
  140. totalDirs: 5,
  141. totalFiles: 2,
  142. totalSize: 256000,
  143. filter: 'foo'
  144. });
  145. s.remove({name: 'bar.txt', type: 'file', size: 128000});
  146. s.remove({name: 'foo.txt', type: 'file', size: 127999});
  147. s.remove({name: 'bar', type: 'dir', size: 100});
  148. s.remove({name: 'foo', type: 'dir', size: 98});
  149. s.update();
  150. expect($container.hasClass('hidden')).toEqual(false);
  151. expect($container.find('.dirinfo').text()).toEqual('4 folders');
  152. expect($container.find('.fileinfo').text()).toEqual('1 file');
  153. expect($container.find('.filter').text()).toEqual(' match "foo"');
  154. expect($container.find('.filesize').text()).toEqual('125 KB');
  155. expect(s.summary.totalDirs).toEqual(4);
  156. expect(s.summary.totalFiles).toEqual(1);
  157. expect(s.summary.totalSize).toEqual(127903);
  158. });
  159. it('properly sum up pending folder sizes after adding', function() {
  160. var s = new FileSummary($container);
  161. s.setSummary({
  162. totalDirs: 0,
  163. totalFiles: 0,
  164. totalSize: 0
  165. });
  166. s.add({type: 'dir', size: -1});
  167. s.update();
  168. expect($container.hasClass('hidden')).toEqual(false);
  169. expect($container.find('.dirinfo').text()).toEqual('1 folder');
  170. expect($container.find('.fileinfo').hasClass('hidden')).toEqual(true);
  171. expect($container.find('.filesize').text()).toEqual('Pending');
  172. expect(s.summary.totalDirs).toEqual(1);
  173. expect(s.summary.totalFiles).toEqual(0);
  174. expect(s.summary.totalSize).toEqual(0);
  175. });
  176. it('properly sum up pending folder sizes after remove', function() {
  177. var s = new FileSummary($container);
  178. s.setSummary({
  179. totalDirs: 0,
  180. totalFiles: 0,
  181. totalSize: 0
  182. });
  183. s.add({type: 'dir', size: -1});
  184. s.remove({type: 'dir', size: -1});
  185. s.update();
  186. expect($container.hasClass('hidden')).toEqual(true);
  187. expect(s.summary.totalDirs).toEqual(0);
  188. expect(s.summary.totalFiles).toEqual(0);
  189. expect(s.summary.totalSize).toEqual(0);
  190. });
  191. describe('hidden files', function() {
  192. var config;
  193. var summary;
  194. beforeEach(function() {
  195. config = new OC.Backbone.Model();
  196. summary = new FileSummary($container, {
  197. config: config
  198. });
  199. });
  200. it('renders hidden count section when hidden files are hidden', function() {
  201. window._nc_event_bus.emit('files:config:updated', { key: 'show_hidden', value: false });
  202. summary.add({name: 'abc', type: 'file', size: 256000});
  203. summary.add({name: 'def', type: 'dir', size: 100});
  204. summary.add({name: '.hidden', type: 'dir', size: 512000});
  205. summary.update();
  206. expect($container.hasClass('hidden')).toEqual(false);
  207. expect($container.find('.dirinfo').text()).toEqual('2 folders');
  208. expect($container.find('.fileinfo').text()).toEqual('1 file');
  209. expect($container.find('.hiddeninfo').hasClass('hidden')).toEqual(false);
  210. expect($container.find('.hiddeninfo').text()).toEqual(' (including 1 hidden)');
  211. expect($container.find('.filesize').text()).toEqual('750 KB');
  212. });
  213. it('does not render hidden count section when hidden files exist but are visible', function() {
  214. window._nc_event_bus.emit('files:config:updated', { key: 'show_hidden', value: true });
  215. summary.add({name: 'abc', type: 'file', size: 256000});
  216. summary.add({name: 'def', type: 'dir', size: 100});
  217. summary.add({name: '.hidden', type: 'dir', size: 512000});
  218. summary.update();
  219. expect($container.hasClass('hidden')).toEqual(false);
  220. expect($container.find('.dirinfo').text()).toEqual('2 folders');
  221. expect($container.find('.fileinfo').text()).toEqual('1 file');
  222. expect($container.find('.hiddeninfo').hasClass('hidden')).toEqual(true);
  223. expect($container.find('.filesize').text()).toEqual('750 KB');
  224. });
  225. it('does not render hidden count section when no hidden files exist', function() {
  226. window._nc_event_bus.emit('files:config:updated', { key: 'show_hidden', value: false });
  227. summary.add({name: 'abc', type: 'file', size: 256000});
  228. summary.add({name: 'def', type: 'dir', size: 100});
  229. summary.update();
  230. expect($container.hasClass('hidden')).toEqual(false);
  231. expect($container.find('.dirinfo').text()).toEqual('1 folder');
  232. expect($container.find('.fileinfo').text()).toEqual('1 file');
  233. expect($container.find('.hiddeninfo').hasClass('hidden')).toEqual(true);
  234. expect($container.find('.filesize').text()).toEqual('250 KB');
  235. });
  236. });
  237. });