diff options
author | Jörn Friedrich Dreyer <jfd@butonic.de> | 2015-01-09 10:49:22 +0100 |
---|---|---|
committer | Jörn Friedrich Dreyer <jfd@butonic.de> | 2015-01-09 10:49:22 +0100 |
commit | 45a20744fcdc0e3706b415fcf2b240afa4a0012e (patch) | |
tree | 97ed4a1c581f9cfa4bff0663fad3058504dc5129 /apps | |
parent | 0bb91cfcf3d0f25ab4962c1417206451bebdb978 (diff) | |
download | nextcloud-server-45a20744fcdc0e3706b415fcf2b240afa4a0012e.tar.gz nextcloud-server-45a20744fcdc0e3706b415fcf2b240afa4a0012e.zip |
add js tests for filelist filtering
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/js/filelist.js | 6 | ||||
-rw-r--r-- | apps/files/tests/js/filelistSpec.js | 119 |
2 files changed, 119 insertions, 6 deletions
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 80f9d9c30c3..0476cd166a0 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1674,7 +1674,9 @@ setFilter:function(filter) { this._filter = filter; this.fileSummary.setFilter(filter, this.files); - this.hideIrrelevantUIWhenNoFilesMatch(); + if (!this.$el.find('.mask').exists()) { + this.hideIrrelevantUIWhenNoFilesMatch(); + } var that = this; this.$fileList.find('tr').each(function(i,e) { var $e = $(e); @@ -1690,7 +1692,7 @@ if (this._filter && this.fileSummary.summary.totalDirs + this.fileSummary.summary.totalFiles === 0) { this.$el.find('#filestable thead th').addClass('hidden'); this.$el.find('#emptycontent').addClass('hidden'); - if ( $('#searchresults').length === 0 || $('#searchresults').hasClass('hidden')) { + if ( $('#searchresults').length === 0 || $('#searchresults').hasClass('hidden') ) { this.$el.find('.nofilterresults').removeClass('hidden'). find('p').text(t('files', "No entries in this folder match '{filter}'", {filter:this._filter})); } diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js index 6dafa262715..c1c8e4ce337 100644 --- a/apps/files/tests/js/filelistSpec.js +++ b/apps/files/tests/js/filelistSpec.js @@ -61,8 +61,8 @@ describe('OCA.Files.FileList tests', function() { $('#testArea').append( '<div id="app-content-files">' + // init horrible parameters - '<input type="hidden" id="dir" value="/subdir"></input>' + - '<input type="hidden" id="permissions" value="31"></input>' + + '<input type="hidden" id="dir" value="/subdir"/>' + + '<input type="hidden" id="permissions" value="31"/>' + // dummy controls '<div id="controls">' + ' <div class="actions creatable"></div>' + @@ -88,6 +88,7 @@ describe('OCA.Files.FileList tests', function() { '<tfoot></tfoot>' + '</table>' + '<div id="emptycontent">Empty content message</div>' + + '<div class="nofilterresults hidden"></div>' + '</div>' ); @@ -763,7 +764,7 @@ describe('OCA.Files.FileList tests', function() { fakeServer.requests[0].respond(200, {'Content-Type': 'application/json'}, JSON.stringify({ status: 'error', data: { - message: 'Error while moving file', + message: 'Error while moving file' } })); @@ -785,7 +786,7 @@ describe('OCA.Files.FileList tests', function() { fakeServer.requests[0].respond(200, {'Content-Type': 'application/json'}, JSON.stringify({ status: 'error', data: { - message: 'Error while moving file', + message: 'Error while moving file' } })); @@ -901,6 +902,116 @@ describe('OCA.Files.FileList tests', function() { expect($summary.find('.info').text()).toEqual('0 folders and 1 file'); }); }); + describe('Filtered list rendering', function() { + it('filters the list of files using filter()', function() { + expect(fileList.files.length).toEqual(0); + expect(fileList.files).toEqual([]); + fileList.setFiles(testFiles); + var $summary = $('#filestable .summary'); + var $nofilterresults = fileList.$el.find(".nofilterresults"); + expect($nofilterresults.length).toEqual(1); + expect($summary.hasClass('hidden')).toEqual(false); + + expect($('#fileList tr:not(.hidden)').length).toEqual(4); + expect(fileList.files.length).toEqual(4); + expect($summary.hasClass('hidden')).toEqual(false); + expect($nofilterresults.hasClass('hidden')).toEqual(true); + + fileList.setFilter('e'); + expect($('#fileList tr:not(.hidden)').length).toEqual(3); + expect(fileList.files.length).toEqual(4); + expect($summary.hasClass('hidden')).toEqual(false); + expect($summary.find('.info').text()).toEqual("1 folder and 2 files match 'e'"); + expect($nofilterresults.hasClass('hidden')).toEqual(true); + + fileList.setFilter('ee'); + expect($('#fileList tr:not(.hidden)').length).toEqual(1); + expect(fileList.files.length).toEqual(4); + expect($summary.hasClass('hidden')).toEqual(false); + expect($summary.find('.info').text()).toEqual("0 folders and 1 file matches 'ee'"); + expect($nofilterresults.hasClass('hidden')).toEqual(true); + + fileList.setFilter('eee'); + expect($('#fileList tr:not(.hidden)').length).toEqual(0); + expect(fileList.files.length).toEqual(4); + expect($summary.hasClass('hidden')).toEqual(true); + expect($nofilterresults.hasClass('hidden')).toEqual(false); + + fileList.setFilter('ee'); + expect($('#fileList tr:not(.hidden)').length).toEqual(1); + expect(fileList.files.length).toEqual(4); + expect($summary.hasClass('hidden')).toEqual(false); + expect($summary.find('.info').text()).toEqual("0 folders and 1 file matches 'ee'"); + expect($nofilterresults.hasClass('hidden')).toEqual(true); + + fileList.setFilter('e'); + expect($('#fileList tr:not(.hidden)').length).toEqual(3); + expect(fileList.files.length).toEqual(4); + expect($summary.hasClass('hidden')).toEqual(false); + expect($summary.find('.info').text()).toEqual("1 folder and 2 files match 'e'"); + expect($nofilterresults.hasClass('hidden')).toEqual(true); + + fileList.setFilter(''); + expect($('#fileList tr:not(.hidden)').length).toEqual(4); + expect(fileList.files.length).toEqual(4); + expect($summary.hasClass('hidden')).toEqual(false); + expect($summary.find('.info').text()).toEqual("1 folder and 3 files"); + expect($nofilterresults.hasClass('hidden')).toEqual(true); + }); + it('hides the emptyfiles notice when using filter()', function() { + expect(fileList.files.length).toEqual(0); + expect(fileList.files).toEqual([]); + fileList.setFiles([]); + var $summary = $('#filestable .summary'); + var $emptycontent = fileList.$el.find("#emptycontent"); + var $nofilterresults = fileList.$el.find(".nofilterresults"); + expect($emptycontent.length).toEqual(1); + expect($nofilterresults.length).toEqual(1); + + expect($('#fileList tr:not(.hidden)').length).toEqual(0); + expect(fileList.files.length).toEqual(0); + expect($summary.hasClass('hidden')).toEqual(true); + expect($emptycontent.hasClass('hidden')).toEqual(false); + expect($nofilterresults.hasClass('hidden')).toEqual(true); + + fileList.setFilter('e'); + expect($('#fileList tr:not(.hidden)').length).toEqual(0); + expect(fileList.files.length).toEqual(0); + expect($summary.hasClass('hidden')).toEqual(true); + expect($emptycontent.hasClass('hidden')).toEqual(true); + expect($nofilterresults.hasClass('hidden')).toEqual(false); + + fileList.setFilter(''); + expect($('#fileList tr:not(.hidden)').length).toEqual(0); + expect(fileList.files.length).toEqual(0); + expect($summary.hasClass('hidden')).toEqual(true); + expect($emptycontent.hasClass('hidden')).toEqual(false); + expect($nofilterresults.hasClass('hidden')).toEqual(true); + }); + it('does not show the emptyfiles or nofilterresults notice when the mask is active', function() { + expect(fileList.files.length).toEqual(0); + expect(fileList.files).toEqual([]); + fileList.showMask(); + fileList.setFiles(testFiles); + var $emptycontent = fileList.$el.find("#emptycontent"); + var $nofilterresults = fileList.$el.find(".nofilterresults"); + expect($emptycontent.length).toEqual(1); + expect($nofilterresults.length).toEqual(1); + + expect($emptycontent.hasClass('hidden')).toEqual(true); + expect($nofilterresults.hasClass('hidden')).toEqual(true); + + /* + fileList.setFilter('e'); + expect($emptycontent.hasClass('hidden')).toEqual(true); + expect($nofilterresults.hasClass('hidden')).toEqual(false); + */ + + fileList.setFilter(''); + expect($emptycontent.hasClass('hidden')).toEqual(true); + expect($nofilterresults.hasClass('hidden')).toEqual(true); + }); + }); describe('Rendering next page on scroll', function() { beforeEach(function() { fileList.setFiles(generateFiles(0, 64)); |