/
ImageView.spec.js
146 lines (111 loc) Β· 3.97 KB
/
ImageView.spec.js
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
import { randUser } from '../../utils/index.js'
const user = randUser()
describe('Image View', () => {
before(() => {
cy.createUser(user)
cy.login(user)
// Upload test files to user's storage
cy.createFolder('child-folder')
cy.uploadFile('github.png', 'image/png')
cy.uploadFile('github.png', 'image/png', 'child-folder/github.png')
})
beforeEach(() => {
cy.login(user)
cy.visit('/apps/files')
})
describe('direct access', () => {
it('from root', () => {
const fileName = `${Cypress.currentTest.title}.md`
cy.createMarkdown(fileName, '# from root\n\n ![git](/github.png)')
cy.openFile(fileName)
cy.getContent()
.find('[data-component="image-view"]')
.should('have.attr', 'data-src')
.should('eq', '/github.png')
cy.getContent()
.find('[data-component="image-view"] img')
.should('have.attr', 'src')
.should('contains', `/dav/files/${user.userId}/github.png`)
})
it('from child folder', () => {
const fileName = `${Cypress.currentTest.title}.md`
cy.createMarkdown(fileName, '# from child\n\n ![git](child-folder/github.png)')
cy.openFile(fileName)
cy.getContent()
.find('[data-component="image-view"]')
.should('have.attr', 'data-src')
.should('eq', 'child-folder/github.png')
cy.getContent()
.find('[data-component="image-view"] img')
.should('have.attr', 'src')
.should('contains', `/dav/files/${user.userId}/child-folder/github.png`)
})
it('from parent folder', () => {
cy.visit('apps/files?dir=/child-folder')
const fileName = `${Cypress.currentTest.title}.md`
cy.createMarkdown(`/child-folder/${fileName}`, '# from parent\n\n ![git](../github.png)')
cy.openFile(fileName, { force: true })
cy.getContent()
.find('[data-component="image-view"]')
.should('have.attr', 'data-src')
.should('eq', '../github.png')
cy.getContent()
.find('[data-component="image-view"] img')
.should('have.attr', 'src')
.should('contain', `/dav/files/${user.userId}/github.png`)
})
})
describe('fail to load', () => {
it('direct access', () => {
const fileName = `${Cypress.currentTest.title}.md`
cy.createMarkdown(fileName, '# from root\n\n ![yaha](/yaha.png)')
cy.openFile(fileName)
cy.getContent()
.find('[data-component="image-view"]')
.should('have.class', 'image-view--failed')
cy.getContent()
.find('[data-component="image-view"] svg')
.should('be.visible')
cy.getContent()
.find('[data-component="image-view"] .image__error-message')
.should('be.visible')
cy.getContent()
.find('[data-component="image-view"] .image__caption input')
.should('have.value', 'yaha')
})
})
describe('native attachments', () => {
before(() => {
cy.login(user)
cy.visit('/apps/files')
const fileName = 'native attachments.md'
cy.createMarkdown(fileName, '# open image in modal\n\n ![git](.attachments.123/github.png)\n\n ![file.txt.gz](.attachments.123/file.txt.gz)')
cy.getFileId(fileName).then((fileId) => {
const attachmentsFolder = `.attachments.${fileId}`
cy.createFolder(attachmentsFolder)
cy.uploadFile('github.png', 'image/png', `${attachmentsFolder}/github.png`)
cy.uploadFile('file.txt.gz', 'application/gzip', `${attachmentsFolder}/file.txt.gz`)
})
})
it('open image in modal', () => {
const fileName = 'native attachments.md'
cy.openFile(fileName)
cy.getContent()
.find('[data-component="image-view"][data-src=".attachments.123/github.png"] img')
.click()
cy.get('.modal__content img')
.should('have.attr', 'src')
.should('contain', 'imageFileName=github.png')
})
it('download non-image gzip attachment', () => {
const fileName = 'native attachments.md'
cy.openFile(fileName)
cy.getContent()
.find('[data-component="image-view"][data-src=".attachments.123/file.txt.gz"] img')
.click()
const downloadsFolder = Cypress.config('downloadsFolder')
cy.log(`downloadsFolder: ${downloadsFolder}`)
cy.readFile(`${downloadsFolder}/file.txt.gz`)
})
})
})