From 7a088cfcf56a841f16023a64a442620fd20c0c6e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= <danxuliu@gmail.com>
Date: Thu, 11 Jan 2018 02:36:00 +0100
Subject: [PATCH] Move adding test files to "beforeEach()"
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

All the tests in the "Renaming files" section added the test files,
although those calling "doRename()" added them by setting a path for the
file too. However, the path is ignored in the other tests, so adding the
files can be unified and moved to "beforeEach()".

This would be needed, for example, to show the details view for a file
before calling "doRename()".

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
---
 apps/files/tests/js/filelistSpec.js | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js
index fc5a6c18f95..a03d2fa1cc7 100644
--- a/apps/files/tests/js/filelistSpec.js
+++ b/apps/files/tests/js/filelistSpec.js
@@ -612,6 +612,12 @@ describe('OCA.Files.FileList tests', function() {
 		beforeEach(function() {
 			deferredRename = $.Deferred();
 			renameStub = sinon.stub(filesClient, 'move').returns(deferredRename.promise());
+
+			for (var i = 0; i < testFiles.length; i++) {
+				var file = testFiles[i];
+				file.path = '/some/subdir';
+				fileList.add(file, {silent: true});
+			}
 		});
 		afterEach(function() {
 			renameStub.restore();
@@ -619,9 +625,6 @@ describe('OCA.Files.FileList tests', function() {
 
 		function doCancelRename() {
 			var $input;
-			for (var i = 0; i < testFiles.length; i++) {
-				fileList.add(testFiles[i]);
-			}
 
 			// trigger rename prompt
 			fileList.rename('One.txt');
@@ -636,12 +639,6 @@ describe('OCA.Files.FileList tests', function() {
 		function doRename() {
 			var $input;
 
-			for (var i = 0; i < testFiles.length; i++) {
-				var file = testFiles[i];
-				file.path = '/some/subdir';
-				fileList.add(file, {silent: true});
-			}
-
 			// trigger rename prompt
 			fileList.rename('One.txt');
 			$input = fileList.$fileList.find('input.filename');
@@ -731,10 +728,6 @@ describe('OCA.Files.FileList tests', function() {
 		it('Validates the file name', function() {
 			var $input, $tr;
 
-			for (var i = 0; i < testFiles.length; i++) {
-				fileList.add(testFiles[i], {silent: true});
-			}
-
 			$tr = fileList.findFileEl('One.txt');
 			expect($tr.find('a.name').css('display')).not.toEqual('none');
 
-- 
GitLab