123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- /**
- * ownCloud
- *
- * @author Vincent Petry
- * @copyright 2014 Vincent Petry <pvince81@owncloud.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- */
- /* global FileSummary */
- describe('OCA.Files.FileSummary tests', function() {
- var FileSummary = OCA.Files.FileSummary;
- var $container;
- beforeEach(function() {
- $container = $('<table><tr></tr></table>').find('tr');
- });
- afterEach(function() {
- $container = null;
- });
- it('renders summary as text', function() {
- var s = new FileSummary($container);
- s.setSummary({
- totalDirs: 5,
- totalFiles: 2,
- totalSize: 256000
- });
- expect($container.hasClass('hidden')).toEqual(false);
- expect($container.find('.info').text()).toEqual('5 folders and 2 files');
- expect($container.find('.filesize').text()).toEqual('250 KB');
- });
- it('hides summary when no files or folders', function() {
- var s = new FileSummary($container);
- s.setSummary({
- totalDirs: 0,
- totalFiles: 0,
- totalSize: 0
- });
- expect($container.hasClass('hidden')).toEqual(true);
- });
- it('increases summary when adding files', function() {
- var s = new FileSummary($container);
- s.setSummary({
- totalDirs: 5,
- totalFiles: 2,
- totalSize: 256000
- });
- s.add({type: 'file', size: 256000});
- s.add({type: 'dir', size: 100});
- s.update();
- expect($container.hasClass('hidden')).toEqual(false);
- expect($container.find('.info').text()).toEqual('6 folders and 3 files');
- expect($container.find('.filesize').text()).toEqual('500 KB');
- expect(s.summary.totalDirs).toEqual(6);
- expect(s.summary.totalFiles).toEqual(3);
- expect(s.summary.totalSize).toEqual(512100);
- });
- it('decreases summary when removing files', function() {
- var s = new FileSummary($container);
- s.setSummary({
- totalDirs: 5,
- totalFiles: 2,
- totalSize: 256000
- });
- s.remove({type: 'file', size: 128000});
- s.remove({type: 'dir', size: 100});
- s.update();
- expect($container.hasClass('hidden')).toEqual(false);
- expect($container.find('.info').text()).toEqual('4 folders and 1 file');
- expect($container.find('.filesize').text()).toEqual('125 KB');
- expect(s.summary.totalDirs).toEqual(4);
- expect(s.summary.totalFiles).toEqual(1);
- expect(s.summary.totalSize).toEqual(127900);
- });
- it('renders filtered summary as text', function() {
- var s = new FileSummary($container);
- s.setSummary({
- totalDirs: 5,
- totalFiles: 2,
- totalSize: 256000,
- filter: 'foo'
- });
- expect($container.hasClass('hidden')).toEqual(false);
- expect($container.find('.info').text()).toEqual('5 folders and 2 files match \'foo\'');
- expect($container.find('.filesize').text()).toEqual('250 KB');
- });
- it('hides filtered summary when no files or folders', function() {
- var s = new FileSummary($container);
- s.setSummary({
- totalDirs: 0,
- totalFiles: 0,
- totalSize: 0,
- filter: 'foo'
- });
- expect($container.hasClass('hidden')).toEqual(true);
- });
- it('increases filtered summary when adding files', function() {
- var s = new FileSummary($container);
- s.setSummary({
- totalDirs: 5,
- totalFiles: 2,
- totalSize: 256000,
- filter: 'foo'
- });
- s.add({name: 'bar.txt', type: 'file', size: 256000});
- s.add({name: 'foo.txt', type: 'file', size: 256001});
- s.add({name: 'bar', type: 'dir', size: 100});
- s.add({name: 'foo', type: 'dir', size: 102});
- s.update();
- expect($container.hasClass('hidden')).toEqual(false);
- expect($container.find('.info').text()).toEqual('6 folders and 3 files match \'foo\'');
- expect($container.find('.filesize').text()).toEqual('500 KB');
- expect(s.summary.totalDirs).toEqual(6);
- expect(s.summary.totalFiles).toEqual(3);
- expect(s.summary.totalSize).toEqual(512103);
- });
- it('decreases filtered summary when removing files', function() {
- var s = new FileSummary($container);
- s.setSummary({
- totalDirs: 5,
- totalFiles: 2,
- totalSize: 256000,
- filter: 'foo'
- });
- s.remove({name: 'bar.txt', type: 'file', size: 128000});
- s.remove({name: 'foo.txt', type: 'file', size: 127999});
- s.remove({name: 'bar', type: 'dir', size: 100});
- s.remove({name: 'foo', type: 'dir', size: 98});
- s.update();
- expect($container.hasClass('hidden')).toEqual(false);
- expect($container.find('.info').text()).toEqual('4 folders and 1 file match \'foo\'');
- expect($container.find('.filesize').text()).toEqual('125 KB');
- expect(s.summary.totalDirs).toEqual(4);
- expect(s.summary.totalFiles).toEqual(1);
- expect(s.summary.totalSize).toEqual(127903);
- });
- it('properly sum up pending folder sizes after adding', function() {
- var s = new FileSummary($container);
- s.setSummary({
- totalDirs: 0,
- totalFiles: 0,
- totalSize: 0
- });
- s.add({type: 'dir', size: -1});
- s.update();
- expect($container.hasClass('hidden')).toEqual(false);
- expect($container.find('.info').text()).toEqual('1 folder and 0 files');
- expect($container.find('.filesize').text()).toEqual('Pending');
- expect(s.summary.totalDirs).toEqual(1);
- expect(s.summary.totalFiles).toEqual(0);
- expect(s.summary.totalSize).toEqual(0);
- });
- it('properly sum up pending folder sizes after remove', function() {
- var s = new FileSummary($container);
- s.setSummary({
- totalDirs: 0,
- totalFiles: 0,
- totalSize: 0
- });
- s.add({type: 'dir', size: -1});
- s.remove({type: 'dir', size: -1});
- s.update();
- expect($container.hasClass('hidden')).toEqual(true);
- expect($container.find('.info').text()).toEqual('0 folders and 0 files');
- expect($container.find('.filesize').text()).toEqual('0 B');
- expect(s.summary.totalDirs).toEqual(0);
- expect(s.summary.totalFiles).toEqual(0);
- expect(s.summary.totalSize).toEqual(0);
- });
- });
|