You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shares.spec.ts 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
  3. *
  4. * @author John Molakvoæ <skjnldsv@protonmail.com>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /* eslint-disable n/no-extraneous-import */
  23. import type { OCSResponse } from '@nextcloud/typings/ocs'
  24. import { expect } from '@jest/globals'
  25. import { Folder, Navigation, View, getNavigation } from '@nextcloud/files'
  26. import axios from '@nextcloud/axios'
  27. import '../main'
  28. import registerSharingViews from './shares'
  29. declare global {
  30. interface Window {
  31. _nc_navigation?: Navigation
  32. }
  33. }
  34. describe('Sharing views definition', () => {
  35. let Navigation
  36. beforeEach(() => {
  37. Navigation = getNavigation()
  38. expect(window._nc_navigation).toBeDefined()
  39. })
  40. afterAll(() => {
  41. delete window._nc_navigation
  42. })
  43. test('Default values', () => {
  44. jest.spyOn(Navigation, 'register')
  45. expect(Navigation.views.length).toBe(0)
  46. registerSharingViews()
  47. const shareOverviewView = Navigation.views.find(view => view.id === 'shareoverview') as View
  48. const sharesChildViews = Navigation.views.filter(view => view.parent === 'shareoverview') as View[]
  49. expect(Navigation.register).toHaveBeenCalledTimes(6)
  50. // one main view and no children
  51. expect(Navigation.views.length).toBe(6)
  52. expect(shareOverviewView).toBeDefined()
  53. expect(sharesChildViews.length).toBe(5)
  54. expect(shareOverviewView?.id).toBe('shareoverview')
  55. expect(shareOverviewView?.name).toBe('Shares')
  56. expect(shareOverviewView?.caption).toBe('Overview of shared files.')
  57. expect(shareOverviewView?.icon).toBe('<svg>SvgMock</svg>')
  58. expect(shareOverviewView?.order).toBe(20)
  59. expect(shareOverviewView?.columns).toStrictEqual([])
  60. expect(shareOverviewView?.getContents).toBeDefined()
  61. const dataProvider = [
  62. { id: 'sharingin', name: 'Shared with you' },
  63. { id: 'sharingout', name: 'Shared with others' },
  64. { id: 'sharinglinks', name: 'Shared by link' },
  65. { id: 'deletedshares', name: 'Deleted shares' },
  66. { id: 'pendingshares', name: 'Pending shares' },
  67. ]
  68. sharesChildViews.forEach((view, index) => {
  69. expect(view?.id).toBe(dataProvider[index].id)
  70. expect(view?.parent).toBe('shareoverview')
  71. expect(view?.name).toBe(dataProvider[index].name)
  72. expect(view?.caption).toBeDefined()
  73. expect(view?.emptyTitle).toBeDefined()
  74. expect(view?.emptyCaption).toBeDefined()
  75. expect(view?.icon).toBe('<svg>SvgMock</svg>')
  76. expect(view?.order).toBe(index + 1)
  77. expect(view?.columns).toStrictEqual([])
  78. expect(view?.getContents).toBeDefined()
  79. })
  80. })
  81. })
  82. describe('Sharing views contents', () => {
  83. let Navigation
  84. beforeEach(() => {
  85. Navigation = getNavigation()
  86. expect(window._nc_navigation).toBeDefined()
  87. })
  88. afterAll(() => {
  89. delete window._nc_navigation
  90. })
  91. test('Sharing overview get contents', async () => {
  92. jest.spyOn(axios, 'get').mockImplementation(async (): Promise<any> => {
  93. return {
  94. data: {
  95. ocs: {
  96. meta: {
  97. status: 'ok',
  98. statuscode: 200,
  99. message: 'OK',
  100. },
  101. data: [],
  102. },
  103. } as OCSResponse<any>,
  104. }
  105. })
  106. registerSharingViews()
  107. expect(Navigation.views.length).toBe(6)
  108. Navigation.views.forEach(async (view: View) => {
  109. const content = await view.getContents('/')
  110. expect(content.contents).toStrictEqual([])
  111. expect(content.folder).toBeInstanceOf(Folder)
  112. })
  113. })
  114. })