|
| 1 | +/*! |
| 2 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import { File, Folder, Permission } from '@nextcloud/files' |
| 7 | +import { createTestingPinia } from '@pinia/testing' |
| 8 | +import { shallowMount } from '@vue/test-utils' |
| 9 | +import { beforeEach, describe, expect, test, vi } from 'vitest' |
| 10 | +import { nextTick } from 'vue' |
| 11 | +import FileEntryGrid from './FileEntryGrid.vue' |
| 12 | +import router from '../router/router.ts' |
| 13 | +import { useActiveStore } from '../store/active.ts' |
| 14 | + |
| 15 | +// useFileListWidth builds its ResizeObserver while the module is evaluated, so |
| 16 | +// the stub has to exist before the import chain runs. jsdom-testing-mocks sets |
| 17 | +// its observer up from a hook, which is already too late here. |
| 18 | +vi.hoisted(() => { |
| 19 | + globalThis.ResizeObserver = class { |
| 20 | + observe() {} |
| 21 | + unobserve() {} |
| 22 | + disconnect() {} |
| 23 | + } |
| 24 | +}) |
| 25 | + |
| 26 | +vi.mock('@nextcloud/auth') |
| 27 | + |
| 28 | +const source = new File({ |
| 29 | + id: 42, |
| 30 | + source: 'http://nextcloud.local/remote.php/dav/files/test/Deep/Nested/report.pdf', |
| 31 | + root: '/files/test', |
| 32 | + owner: 'test', |
| 33 | + mime: 'application/pdf', |
| 34 | + permissions: Permission.READ, |
| 35 | +}) |
| 36 | + |
| 37 | +const nestedFolder = new Folder({ |
| 38 | + id: 41, |
| 39 | + source: 'http://nextcloud.local/remote.php/dav/files/test/Deep/Nested', |
| 40 | + root: '/files/test', |
| 41 | + owner: 'test', |
| 42 | + permissions: Permission.READ, |
| 43 | +}) |
| 44 | + |
| 45 | +describe('FileEntryGrid.vue', () => { |
| 46 | + beforeEach(async () => { |
| 47 | + await router.replace({ name: 'filelist', params: { view: 'files' } }) |
| 48 | + }) |
| 49 | + |
| 50 | + // The grid entry hands its `activeFolder` to the file actions, so a stale copy |
| 51 | + // makes opening a file navigate to whichever folder was active when the entry |
| 52 | + // was first rendered rather than the one the file lives in. |
| 53 | + test('follows the active folder after navigating', async () => { |
| 54 | + const wrapper = shallowMount(FileEntryGrid, { |
| 55 | + propsData: { source, nodes: [source] }, |
| 56 | + mocks: { t: (_: string, text: string) => text }, |
| 57 | + router, |
| 58 | + pinia: createTestingPinia({ createSpy: vi.fn }), |
| 59 | + }) |
| 60 | + const activeStore = useActiveStore() |
| 61 | + |
| 62 | + expect(wrapper.vm.activeFolder).not.toBe(nestedFolder) |
| 63 | + |
| 64 | + activeStore.activeFolder = nestedFolder |
| 65 | + await nextTick() |
| 66 | + |
| 67 | + expect(wrapper.vm.activeFolder).toBe(nestedFolder) |
| 68 | + }) |
| 69 | +}) |
0 commit comments