Skip to content

Commit 4c6c536

Browse files
committed
test: for button to remove icon
Also test for it being hidden when in read only mode. Signed-off-by: Max <[email protected]>
1 parent 822ce26 commit 4c6c536

1 file changed

Lines changed: 26 additions & 9 deletions

File tree

src/tests/nodes/ImageView.spec.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,60 @@ global.OC = {
1010

1111
describe('Image View src attribute based on markdown', () => {
1212

13-
const factory = attrs => {
13+
const factory = (attrs, options = {}) => {
1414
const propsData = {
15-
extension: { options: {currentDirectory: '/current'} },
16-
editor: { isEditable: true },
17-
node: {attrs}
15+
extension: { options: { currentDirectory: '/current' } },
16+
editor: { isEditable: options.isEditable ?? true },
17+
node: { attrs },
18+
deleteNode: options.deleteNode ?? function() {},
1819
}
1920
const data = () => ({
2021
imageLoaded: true,
2122
loaded: true,
2223
failed: false,
24+
showIcons: true,
2325
})
2426
return shallowMount(ImageView, {propsData, data})
2527
}
2628

2729
test('old style is used as is', () => {
2830
const src = '/core/preview?fileId=123#mimetype=image%2Fjpeg'
29-
const wrapper = factory({src})
31+
const wrapper = factory({ src })
3032
expect(wrapper.find('.image__main').attributes('src')).toBe(src)
3133
})
3234

35+
test('has button to remove image', () => {
36+
const deleteNode = jest.fn()
37+
const src = '/core/preview?fileId=123#mimetype=image%2Fjpeg'
38+
const wrapper = factory({ src }, { deleteNode })
39+
wrapper.find('.image .trash-icon').trigger('click')
40+
expect(deleteNode).toHaveBeenCalled()
41+
})
42+
43+
test('no button to remove image when not editable', () => {
44+
const src = '/core/preview?fileId=123#mimetype=image%2Fjpeg'
45+
const wrapper = factory({ src }, { isEditable: false })
46+
expect(wrapper.find('.image__main').attributes('src')).toBe(src)
47+
expect(wrapper.find('.image .trash-icon').exists()).toBeFalsy()
48+
})
49+
3350
test('old style with index.php is used as is', () => {
3451
const src = '/index.php/core/preview?fileId=9&x=1024&y=1024&a=true#mimetype=image%2Fjpeg&hasPreview=true&fileId=9'
35-
const wrapper = factory({src})
52+
const wrapper = factory({ src })
3653
expect(wrapper.find('.image__main').attributes('src')).toBe(src)
3754
})
3855

3956
test('fileId is used for preview url', () => {
4057
const src = '/Media/photo.jpeg?fileId=7#mimetype=image%2Fjpeg&hasPreview=true'
41-
const wrapper = factory({src})
58+
const wrapper = factory({ src })
4259
expect(wrapper.vm.fileId).toBe('7')
4360
expect(wrapper.find('.image__main').attributes('src'))
4461
.toContain('/core/preview?fileId=7')
4562
})
4663

4764
test('use dav paths for gifs so they are animated', () => {
4865
const src = '/Media/giffy.gif?fileId=7#mimetype=image%2Fgif&hasPreview=true'
49-
const wrapper = factory({src})
66+
const wrapper = factory({ src })
5067
expect(wrapper.vm.extension.options.currentDirectory).toBe('/current')
5168
expect(wrapper.find('.image__main').attributes('src'))
5269
.toContain("remote.php/dav/files/user1/current/Media/giffy.gif")
@@ -68,7 +85,7 @@ describe('Image View src attribute based on markdown', () => {
6885

6986
test('data urls are used as is', () => {
7087
const src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII='
71-
const wrapper = factory({src})
88+
const wrapper = factory({ src })
7289
expect(wrapper.find('.image__main').attributes('src')).toBe(src)
7390
})
7491

0 commit comments

Comments
 (0)