-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathFilesList.spec.ts
More file actions
205 lines (172 loc) · 5.7 KB
/
FilesList.spec.ts
File metadata and controls
205 lines (172 loc) · 5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/**
* SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import FilesList from '../../../views/FilesList/FilesList.vue'
import { useFilesStore } from '../../../store/files.js'
import { useUserConfigStore } from '../../../store/userconfig.js'
vi.mock('@nextcloud/l10n', () => ({
t: vi.fn((_app: string, text: string) => text),
}))
vi.mock('@nextcloud/logger', () => ({
getLogger: vi.fn(() => ({
error: vi.fn(),
warn: vi.fn(),
info: vi.fn(),
debug: vi.fn(),
})),
getLoggerBuilder: vi.fn(() => ({
setApp: vi.fn().mockReturnThis(),
detectUser: vi.fn().mockReturnThis(),
build: vi.fn(() => ({
error: vi.fn(),
warn: vi.fn(),
info: vi.fn(),
debug: vi.fn(),
})),
})),
}))
vi.mock('@nextcloud/axios', () => ({
default: {
get: vi.fn(),
post: vi.fn(),
delete: vi.fn(),
patch: vi.fn(),
},
}))
vi.mock('@nextcloud/router', () => ({
generateOcsUrl: vi.fn((path: string) => `/ocs/v2.php${path}`),
}))
vi.mock('@nextcloud/auth', () => ({
getCurrentUser: vi.fn(() => ({
uid: 'testuser',
displayName: 'Test User',
})),
}))
vi.mock('@nextcloud/event-bus', () => ({
emit: vi.fn(),
subscribe: vi.fn(),
}))
vi.mock('@nextcloud/initial-state', () => ({
loadState: vi.fn((_app: string, _key: string, defaultValue: unknown) => defaultValue),
}))
vi.mock('@nextcloud/moment', () => ({
default: vi.fn(() => ({
format: () => 'date',
fromNow: () => '2 days ago',
})),
}))
vi.mock('@nextcloud/vue/components/NcAppContent', () => ({
default: { name: 'NcAppContent', template: '<div><slot /></div>' },
}))
vi.mock('@nextcloud/vue/components/NcBreadcrumb', () => ({
default: { name: 'NcBreadcrumb', template: '<div><slot name="icon" /></div>' },
}))
vi.mock('@nextcloud/vue/components/NcBreadcrumbs', () => ({
default: { name: 'NcBreadcrumbs', template: '<div><slot /><slot name="actions" /></div>' },
}))
vi.mock('@nextcloud/vue/components/NcButton', () => ({
default: { name: 'NcButton', template: '<button><slot name="icon" /></button>' },
}))
vi.mock('@nextcloud/vue/components/NcEmptyContent', () => ({
default: { name: 'NcEmptyContent', template: '<section><slot name="action" /><slot name="icon" /></section>' },
}))
vi.mock('@nextcloud/vue/components/NcIconSvgWrapper', () => ({
default: {
name: 'NcIconSvgWrapper',
props: ['path', 'svg', 'size'],
template: '<i class="nc-icon" :data-path="path" :data-svg="svg" />',
},
}))
vi.mock('@nextcloud/vue/components/NcLoadingIcon', () => ({
default: { name: 'NcLoadingIcon', template: '<span class="loading" />' },
}))
vi.mock('../../../views/FilesList/FilesListVirtual.vue', () => ({
default: {
name: 'FilesListVirtual',
props: ['nodes', 'loading'],
template: '<div class="virtual-list"><slot name="empty" /></div>',
},
}))
vi.mock('../../../components/Request/RequestPicker.vue', () => ({
default: {
name: 'RequestPicker',
template: '<div class="request-picker-stub" />',
},
}))
const routeMock = {
query: {},
}
describe('FilesList.vue rendering rules', () => {
beforeEach(() => {
setActivePinia(createPinia())
vi.clearAllMocks()
})
function mountComponent() {
return mount(FilesList, {
global: {
mocks: {
$route: routeMock,
},
},
})
}
it('exposes mdi icons from setup for template bindings', async () => {
const filesStore = useFilesStore()
vi.spyOn(filesStore, 'getAllFiles').mockResolvedValue({})
const wrapper = mountComponent()
await flushPromises()
expect(wrapper.vm.mdiFolder).toBeTruthy()
expect(wrapper.vm.mdiViewGrid).toBeTruthy()
expect(wrapper.vm.mdiViewList).toBeTruthy()
})
it('shows empty-state request action when user can request sign', async () => {
const filesStore = useFilesStore()
const userConfigStore = useUserConfigStore()
filesStore.canRequestSign = true
filesStore.files = {}
filesStore.ordered = []
userConfigStore.files_list_grid_view = false
vi.spyOn(filesStore, 'getAllFiles').mockResolvedValue({})
const wrapper = mountComponent()
await flushPromises()
const pickers = wrapper.findAll('.request-picker-stub')
expect(pickers).toHaveLength(2)
})
it('hides empty-state request action when user cannot request sign', async () => {
const filesStore = useFilesStore()
const userConfigStore = useUserConfigStore()
filesStore.canRequestSign = false
filesStore.files = {}
filesStore.ordered = []
userConfigStore.files_list_grid_view = false
vi.spyOn(filesStore, 'getAllFiles').mockResolvedValue({})
const wrapper = mountComponent()
await flushPromises()
const pickers = wrapper.findAll('.request-picker-stub')
expect(pickers).toHaveLength(1)
})
it('renders grid toggle icon path when in list mode', async () => {
const filesStore = useFilesStore()
const userConfigStore = useUserConfigStore()
vi.spyOn(filesStore, 'getAllFiles').mockResolvedValue({})
userConfigStore.files_list_grid_view = false
const wrapper = mountComponent()
await flushPromises()
const iconWithPath = wrapper.findAll('.nc-icon').find((node) => !!node.attributes('data-path'))
expect(iconWithPath?.attributes('data-path')).toBe(wrapper.vm.mdiViewGrid)
})
it('renders list toggle icon path when in grid mode', async () => {
const filesStore = useFilesStore()
const userConfigStore = useUserConfigStore()
vi.spyOn(filesStore, 'getAllFiles').mockResolvedValue({})
userConfigStore.files_list_grid_view = true
const wrapper = mountComponent()
await flushPromises()
const iconWithPath = wrapper.findAll('.nc-icon').find((node) => !!node.attributes('data-path'))
expect(iconWithPath?.attributes('data-path')).toBe(wrapper.vm.mdiViewList)
})
})