appSpec.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * SPDX-FileCopyrightText: 2014 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. import $ from 'jquery'
  6. describe('OCA.Files_External.App tests', function() {
  7. const App = OCA.Files_External.App
  8. let fileList
  9. beforeEach(function() {
  10. $('#testArea').append(
  11. '<div id="app-navigation">'
  12. + '<ul><li data-id="files"><a>Files</a></li>'
  13. + '<li data-id="sharingin"><a></a></li>'
  14. + '<li data-id="sharingout"><a></a></li>'
  15. + '</ul></div>'
  16. + '<div id="app-content">'
  17. + '<div id="app-content-files" class="hidden">'
  18. + '</div>'
  19. + '<div id="app-content-extstoragemounts" class="hidden">'
  20. + '</div>'
  21. + '</div>'
  22. + '</div>',
  23. )
  24. fileList = App.initList($('#app-content-extstoragemounts'))
  25. })
  26. afterEach(function() {
  27. App.fileList = null
  28. fileList.destroy()
  29. fileList = null
  30. })
  31. describe('initialization', function() {
  32. it('inits external mounts list on show', function() {
  33. expect(App.fileList).toBeDefined()
  34. })
  35. })
  36. describe('file actions', function() {
  37. it('provides default file actions', function() {
  38. const fileActions = fileList.fileActions
  39. expect(fileActions.actions.all).toBeDefined()
  40. expect(fileActions.actions.all.Delete).toBeDefined()
  41. expect(fileActions.actions.all.Rename).toBeDefined()
  42. expect(fileActions.actions.all.Download).toBeDefined()
  43. expect(fileActions.defaults.dir).toEqual('Open')
  44. })
  45. it('redirects to files app when opening a directory', function() {
  46. const oldList = OCA.Files.App.fileList
  47. // dummy new list to make sure it exists
  48. OCA.Files.App.fileList = new OCA.Files.FileList($('<table><thead></thead><tbody></tbody></table>'))
  49. const setActiveViewStub = sinon.stub(OCA.Files.App, 'setActiveView')
  50. // create dummy table so we can click the dom
  51. const $table = '<table><thead></thead><tbody class="files-fileList"></tbody></table>'
  52. $('#app-content-extstoragemounts').append($table)
  53. App._inFileList = null
  54. fileList = App.initList($('#app-content-extstoragemounts'))
  55. fileList.setFiles([{
  56. name: 'testdir',
  57. type: 'dir',
  58. path: '/somewhere/inside/subdir',
  59. counterParts: ['user2'],
  60. shareOwner: 'user2',
  61. }])
  62. fileList.findFileEl('testdir').find('td a.name').click()
  63. expect(OCA.Files.App.fileList.getCurrentDirectory()).toEqual('/somewhere/inside/subdir/testdir')
  64. expect(setActiveViewStub.calledOnce).toEqual(true)
  65. expect(setActiveViewStub.calledWith('files')).toEqual(true)
  66. setActiveViewStub.restore()
  67. // restore old list
  68. OCA.Files.App.fileList = oldList
  69. })
  70. })
  71. })