From a15b68c10fa7401dc4b30a173c80084bf114dde9 Mon Sep 17 00:00:00 2001
From: Vincent Petry <pvince81@owncloud.com>
Date: Thu, 10 Apr 2014 20:07:02 +0200
Subject: Fixed selection summary calculation issue

---
 apps/files/js/filelist.js           |  4 +---
 apps/files/tests/js/filelistSpec.js | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 3 deletions(-)

(limited to 'apps')

diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index 723a22f24e8..f9916b647b2 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -194,6 +194,7 @@ window.FileList = {
 		this.$fileList.find('td.filename input:checkbox').prop('checked', checked)
 			.closest('tr').toggleClass('selected', checked);
 		this._selectedFiles = {};
+		this._selectionSummary.clear();
 		if (checked) {
 			for (var i = 0; i < this.files.length; i++) {
 				var fileData = this.files[i];
@@ -201,9 +202,6 @@ window.FileList = {
 				this._selectionSummary.add(fileData);
 			}
 		}
-		else {
-			this._selectionSummary.clear();
-		}
 		this.updateSelectionSummary();
 	},
 
diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js
index be285a7b636..da209220cca 100644
--- a/apps/files/tests/js/filelistSpec.js
+++ b/apps/files/tests/js/filelistSpec.js
@@ -1118,6 +1118,32 @@ describe('FileList tests', function() {
 			expect($('#select_all').prop('checked')).toEqual(false);
 			expect(_.pluck(FileList.getSelectedFiles(), 'name').length).toEqual(3);
 		});
+		it('Updates the selection summary when doing a few manipulations with "Select all"', function() {
+			$('#select_all').click();
+			expect($('#select_all').prop('checked')).toEqual(true);
+
+			var $tr = FileList.findFileEl('One.txt');
+			// unselect one
+			$tr.find('input:checkbox').click();
+
+			expect($('#select_all').prop('checked')).toEqual(false);
+			expect(_.pluck(FileList.getSelectedFiles(), 'name').length).toEqual(3);
+
+			// select all
+			$('#select_all').click();
+			expect($('#select_all').prop('checked')).toEqual(true);
+			expect(_.pluck(FileList.getSelectedFiles(), 'name').length).toEqual(4);
+
+			// unselect one
+			$tr.find('input:checkbox').click();
+			expect($('#select_all').prop('checked')).toEqual(false);
+			expect(_.pluck(FileList.getSelectedFiles(), 'name').length).toEqual(3);
+
+			// re-select it
+			$tr.find('input:checkbox').click();
+			expect($('#select_all').prop('checked')).toEqual(true);
+			expect(_.pluck(FileList.getSelectedFiles(), 'name').length).toEqual(4);
+		});
 		it('Auto-selects files on next page when "select all" is checked', function() {
 			FileList.setFiles(generateFiles(0, 41));
 			$('#select_all').click();
-- 
cgit v1.2.3