From f18fc851c00c5cb9cad5b3217b49359f7f2165fc Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Fri, 17 Aug 2018 20:08:57 +0200 Subject: [PATCH 1/3] Adds a test to check that the sorting isn't stored without an user Signed-off-by: Michael Weimann --- apps/files/tests/js/filelistSpec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js index 7947dd91f2..d140299d22 100644 --- a/apps/files/tests/js/filelistSpec.js +++ b/apps/files/tests/js/filelistSpec.js @@ -2614,6 +2614,14 @@ describe('OCA.Files.FileList tests', function() { }); }); describe('Sorting files', function() { + + /** + * Set any user id before tests. + */ + beforeEach(function() { + OC.currentUser = 1; + }); + it('Toggles the sort indicator when clicking on a column header', function() { var ASC_CLASS = fileList.SORT_INDICATOR_ASC_CLASS; var DESC_CLASS = fileList.SORT_INDICATOR_DESC_CLASS; @@ -2739,6 +2747,14 @@ describe('OCA.Files.FileList tests', function() { sortStub.restore(); }); + + it('doesn\'t send a sort update request if there is no user logged in', function() { + OC.currentUser = false; + fileList.$el.find('.column-size .columntitle').click(); + // check if there was no request + expect(fakeServer.requests.length).toEqual(0); + }); + describe('with favorites', function() { it('shows favorite files on top', function() { testFiles.push(new FileInfo({ From 887737f7067a6e9872fb0843ee5bac8a540fd684 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Fri, 17 Aug 2018 20:09:11 +0200 Subject: [PATCH 2/3] Stores the sorting only if there is an user Signed-off-by: Michael Weimann --- apps/files/js/filelist.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 8e7c60551a..8fb8a02181 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1738,7 +1738,7 @@ } } - if (persist) { + if (persist && OC.getCurrentUser().uid) { $.post(OC.generateUrl('/apps/files/api/v1/sorting'), { mode: sort, direction: direction From 2de34d77780a60de198ef82a3f17292db9f668a4 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Fri, 17 Aug 2018 20:35:23 +0200 Subject: [PATCH 3/3] Improves the tests Signed-off-by: Michael Weimann --- apps/files/tests/js/filelistSpec.js | 33 +++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js index d140299d22..50b336902b 100644 --- a/apps/files/tests/js/filelistSpec.js +++ b/apps/files/tests/js/filelistSpec.js @@ -2615,11 +2615,17 @@ describe('OCA.Files.FileList tests', function() { }); describe('Sorting files', function() { - /** - * Set any user id before tests. - */ + var getCurrentUserStub; + beforeEach(function() { - OC.currentUser = 1; + getCurrentUserStub = sinon.stub(OC, 'getCurrentUser').returns({ + uid: 1, + displayName: 'user1' + }); + }); + + afterEach(function() { + getCurrentUserStub.restore(); }); it('Toggles the sort indicator when clicking on a column header', function() { @@ -2748,11 +2754,20 @@ describe('OCA.Files.FileList tests', function() { sortStub.restore(); }); - it('doesn\'t send a sort update request if there is no user logged in', function() { - OC.currentUser = false; - fileList.$el.find('.column-size .columntitle').click(); - // check if there was no request - expect(fakeServer.requests.length).toEqual(0); + describe('if no user logged in', function() { + beforeEach(function() { + getCurrentUserStub.returns({ + uid: null, + displayName: 'Guest' + }); + }); + + it('shouldn\'t send an update sort order request', function() { + OC.currentUser = false; + fileList.$el.find('.column-size .columntitle').click(); + // check if there was no request + expect(fakeServer.requests.length).toEqual(0); + }); }); describe('with favorites', function() {