diff options
Diffstat (limited to 'apps/files_versions/tests/js')
-rw-r--r-- | apps/files_versions/tests/js/versioncollectionSpec.js | 161 | ||||
-rw-r--r-- | apps/files_versions/tests/js/versionmodelSpec.js | 96 | ||||
-rw-r--r-- | apps/files_versions/tests/js/versionstabviewSpec.js | 208 |
3 files changed, 0 insertions, 465 deletions
diff --git a/apps/files_versions/tests/js/versioncollectionSpec.js b/apps/files_versions/tests/js/versioncollectionSpec.js deleted file mode 100644 index 87065fa1d36..00000000000 --- a/apps/files_versions/tests/js/versioncollectionSpec.js +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2015 - * - * This file is licensed under the Affero General Public License version 3 - * or later. - * - * See the COPYING-README file. - * - */ -describe('OCA.Versions.VersionCollection', function() { - var VersionCollection = OCA.Versions.VersionCollection; - var collection, fileInfoModel; - - beforeEach(function() { - fileInfoModel = new OCA.Files.FileInfoModel({ - path: '/subdir', - name: 'some file.txt' - }); - collection = new VersionCollection(); - collection.setFileInfo(fileInfoModel); - }); - it('fetches the next page', function() { - collection.fetchNext(); - - expect(fakeServer.requests.length).toEqual(1); - expect(fakeServer.requests[0].url).toEqual( - OC.generateUrl('apps/files_versions/ajax/getVersions.php') + - '?source=%2Fsubdir%2Fsome%20file.txt&start=0' - ); - fakeServer.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({ - status: 'success', - data: { - endReached: false, - versions: [{ - version: 10000000, - size: 123, - name: 'some file.txt', - fullPath: '/subdir/some file.txt' - },{ - version: 15000000, - size: 150, - name: 'some file.txt', - path: '/subdir/some file.txt' - }] - } - }) - ); - - expect(collection.length).toEqual(2); - expect(collection.hasMoreResults()).toEqual(true); - - collection.fetchNext(); - - expect(fakeServer.requests.length).toEqual(2); - expect(fakeServer.requests[1].url).toEqual( - OC.generateUrl('apps/files_versions/ajax/getVersions.php') + - '?source=%2Fsubdir%2Fsome%20file.txt&start=2' - ); - fakeServer.requests[1].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({ - status: 'success', - data: { - endReached: true, - versions: [{ - version: 18000000, - size: 123, - name: 'some file.txt', - path: '/subdir/some file.txt' - }] - } - }) - ); - - expect(collection.length).toEqual(3); - expect(collection.hasMoreResults()).toEqual(false); - - collection.fetchNext(); - - // no further requests - expect(fakeServer.requests.length).toEqual(2); - }); - it('properly parses the results', function() { - collection.fetchNext(); - - expect(fakeServer.requests.length).toEqual(1); - expect(fakeServer.requests[0].url).toEqual( - OC.generateUrl('apps/files_versions/ajax/getVersions.php') + - '?source=%2Fsubdir%2Fsome%20file.txt&start=0' - ); - fakeServer.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({ - status: 'success', - data: { - endReached: false, - versions: [{ - version: 10000000, - size: 123, - name: 'some file.txt', - path: '/subdir/some file.txt' - },{ - version: 15000000, - size: 150, - name: 'some file.txt', - path: '/subdir/some file.txt' - }] - } - }) - ); - - expect(collection.length).toEqual(2); - - var model = collection.at(0); - expect(model.get('id')).toEqual(10000000); - expect(model.get('timestamp')).toEqual(10000000); - expect(model.get('name')).toEqual('some file.txt'); - expect(model.get('fullPath')).toEqual('/subdir/some file.txt'); - expect(model.get('size')).toEqual(123); - - model = collection.at(1); - expect(model.get('id')).toEqual(15000000); - expect(model.get('timestamp')).toEqual(15000000); - expect(model.get('name')).toEqual('some file.txt'); - expect(model.get('fullPath')).toEqual('/subdir/some file.txt'); - expect(model.get('size')).toEqual(150); - }); - it('resets page counted when setting a new file info model', function() { - collection.fetchNext(); - - expect(fakeServer.requests.length).toEqual(1); - fakeServer.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({ - status: 'success', - data: { - endReached: true, - versions: [{ - version: 18000000, - size: 123, - name: 'some file.txt', - path: '/subdir/some file.txt' - }] - } - }) - ); - - expect(collection.hasMoreResults()).toEqual(false); - - collection.setFileInfo(fileInfoModel); - - expect(collection.hasMoreResults()).toEqual(true); - }); -}); - diff --git a/apps/files_versions/tests/js/versionmodelSpec.js b/apps/files_versions/tests/js/versionmodelSpec.js deleted file mode 100644 index 0f1c06581d5..00000000000 --- a/apps/files_versions/tests/js/versionmodelSpec.js +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2015 - * - * This file is licensed under the Affero General Public License version 3 - * or later. - * - * See the COPYING-README file. - * - */ -describe('OCA.Versions.VersionModel', function() { - var VersionModel = OCA.Versions.VersionModel; - var model; - - beforeEach(function() { - model = new VersionModel({ - id: 10000000, - timestamp: 10000000, - fullPath: '/subdir/some file.txt', - name: 'some file.txt', - size: 150 - }); - }); - - it('returns the full path', function() { - expect(model.getFullPath()).toEqual('/subdir/some file.txt'); - }); - it('returns the preview url', function() { - expect(model.getPreviewUrl()) - .toEqual(OC.generateUrl('/apps/files_versions/preview') + - '?file=%2Fsubdir%2Fsome%20file.txt&version=10000000' - ); - }); - it('returns the download url', function() { - expect(model.getDownloadUrl()) - .toEqual(OC.generateUrl('/apps/files_versions/download.php') + - '?file=%2Fsubdir%2Fsome%20file.txt&revision=10000000' - ); - }); - describe('reverting', function() { - var revertEventStub; - var successStub; - var errorStub; - - beforeEach(function() { - revertEventStub = sinon.stub(); - errorStub = sinon.stub(); - successStub = sinon.stub(); - - model.on('revert', revertEventStub); - model.on('error', errorStub); - }); - it('tells the server to revert when calling the revert method', function() { - model.revert({ - success: successStub - }); - - expect(fakeServer.requests.length).toEqual(1); - expect(fakeServer.requests[0].url) - .toEqual( - OC.generateUrl('/apps/files_versions/ajax/rollbackVersion.php') + - '?file=%2Fsubdir%2Fsome+file.txt&revision=10000000' - ); - - fakeServer.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({ - status: 'success', - }) - ); - - expect(revertEventStub.calledOnce).toEqual(true); - expect(successStub.calledOnce).toEqual(true); - expect(errorStub.notCalled).toEqual(true); - }); - it('triggers error event when server returns a failure', function() { - model.revert({ - success: successStub - }); - - expect(fakeServer.requests.length).toEqual(1); - fakeServer.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({ - status: 'error', - }) - ); - - expect(revertEventStub.notCalled).toEqual(true); - expect(successStub.notCalled).toEqual(true); - expect(errorStub.calledOnce).toEqual(true); - }); - }); -}); - diff --git a/apps/files_versions/tests/js/versionstabviewSpec.js b/apps/files_versions/tests/js/versionstabviewSpec.js deleted file mode 100644 index 306dd66be2a..00000000000 --- a/apps/files_versions/tests/js/versionstabviewSpec.js +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (c) 2015 - * - * This file is licensed under the Affero General Public License version 3 - * or later. - * - * See the COPYING-README file. - * - */ -describe('OCA.Versions.VersionsTabView', function() { - var VersionCollection = OCA.Versions.VersionCollection; - var VersionModel = OCA.Versions.VersionModel; - var VersionsTabView = OCA.Versions.VersionsTabView; - - var fetchStub, fileInfoModel, tabView, testVersions, clock; - - beforeEach(function() { - clock = sinon.useFakeTimers(Date.UTC(2015, 6, 17, 1, 2, 0, 3)); - var time1 = Date.UTC(2015, 6, 17, 1, 2, 0, 3) / 1000; - var time2 = Date.UTC(2015, 6, 15, 1, 2, 0, 3) / 1000; - - var version1 = new VersionModel({ - id: time1, - timestamp: time1, - name: 'some file.txt', - size: 140, - fullPath: '/subdir/some file.txt' - }); - var version2 = new VersionModel({ - id: time2, - timestamp: time2, - name: 'some file.txt', - size: 150, - fullPath: '/subdir/some file.txt' - }); - - testVersions = [version1, version2]; - - fetchStub = sinon.stub(VersionCollection.prototype, 'fetch'); - fileInfoModel = new OCA.Files.FileInfoModel({ - id: 123, - name: 'test.txt' - }); - tabView = new VersionsTabView(); - tabView.render(); - }); - - afterEach(function() { - fetchStub.restore(); - tabView.remove(); - clock.restore(); - }); - - describe('rendering', function() { - it('reloads matching versions when setting file info model', function() { - tabView.setFileInfo(fileInfoModel); - expect(fetchStub.calledOnce).toEqual(true); - }); - - it('renders loading icon while fetching versions', function() { - tabView.setFileInfo(fileInfoModel); - tabView.collection.trigger('request'); - - expect(tabView.$el.find('.loading').length).toEqual(1); - expect(tabView.$el.find('.versions li').length).toEqual(0); - }); - - it('renders versions', function() { - - tabView.setFileInfo(fileInfoModel); - tabView.collection.set(testVersions); - - var version1 = testVersions[0]; - var version2 = testVersions[1]; - var $versions = tabView.$el.find('.versions>li'); - expect($versions.length).toEqual(2); - var $item = $versions.eq(0); - expect($item.find('.downloadVersion').attr('href')).toEqual(version1.getDownloadUrl()); - expect($item.find('.versiondate').text()).toEqual('seconds ago'); - expect($item.find('.revertVersion').length).toEqual(1); - expect($item.find('.preview').attr('src')).toEqual(version1.getPreviewUrl()); - - $item = $versions.eq(1); - expect($item.find('.downloadVersion').attr('href')).toEqual(version2.getDownloadUrl()); - expect($item.find('.versiondate').text()).toEqual('2 days ago'); - expect($item.find('.revertVersion').length).toEqual(1); - expect($item.find('.preview').attr('src')).toEqual(version2.getPreviewUrl()); - }); - }); - - describe('More versions', function() { - var hasMoreResultsStub; - - beforeEach(function() { - tabView.collection.set(testVersions); - hasMoreResultsStub = sinon.stub(VersionCollection.prototype, 'hasMoreResults'); - }); - afterEach(function() { - hasMoreResultsStub.restore(); - }); - - it('shows "More versions" button when more versions are available', function() { - hasMoreResultsStub.returns(true); - tabView.collection.trigger('sync'); - - expect(tabView.$el.find('.showMoreVersions').hasClass('hidden')).toEqual(false); - }); - it('does not show "More versions" button when more versions are available', function() { - hasMoreResultsStub.returns(false); - tabView.collection.trigger('sync'); - - expect(tabView.$el.find('.showMoreVersions').hasClass('hidden')).toEqual(true); - }); - it('fetches and appends the next page when clicking the "More" button', function() { - hasMoreResultsStub.returns(true); - - expect(fetchStub.notCalled).toEqual(true); - - tabView.$el.find('.showMoreVersions').click(); - - expect(fetchStub.calledOnce).toEqual(true); - }); - it('appends version to the list when added to collection', function() { - var time3 = Date.UTC(2015, 6, 10, 1, 0, 0, 0) / 1000; - - var version3 = new VersionModel({ - id: time3, - timestamp: time3, - name: 'some file.txt', - size: 54, - fullPath: '/subdir/some file.txt' - }); - - tabView.collection.add(version3); - - expect(tabView.$el.find('.versions>li').length).toEqual(3); - - var $item = tabView.$el.find('.versions>li').eq(2); - expect($item.find('.downloadVersion').attr('href')).toEqual(version3.getDownloadUrl()); - expect($item.find('.versiondate').text()).toEqual('7 days ago'); - expect($item.find('.revertVersion').length).toEqual(1); - expect($item.find('.preview').attr('src')).toEqual(version3.getPreviewUrl()); - }); - }); - - describe('Reverting', function() { - var revertStub; - - beforeEach(function() { - revertStub = sinon.stub(VersionModel.prototype, 'revert'); - tabView.setFileInfo(fileInfoModel); - tabView.collection.set(testVersions); - }); - - afterEach(function() { - revertStub.restore(); - }); - - it('tells the model to revert when clicking "Revert"', function() { - tabView.$el.find('.revertVersion').eq(1).click(); - - expect(revertStub.calledOnce).toEqual(true); - }); - it('triggers busy state during revert', function() { - var busyStub = sinon.stub(); - fileInfoModel.on('busy', busyStub); - - tabView.$el.find('.revertVersion').eq(1).click(); - - expect(busyStub.calledOnce).toEqual(true); - expect(busyStub.calledWith(fileInfoModel, true)).toEqual(true); - - busyStub.reset(); - revertStub.getCall(0).args[0].success(); - - expect(busyStub.calledOnce).toEqual(true); - expect(busyStub.calledWith(fileInfoModel, false)).toEqual(true); - }); - it('updates the file info model with the information from the reverted revision', function() { - var changeStub = sinon.stub(); - fileInfoModel.on('change', changeStub); - - tabView.$el.find('.revertVersion').eq(1).click(); - - expect(changeStub.notCalled).toEqual(true); - - revertStub.getCall(0).args[0].success(); - - expect(changeStub.calledOnce).toEqual(true); - var changes = changeStub.getCall(0).args[0].changed; - expect(changes.size).toEqual(150); - expect(changes.mtime).toEqual(testVersions[1].get('timestamp') * 1000); - expect(changes.etag).toBeDefined(); - }); - it('shows notification on revert error', function() { - var notificationStub = sinon.stub(OC.Notification, 'showTemporary'); - - tabView.$el.find('.revertVersion').eq(1).click(); - - revertStub.getCall(0).args[0].error(); - - expect(notificationStub.calledOnce).toEqual(true); - - notificationStub.restore(); - }); - }); -}); - |