appSpec.js 2.5 KB

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