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
|
import { shallowMount } from '@vue/test-utils'
import ImageView from '../../nodes/ImageView.vue'
global.FileList = {
getCurrentDirectory: function() {return '/current'},
}
global.OC = {
requestToken: '123',
config: {modRewriteWorking: true},
MimeType: {getIconUrl: mime => mime},
webroot: ''
}
describe('Image View src attribute based on markdown', () => {
const factory = attrs => {
const propsData = {
node: {attrs}
}
const data = () => ({
imageLoaded: true,
loaded: true,
failed: false,
})
return shallowMount(ImageView, {propsData, data})
}
test('old style is used as is', () => {
const src = '/core/preview?fileId=123#mimetype=image%2Fjpeg'
const wrapper = factory({src})
expect(wrapper.find('.image__main').attributes('src')).toBe(src)
})
test('old style with index.php is used as is', () => {
const src = '/index.php/core/preview?fileId=9&x=1024&y=1024&a=true#mimetype=image%2Fjpeg&hasPreview=true&fileId=9'
const wrapper = factory({src})
expect(wrapper.find('.image__main').attributes('src')).toBe(src)
})
test('fileId is used for preview url', () => {
const wrapper = factory({src: '/Media/photo-1498855592392-af2bf1e0a4c7.jpeg?fileId=7#mimetype=image%2Fjpeg&hasPreview=true'})
expect(wrapper.vm.fileId).toBe('7')
expect(wrapper.find('.image__main').attributes('src'))
.toBe('/core/preview?fileId=7&x=1024&y=1024&a=true')
})
test('without fileId relative path is used in file based preview url', () => {
const wrapper = factory({src: 'sub/asdf.jpg'})
expect(wrapper.vm.isSupportedImage).toBe(true)
expect(wrapper.find('.image__main').attributes('src'))
.toBe('/core/preview.png?file=%2Fcurrent%2Fsub%2Fasdf.jpg&x=1024&y=1024&a=true')
})
test('public share link previews are just used as they are', () => {
const wrapper = factory({src: 'https://nextcloud/index.php/apps/files_sharing/publicpreview/CSYoWifBzrsMWeA?file=/deck11-calendar.png&x=1760&y=990&a=true'})
expect(wrapper.vm.isSupportedImage).toBe(true)
expect(wrapper.find('.image__main').attributes('src'))
.toBe('https://nextcloud/index.php/apps/files_sharing/publicpreview/CSYoWifBzrsMWeA?file=/deck11-calendar.png&x=1760&y=990&a=true')
})
})
|