From a48359ac024b1b0dbfea2dc3deb93607b0dbf329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Wed, 16 Oct 2019 21:46:31 +0200 Subject: [PATCH] Adjust unit tests to new OCA.Sidebar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- apps/comments/tests/js/filespluginSpec.js | 2 +- apps/files/tests/js/filelistSpec.js | 208 ------------------ apps/files_sharing/tests/js/shareSpec.js | 207 ----------------- .../tests/js/systemtagsinfoviewSpec.js | 6 +- 4 files changed, 4 insertions(+), 419 deletions(-) diff --git a/apps/comments/tests/js/filespluginSpec.js b/apps/comments/tests/js/filespluginSpec.js index 78becc5af0..0613169803 100644 --- a/apps/comments/tests/js/filespluginSpec.js +++ b/apps/comments/tests/js/filespluginSpec.js @@ -74,7 +74,7 @@ describe('OCA.Comments.FilesPlugin tests', function() { expect(sidebarStub.calledOnce).toEqual(true); expect(sidebarStub.lastCall.args[0]).toEqual('One.txt'); - expect(sidebarStub.lastCall.args[1]).toEqual('commentsTabView'); + expect(sidebarStub.lastCall.args[1]).toEqual('comments'); }); }); describe('elementToFile', function() { diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js index 402cfaa107..f9c1b5f31c 100644 --- a/apps/files/tests/js/filelistSpec.js +++ b/apps/files/tests/js/filelistSpec.js @@ -748,36 +748,6 @@ describe('OCA.Files.FileList tests', function() { expect(notificationStub.calledOnce).toEqual(true); }); - it('Shows renamed file details if rename ajax call suceeded', function() { - fileList.showDetailsView('One.txt'); - - expect($('#app-sidebar').hasClass('disappear')).toEqual(false); - expect(fileList._detailsView.getFileInfo().get('id')).toEqual(1); - expect(fileList._detailsView.getFileInfo().get('name')).toEqual('One.txt'); - - doRename(); - - deferredRename.resolve(201); - - expect($('#app-sidebar').hasClass('disappear')).toEqual(false); - expect(fileList._detailsView.getFileInfo().get('id')).toEqual(1); - expect(fileList._detailsView.getFileInfo().get('name')).toEqual('Tu_after_three.txt'); - }); - it('Shows again file details if rename ajax call failed', function() { - fileList.showDetailsView('One.txt'); - - expect($('#app-sidebar').hasClass('disappear')).toEqual(false); - expect(fileList._detailsView.getFileInfo().get('id')).toEqual(1); - expect(fileList._detailsView.getFileInfo().get('name')).toEqual('One.txt'); - - doRename(); - - deferredRename.reject(403); - - expect($('#app-sidebar').hasClass('disappear')).toEqual(false); - expect(fileList._detailsView.getFileInfo().get('id')).toEqual(1); - expect(fileList._detailsView.getFileInfo().get('name')).toEqual('One.txt'); - }); it('Correctly updates file link after rename', function() { var $tr; doRename(); @@ -2460,184 +2430,6 @@ describe('OCA.Files.FileList tests', function() { }); }); }); - describe('Details sidebar', function() { - beforeEach(function() { - fileList.setFiles(testFiles); - fileList.showDetailsView('Two.jpg'); - }); - describe('registering', function() { - var addTabStub; - var addDetailStub; - - beforeEach(function() { - addTabStub = sinon.stub(OCA.Files.DetailsView.prototype, 'addTabView'); - addDetailStub = sinon.stub(OCA.Files.DetailsView.prototype, 'addDetailView'); - getDetailsStub = sinon.stub(OCA.Files.DetailsView.prototype, 'getDetailViews'); - }); - afterEach(function() { - addTabStub.restore(); - addDetailStub.restore(); - getDetailsStub.restore(); - }); - it('forward the registered views to the underlying DetailsView', function() { - fileList.destroy(); - fileList = new OCA.Files.FileList($('#app-content-files'), { - detailsViewEnabled: true - }); - fileList.registerTabView(new OCA.Files.DetailTabView()); - fileList.registerDetailView(new OCA.Files.DetailFileInfoView()); - - expect(addTabStub.calledOnce).toEqual(true); - // twice because the filelist already registers one by default - expect(addDetailStub.calledTwice).toEqual(true); - }); - it('forward getting the registered views to the underlying DetailsView', function() { - fileList.destroy(); - fileList = new OCA.Files.FileList($('#app-content-files'), { - detailsViewEnabled: true - }); - var expectedRegisteredDetailsView = []; - getDetailsStub.returns(expectedRegisteredDetailsView); - - var registeredDetailViews = fileList.getRegisteredDetailViews(); - - expect(getDetailsStub.calledOnce).toEqual(true); - expect(registeredDetailViews).toEqual(expectedRegisteredDetailsView); - }); - it('does not error when registering panels when not details view configured', function() { - fileList.destroy(); - fileList = new OCA.Files.FileList($('#app-content-files'), { - detailsViewEnabled: false - }); - fileList.registerTabView(new OCA.Files.DetailTabView()); - fileList.registerDetailView(new OCA.Files.DetailFileInfoView()); - - expect(addTabStub.notCalled).toEqual(true); - expect(addDetailStub.notCalled).toEqual(true); - }); - it('returns null when getting the registered views when not details view configured', function() { - fileList.destroy(); - fileList = new OCA.Files.FileList($('#app-content-files'), { - detailsViewEnabled: false - }); - - var registeredDetailViews = fileList.getRegisteredDetailViews(); - - expect(getDetailsStub.notCalled).toEqual(true); - expect(registeredDetailViews).toBeNull(); - }); - }); - it('triggers file action when clicking on row if no details view configured', function() { - fileList.destroy(); - fileList = new OCA.Files.FileList($('#app-content-files'), { - detailsViewEnabled: false - }); - var updateDetailsViewStub = sinon.stub(fileList, '_updateDetailsView'); - var actionStub = sinon.stub(); - fileList.setFiles(testFiles); - fileList.fileActions.register( - 'text/plain', - 'Test', - OC.PERMISSION_ALL, - function() { - // Specify icon for hitory button - return OC.imagePath('core','actions/history'); - }, - actionStub - ); - fileList.fileActions.setDefault('text/plain', 'Test'); - var $tr = fileList.findFileEl('One.txt'); - $tr.find('td.filesize').click(); - expect(actionStub.calledOnce).toEqual(true); - expect(updateDetailsViewStub.notCalled).toEqual(true); - updateDetailsViewStub.restore(); - }); - it('highlights current file when clicked and updates sidebar', function() { - fileList.fileActions.setDefault('text/plain', 'Test'); - var $tr = fileList.findFileEl('One.txt'); - $tr.find('td.filesize').click(); - expect($tr.hasClass('highlighted')).toEqual(true); - - expect(fileList._detailsView.getFileInfo().id).toEqual(1); - }); - it('keeps the last highlighted file when clicking outside', function() { - var $tr = fileList.findFileEl('One.txt'); - $tr.find('td.filesize').click(); - - fileList.$el.find('tfoot').click(); - - expect($tr.hasClass('highlighted')).toEqual(true); - expect(fileList._detailsView.getFileInfo().id).toEqual(1); - }); - it('removes last highlighted file when selecting via checkbox', function() { - var $tr = fileList.findFileEl('One.txt'); - - // select - $tr.find('td.filesize').click(); - $tr.find('input:checkbox').click(); - expect($tr.hasClass('highlighted')).toEqual(false); - - // deselect - $tr.find('td.filesize').click(); - $tr.find('input:checkbox').click(); - expect($tr.hasClass('highlighted')).toEqual(false); - - expect(fileList._detailsView.getFileInfo()).toEqual(null); - }); - it('removes last highlighted file when selecting all files via checkbox', function() { - var $tr = fileList.findFileEl('One.txt'); - - // select - $tr.find('td.filesize').click(); - fileList.$el.find('.select-all.checkbox').click(); - expect($tr.hasClass('highlighted')).toEqual(false); - - // deselect - $tr.find('td.filesize').click(); - fileList.$el.find('.select-all.checkbox').click(); - expect($tr.hasClass('highlighted')).toEqual(false); - - expect(fileList._detailsView.getFileInfo()).toEqual(null); - }); - it('closes sidebar whenever the currently highlighted file was removed from the list', function() { - jQuery.fx.off = true; - var $tr = fileList.findFileEl('One.txt'); - $tr.find('td.filesize').click(); - expect($tr.hasClass('highlighted')).toEqual(true); - - expect(fileList._detailsView.getFileInfo().id).toEqual(1); - - expect($('#app-sidebar').hasClass('disappear')).toEqual(false); - fileList.remove('One.txt'); - // sidebar is removed on close before being - expect($('#app-sidebar').length).toEqual(0); - jQuery.fx.off = false; - }); - it('returns the currently selected model instance when calling getModelForFile', function() { - var $tr = fileList.findFileEl('One.txt'); - $tr.find('td.filesize').click(); - - var model1 = fileList.getModelForFile('One.txt'); - var model2 = fileList.getModelForFile('One.txt'); - model1.set('test', true); - - // it's the same model - expect(model2).toEqual(model1); - - var model3 = fileList.getModelForFile($tr); - expect(model3).toEqual(model1); - }); - it('closes the sidebar when switching folders', function() { - jQuery.fx.off = true; - var $tr = fileList.findFileEl('One.txt'); - $tr.find('td.filesize').click(); - - expect($('#app-sidebar').hasClass('disappear')).toEqual(false); - fileList.changeDirectory('/another'); - expect($('#app-sidebar').length).toEqual(0); - jQuery.fx.off = false; - }); - }); describe('File actions', function() { it('Clicking on a file name will trigger default action', function() { var actionStub = sinon.stub(); diff --git a/apps/files_sharing/tests/js/shareSpec.js b/apps/files_sharing/tests/js/shareSpec.js index a4aa6eea74..061c789c14 100644 --- a/apps/files_sharing/tests/js/shareSpec.js +++ b/apps/files_sharing/tests/js/shareSpec.js @@ -234,198 +234,6 @@ describe('OCA.Sharing.Util tests', function() { expect($tr.find('.action-share').length).toEqual(0); }); }); - describe('Share action', function() { - var shareTab; - - function makeDummyShareItem(displayName) { - return { - share_with_displayname: displayName - }; - } - - beforeEach(function() { - // make it look like not the "All files" list - fileList.id = 'test'; - shareTab = fileList._detailsView._tabViews[0]; - }); - afterEach(function() { - shareTab = null; - }); - it('clicking share action opens sidebar and share tab', function() { - var showDetailsViewStub = sinon.stub(fileList, 'showDetailsView'); - - fileList.setFiles([{ - id: 1, - type: 'file', - name: 'One.txt', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_ALL, - etag: 'abc' - }]); - - var $tr = fileList.$el.find('tr:first'); - $tr.find('.action-share').click(); - - expect(showDetailsViewStub.calledOnce).toEqual(true); - expect(showDetailsViewStub.getCall(0).args[0]).toEqual('One.txt'); - expect(showDetailsViewStub.getCall(0).args[1]).toEqual('shareTabView'); - - showDetailsViewStub.restore(); - }); - it('adds share icon after sharing a non-shared file', function() { - var $action, $tr; - OC.Share.statuses = {}; - fileList.setFiles([{ - id: 1, - type: 'file', - name: 'One.txt', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_ALL, - etag: 'abc' - }]); - $action = fileList.$el.find('tbody tr:first .action-share'); - $tr = fileList.$el.find('tr:first'); - - $tr.find('.action-share').click(); - - // simulate updating shares - shareTab._dialog.model.set({ - shares: [ - {share_with_displayname: 'User One', share_with: 'User One'}, - {share_with_displayname: 'User Two', share_with: 'User Two'}, - {share_with_displayname: 'Group One', share_with: 'Group One'}, - {share_with_displayname: 'Group Two', share_with: 'Group Two'} - ] - }); - - expect($action.text().trim()).toEqual('Shared with Group One Shared with Group Two Shared with User One Shared with User Two'); - expect($action.find('.icon').hasClass('icon-shared')).toEqual(true); - expect($action.find('.icon').hasClass('icon-public')).toEqual(false); - }); - it('updates share icon after updating shares of a file', function() { - var $action, $tr; - OC.Share.statuses = {1: {link: false, path: '/subdir'}}; - fileList.setFiles([{ - id: 1, - type: 'file', - name: 'One.txt', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_ALL, - etag: 'abc' - }]); - $action = fileList.$el.find('tbody tr:first .action-share'); - $tr = fileList.$el.find('tr:first'); - - $tr.find('.action-share').click(); - - // simulate updating shares - shareTab._dialog.model.set({ - shares: [ - {share_with_displayname: 'User One', share_with: 'User One'}, - {share_with_displayname: 'User Two', share_with: 'User Two'}, - {share_with_displayname: 'User Three', share_with: 'User Three'} - ] - }); - - expect($action.text().trim()).toEqual('Shared with User One Shared with User Three Shared with User Two'); - expect($action.find('.icon').hasClass('icon-shared')).toEqual(true); - expect($action.find('.icon').hasClass('icon-public')).toEqual(false); - }); - it('removes share icon after removing all shares from a file', function() { - var $action, $tr; - OC.Share.statuses = {1: {link: false, path: '/subdir'}}; - fileList.setFiles([{ - id: 1, - type: 'file', - name: 'One.txt', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_ALL, - etag: 'abc', - recipients: 'User One, User Two' - }]); - $action = fileList.$el.find('tbody tr:first .action-share'); - $tr = fileList.$el.find('tr:first'); - - $tr.find('.action-share').click(); - - // simulate updating shares - shareTab._dialog.model.set({ - shares: [] - }); - - expect($tr.attr('data-share-recipient-data')).not.toBeDefined(); - }); - it('keep share text after updating reshare', function() { - var $action, $tr; - OC.Share.statuses = {1: {link: false, path: '/subdir'}}; - fileList.setFiles([{ - id: 1, - type: 'file', - name: 'One.txt', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_ALL, - etag: 'abc', - shareOwner: 'User One', - shareOwnerId: 'User One' - }]); - $action = fileList.$el.find('tbody tr:first .action-share'); - $tr = fileList.$el.find('tr:first'); - - $tr.find('.action-share').click(); - - // simulate updating shares - shareTab._dialog.model.set({ - shares: [{share_with_displayname: 'User Two'}] - }); - - expect($action.find('>span').text().trim()).toEqual('Shared by User One'); - expect($action.find('.icon').hasClass('icon-shared')).toEqual(false); - expect($action.find('.icon').hasClass('icon-public')).toEqual(false); - }); - it('keep share text after unsharing reshare', function() { - var $action, $tr; - OC.Share.statuses = {1: {link: false, path: '/subdir'}}; - fileList.setFiles([{ - id: 1, - type: 'file', - name: 'One.txt', - path: '/subdir', - mimetype: 'text/plain', - size: 12, - permissions: OC.PERMISSION_ALL, - etag: 'abc', - shareOwner: 'User One', - shareOwnerId: 'User One', - recipients: 'User Two', - recipientData: {'User Two': 'User Two'} - }]); - $action = fileList.$el.find('tbody tr:first .action-share'); - $tr = fileList.$el.find('tr:first'); - - $tr.find('.action-share').click(); - - // simulate updating shares - shareTab._dialog.model.set({ - shares: [] - }); - - expect($tr.attr('data-share-recipient-data')).not.toBeDefined(); - - expect($action.find('>span').text().trim()).toEqual('Shared by User One'); - expect($action.find('.icon').hasClass('icon-shared')).toEqual(false); - expect($action.find('.icon').hasClass('icon-public')).toEqual(false); - }); - }); describe('Excluded lists', function() { function createListThenAttach(listId) { var fileActions = new OCA.Files.FileActions(); @@ -513,20 +321,5 @@ describe('OCA.Sharing.Util tests', function() { afterEach(function() { shareTabSpy.restore(); }); - - it('updates fileInfoModel when shares changed', function() { - var changeHandler = sinon.stub(); - fileInfoModel.on('change', changeHandler); - - shareTabSpy.getCall(0).returnValue.trigger('sharesChanged', shareModel); - - expect(changeHandler.calledOnce).toEqual(true); - expect(changeHandler.getCall(0).args[0].changed).toEqual({ - shareTypes: [ - OC.Share.SHARE_TYPE_USER, - OC.Share.SHARE_TYPE_REMOTE - ] - }); - }); }); }); diff --git a/apps/systemtags/tests/js/systemtagsinfoviewSpec.js b/apps/systemtags/tests/js/systemtagsinfoviewSpec.js index 2f87468811..99c0471d50 100644 --- a/apps/systemtags/tests/js/systemtagsinfoviewSpec.js +++ b/apps/systemtags/tests/js/systemtagsinfoviewSpec.js @@ -45,7 +45,7 @@ describe('OCA.SystemTags.SystemTagsInfoView tests', function() { var fetchStub = sinon.stub(OC.SystemTags.SystemTagsMappingCollection.prototype, 'fetch'); var setDataStub = sinon.stub(OC.SystemTags.SystemTagsInputField.prototype, 'setData'); - expect(view.$el.hasClass('hidden')).toEqual(true); + expect(view.$el.hasClass('hidden')).toEqual(false); view.setFileInfo({id: '123'}); expect(view.$el.find('input[name=tags]').length).toEqual(1); @@ -211,10 +211,10 @@ describe('OCA.SystemTags.SystemTagsInfoView tests', function() { expect(view.isVisible()).toBeTruthy(); }); - it('is not visible after rendering', function() { + it('is visible after rendering', function() { view.render(); - expect(view.isVisible()).toBeFalsy(); + expect(view.isVisible()).toBeTruthy(); }); it('shows and hides the element', function() { view.show();