forked from owncloud/web
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathFileDetails.spec.ts
201 lines (197 loc) · 7.53 KB
/
FileDetails.spec.ts
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
import FileDetails from '../../../../../src/components/SideBar/Details/FileDetails.vue'
import { ShareTypes } from 'web-client/src/helpers/share'
import {
createStore,
defaultComponentMocks,
defaultPlugins,
shallowMount,
defaultStoreMockOptions
} from 'web-test-helpers'
import { mock, mockDeep } from 'jest-mock-extended'
import { Resource, SpaceResource } from 'web-client/src/helpers'
const getResourceMock = ({
type = 'file',
tags = [],
thumbnail = null,
shareTypes = [],
share = null,
path = '/somePath/someResource'
} = {}) =>
mock<Resource>({
id: '1',
type,
ownerId: 'marie',
ownerDisplayName: 'Marie',
owner: null,
mdate: 'Wed, 21 Oct 2015 07:28:00 GMT',
tags,
size: '740',
path,
thumbnail,
shareTypes,
share
})
const selectors = {
eosPath: '[data-testid="eosPath"]',
eosDirectLink: '[data-testid="eosDirectLink"]',
sambaPath: '[data-testid="sambaPath"]',
ownerDisplayName: '[data-testid="ownerDisplayName"]',
preview: '[data-testid="preview"]',
resourceIcon: '.details-icon',
sharedBy: '[data-testid="shared-by"]',
sharedVia: '[data-testid="shared-via"]',
sharingInfo: '[data-testid="sharingInfo"]',
sizeInfo: '[data-testid="sizeInfo"]',
tags: '[data-testid="tags"]',
timestamp: '[data-testid="timestamp"]',
versionsInfo: '[data-testid="versionsInfo"]'
}
describe('Details SideBar Panel', () => {
describe('preview', () => {
it('shows if given for files', () => {
const resource = getResourceMock({ thumbnail: 'example.com/image' })
const { wrapper } = createWrapper({ resource })
expect(wrapper.find(selectors.preview).exists()).toBeTruthy()
expect(wrapper.find(selectors.resourceIcon).exists()).toBeFalsy()
})
it('shows resource icon instead if the resource is a folder', () => {
const resource = getResourceMock({ type: 'folder' })
const { wrapper } = createWrapper({ resource })
expect(wrapper.find(selectors.preview).exists()).toBeFalsy()
expect(wrapper.find(selectors.resourceIcon).exists()).toBeTruthy()
})
})
describe('status indicators', () => {
it('show if given on non-public page', () => {
const resource = getResourceMock({ shareTypes: [ShareTypes.user.value] })
const { wrapper } = createWrapper({ resource })
expect(wrapper.find(selectors.sharingInfo).exists()).toBeTruthy()
})
it('do not show on a public page', () => {
const resource = getResourceMock({ shareTypes: [ShareTypes.user.value] })
const { wrapper } = createWrapper({ resource, isPublicLinkContext: true })
expect(wrapper.find(selectors.sharingInfo).exists()).toBeFalsy()
})
})
describe('timestamp', () => {
it('shows if given', () => {
const resource = getResourceMock()
const { wrapper } = createWrapper({ resource })
expect(wrapper.find(selectors.timestamp).exists()).toBeTruthy()
})
})
describe('shared via', () => {
it('shows if the resource has an indirect share', () => {
const resource = getResourceMock()
const ancestorMetaData = {
'/somePath': { path: '/somePath', shareTypes: [ShareTypes.user.value] }
}
const { wrapper } = createWrapper({ resource, ancestorMetaData })
expect(wrapper.find(selectors.sharedVia).exists()).toBeTruthy()
})
})
describe('shared by', () => {
it('shows if the resource is a share from another user', () => {
const share = { fileOwner: { displayName: 'Marie' } }
const resource = getResourceMock({ shareTypes: [ShareTypes.user.value], share })
const { wrapper } = createWrapper({ resource, user: { id: 'einstein' } })
expect(wrapper.find(selectors.sharedBy).exists()).toBeTruthy()
})
})
describe('owner display name', () => {
it('shows if given', () => {
const resource = getResourceMock()
const { wrapper } = createWrapper({ resource })
expect(wrapper.find(selectors.ownerDisplayName).exists()).toBeTruthy()
})
})
describe('size', () => {
it('shows if given', () => {
const resource = getResourceMock()
const { wrapper } = createWrapper({ resource })
expect(wrapper.find(selectors.sizeInfo).exists()).toBeTruthy()
})
})
describe('versions', () => {
it('show if given for files on a private page', () => {
const resource = getResourceMock()
const { wrapper } = createWrapper({ resource, versions: ['1'] })
expect(wrapper.find(selectors.versionsInfo).exists()).toBeTruthy()
})
it('do not show for folders on a private page', () => {
const resource = getResourceMock({ type: 'folder' })
const { wrapper } = createWrapper({ resource, versions: ['1'] })
expect(wrapper.find(selectors.versionsInfo).exists()).toBeFalsy()
})
it('do not show on public pages', () => {
const resource = getResourceMock()
const { wrapper } = createWrapper({ resource, versions: ['1'], isPublicLinkContext: true })
expect(wrapper.find(selectors.versionsInfo).exists()).toBeFalsy()
})
})
describe('running on EOS', () => {
it('shows eos path and direct link', () => {
const resource = getResourceMock()
const { wrapper } = createWrapper({ resource, runningOnEos: true })
expect(wrapper.find(selectors.eosPath).exists()).toBeTruthy()
expect(wrapper.find(selectors.eosDirectLink).exists()).toBeTruthy()
})
})
describe('CERN features', () => {
it('show samba link', () => {
const resource = getResourceMock({ path: '/eos/user/t/test/123.png' })
const { wrapper } = createWrapper({ resource, cernFeatures: true })
expect(wrapper.find(selectors.sambaPath).exists()).toBeTruthy()
})
})
describe('tags', () => {
it('show if given', () => {
const resource = getResourceMock({ tags: ['moon', 'mars'] })
const { wrapper } = createWrapper({ resource })
expect(wrapper.find(selectors.tags).exists()).toBeTruthy()
})
it('should use router-link on private page', () => {
const resource = getResourceMock({ tags: ['moon', 'mars'] })
const { wrapper } = createWrapper({ resource })
expect(wrapper.find(selectors.tags).find('router-link-stub').exists()).toBeTruthy()
})
it('should not use router-link on public page', () => {
const resource = getResourceMock({ tags: ['moon', 'mars'] })
const { wrapper } = createWrapper({ resource, isPublicLinkContext: true })
expect(wrapper.find(selectors.tags).find('router-link-stub').exists()).toBeFalsy()
})
})
})
function createWrapper({
resource = null,
runningOnEos = false,
cernFeatures = false,
isPublicLinkContext = false,
ancestorMetaData = {},
user = { id: 'marie' },
versions = []
} = {}) {
const storeOptions = defaultStoreMockOptions
storeOptions.getters.user.mockReturnValue(user)
storeOptions.getters.configuration.mockReturnValue({ options: { runningOnEos, cernFeatures } })
storeOptions.modules.Files.getters.versions.mockReturnValue(versions)
storeOptions.getters.capabilities.mockReturnValue({ files: { tags: true } })
storeOptions.modules.Files.getters.ancestorMetaData.mockReturnValue(ancestorMetaData)
storeOptions.modules.runtime.modules.auth.getters.isPublicLinkContextReady.mockReturnValue(
isPublicLinkContext
)
const store = createStore(storeOptions)
return {
wrapper: shallowMount(FileDetails, {
global: {
stubs: { 'router-link': true, 'oc-resource-icon': true },
provide: {
resource,
space: mockDeep<SpaceResource>()
},
plugins: [...defaultPlugins(), store],
mocks: { ...defaultComponentMocks() }
}
})
}
}