Files
kite/frontend/src/components/cloud/__tests__/CloudFolderTreeItem.test.js
T
curo1305 057b4999fd feat(12-06): UUID-only cloud navigation, breadcrumb hierarchy, route-aware sidebar
- CloudProviderTreeItem: getCloudFoldersByConnectionId(connection.id) + /cloud/{uuid}/root
- CloudFolderTreeItem: connectionId prop replaces provider slug in browse + route
- AppSidebar: Cloud Storage active only on exact /cloud; connection nodes use per-connection isActive
- New tests: CloudProviderTreeItem, CloudFolderTreeItem, AppSidebar cloud active-state
2026-06-21 22:30:05 +02:00

83 lines
2.9 KiB
JavaScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
import { mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
const mockPush = vi.fn()
let mockRoutePath = '/cloud/uuid-conn-1/some-folder'
vi.mock('vue-router', () => ({
useRouter: () => ({ push: mockPush }),
useRoute: () => ({ path: mockRoutePath }),
}))
vi.mock('../../../api/client.js', () => ({
getCloudFoldersByConnectionId: vi.fn().mockResolvedValue({ items: [] }),
getCloudFolders: vi.fn(), // deprecated — must NOT be called
}))
import * as api from '../../../api/client.js'
import CloudFolderTreeItem from '../CloudFolderTreeItem.vue'
const TreeItemStub = {
name: 'TreeItem',
template: `<div data-test="tree-item" @click="$emit('select')"><slot name="children" :children="[]" /></div>`,
props: ['label', 'loadChildren', 'depth', 'isActive', 'expandable'],
emits: ['select'],
}
const globalStubs = {
TreeItem: TreeItemStub,
AppIcon: true,
}
const folder = { id: 'some-folder', name: 'Documents', is_dir: true }
beforeEach(() => {
setActivePinia(createPinia())
vi.clearAllMocks()
mockRoutePath = '/cloud/uuid-conn-1/some-folder'
})
describe('CloudFolderTreeItem', () => {
it('navigates to /cloud/{connectionId}/{folderId}, never /cloud/{provider}/{folderId}', async () => {
const wrapper = mount(CloudFolderTreeItem, {
props: { folder, connectionId: 'uuid-conn-1', depth: 2 },
global: { stubs: globalStubs },
})
await wrapper.find('[data-test="tree-item"]').trigger('click')
expect(mockPush).toHaveBeenCalledWith('/cloud/uuid-conn-1/some-folder')
expect(mockPush).not.toHaveBeenCalledWith(expect.stringContaining('nextcloud'))
})
it('browses children using getCloudFoldersByConnectionId with folder.id', async () => {
const wrapper = mount(CloudFolderTreeItem, {
props: { folder, connectionId: 'uuid-conn-1', depth: 2 },
global: { stubs: globalStubs },
})
const treeItemStub = wrapper.findComponent(TreeItemStub)
const loadChildren = treeItemStub.props('loadChildren')
if (loadChildren) {
await loadChildren()
expect(api.getCloudFoldersByConnectionId).toHaveBeenCalledWith('uuid-conn-1', 'some-folder')
}
expect(api.getCloudFolders).not.toHaveBeenCalled()
})
it('isActive=true when current route matches this folder', () => {
const wrapper = mount(CloudFolderTreeItem, {
props: { folder, connectionId: 'uuid-conn-1', depth: 2 },
global: { stubs: globalStubs },
})
expect(wrapper.findComponent(TreeItemStub).props('isActive')).toBe(true)
})
it('isActive=false when route does not match this folder', () => {
mockRoutePath = '/cloud/uuid-conn-1/other-folder'
const wrapper = mount(CloudFolderTreeItem, {
props: { folder, connectionId: 'uuid-conn-1', depth: 2 },
global: { stubs: globalStubs },
})
expect(wrapper.findComponent(TreeItemStub).props('isActive')).toBe(false)
})
})