/** * @copyright Copyright (c) 2023 John Molakvoæ * * @author John Molakvoæ * * @license AGPL-3.0-or-later * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ /* eslint-disable n/no-extraneous-import */ import type { OCSResponse } from '@nextcloud/typings/ocs' import { expect } from '@jest/globals' import { Folder, Navigation, View, getNavigation } from '@nextcloud/files' import axios from '@nextcloud/axios' import '../main' import registerSharingViews from './shares' declare global { interface Window { _nc_navigation?: Navigation } } describe('Sharing views definition', () => { let Navigation beforeEach(() => { Navigation = getNavigation() expect(window._nc_navigation).toBeDefined() }) afterAll(() => { delete window._nc_navigation }) test('Default values', () => { jest.spyOn(Navigation, 'register') expect(Navigation.views.length).toBe(0) registerSharingViews() const shareOverviewView = Navigation.views.find(view => view.id === 'shareoverview') as View const sharesChildViews = Navigation.views.filter(view => view.parent === 'shareoverview') as View[] expect(Navigation.register).toHaveBeenCalledTimes(6) // one main view and no children expect(Navigation.views.length).toBe(6) expect(shareOverviewView).toBeDefined() expect(sharesChildViews.length).toBe(5) expect(shareOverviewView?.id).toBe('shareoverview') expect(shareOverviewView?.name).toBe('Shares') expect(shareOverviewView?.caption).toBe('Overview of shared files.') expect(shareOverviewView?.icon).toBe('SvgMock') expect(shareOverviewView?.order).toBe(20) expect(shareOverviewView?.columns).toStrictEqual([]) expect(shareOverviewView?.getContents).toBeDefined() const dataProvider = [ { id: 'sharingin', name: 'Shared with you' }, { id: 'sharingout', name: 'Shared with others' }, { id: 'sharinglinks', name: 'Shared by link' }, { id: 'deletedshares', name: 'Deleted shares' }, { id: 'pendingshares', name: 'Pending shares' }, ] sharesChildViews.forEach((view, index) => { expect(view?.id).toBe(dataProvider[index].id) expect(view?.parent).toBe('shareoverview') expect(view?.name).toBe(dataProvider[index].name) expect(view?.caption).toBeDefined() expect(view?.emptyTitle).toBeDefined() expect(view?.emptyCaption).toBeDefined() expect(view?.icon).toBe('SvgMock') expect(view?.order).toBe(index + 1) expect(view?.columns).toStrictEqual([]) expect(view?.getContents).toBeDefined() }) }) }) describe('Sharing views contents', () => { let Navigation beforeEach(() => { Navigation = getNavigation() expect(window._nc_navigation).toBeDefined() }) afterAll(() => { delete window._nc_navigation }) test('Sharing overview get contents', async () => { jest.spyOn(axios, 'get').mockImplementation(async (): Promise => { return { data: { ocs: { meta: { status: 'ok', statuscode: 200, message: 'OK', }, data: [], }, } as OCSResponse, } }) registerSharingViews() expect(Navigation.views.length).toBe(6) Navigation.views.forEach(async (view: View) => { const content = await view.getContents('/') expect(content.contents).toStrictEqual([]) expect(content.folder).toBeInstanceOf(Folder) }) }) })