-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
index.spec.js
219 lines (186 loc) · 6.46 KB
/
index.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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
describe('quill-magic-url', () => {
beforeEach(() => {
cy.visit('http://localhost:8080')
cy.get('.ql-editor').as('editor')
})
function type(text) {
cy.get('@editor').type(text)
}
function paste(text) {
cy.window().then((win) => {
win.quill.clipboard.dangerouslyPasteHTML(text)
})
}
function shouldContain(text) {
cy.get('@editor').should('contain.html', text)
}
function shouldContainLink(url, text) {
const editor = cy.get('@editor')
editor.should('contain.html', `<a href="${url}"`)
editor.should('contain.html', `${text ? text : url}</a>`)
}
describe('typing', () => {
it('triggered by blank space', () => {
type('http://test.de ')
shouldContainLink('http://test.de')
})
it('triggered by enter', () => {
type('http://test.de{enter}')
shouldContainLink('http://test.de')
})
it('triggered by tab', () => {
type('http://test.de\t')
shouldContainLink('http://test.de')
})
it('triggered by blur', () => {
type('http://test.de')
cy.get('@editor').blur()
shouldContainLink('http://test.de')
})
it('does not throw on blur when empty', () => {
cy.get('@editor').focus()
cy.get('@editor').blur()
shouldContain('<p><br></p>')
})
it('for multiple urls', () => {
type('http://test.de https://google.de ')
shouldContainLink('http://test.de')
shouldContainLink('https://google.de')
})
it('normalizes url', () => {
type('www.test.de ')
shouldContainLink('http://www.test.de', 'www.test.de')
})
it('for email address', () => {
type('test@test.de ')
shouldContainLink('mailto:test@test.de', 'test@test.de')
})
it('for urls and email addresses', () => {
type('http://test.de test@test.de https://google.de www.test.de ')
shouldContainLink('http://test.de')
shouldContainLink('mailto:test@test.de', 'test@test.de')
shouldContainLink('https://google.de')
shouldContainLink('http://www.test.de', 'www.test.de')
})
it('preserves normal text', () => {
type(
'i want to be preserved http://test.de my little pony www.google.com look a mail peter@google.com bam!'
)
shouldContain(
'<p>i want to be preserved <a href="http://test.de" target="_blank">http://test.de</a> my little pony <a href="http://www.google.com" target="_blank">www.google.com</a> look a mail <a href="mailto:peter@google.com" target="_blank">peter@google.com</a> bam!</p>'
)
})
describe('does not trigger', () => {
beforeEach(() => {
type('http://test.de {leftarrow}{leftarrow}')
cy.get('.ql-remove').click()
cy.get('@editor').click('bottomRight')
})
it('on double blank space', () => {
type(' ')
shouldContain('<p>http://test.de </p>')
})
it('on new word in same line', () => {
type(' new ')
shouldContain('<p>http://test.de new </p>')
})
it('on blank space and enter', () => {
type('{enter}')
shouldContain('<p>http://test.de </p><p><br></p>')
})
it('on blank space in new line', () => {
type('{enter}next ')
shouldContain('<p>http://test.de </p><p>next </p>')
})
it('on blank space after blur', () => {
cy.get('@editor').blur()
shouldContain('<p>http://test.de </p>')
})
})
describe('converts first url', () => {
beforeEach(() => {
type('http://test.de {leftarrow}{leftarrow}')
cy.get('.ql-remove').click()
cy.get('@editor').click('bottomRight')
type('www.google.com')
// Move to end of first url
type(`{movetostart}${'{rightarrow}'.repeat(14)}`)
})
it('on blank space', () => {
type(' ')
shouldContain(
'<p><a href="http://test.de" target="_blank">http://test.de</a> www.google.com</p>'
)
})
it('on enter', () => {
type('{enter}')
shouldContain(
'<p><a href="http://test.de" target="_blank">http://test.de</a></p><p> www.google.com</p>'
)
})
it('on blur', () => {
cy.get('@editor').blur()
shouldContain(
'<p><a href="http://test.de" target="_blank">http://test.de</a> www.google.com</p>'
)
})
})
describe('converts second url', () => {
beforeEach(() => {
type('http://test.de {leftarrow}{leftarrow}')
cy.get('.ql-remove').click()
cy.get('@editor').click('bottomRight')
type('www.google.com')
})
it('on blank space', () => {
type(' ')
shouldContain(
'<p>http://test.de <a href="http://www.google.com" target="_blank">www.google.com</a> </p>'
)
})
it('on enter', () => {
type('{enter}')
shouldContain(
'<p>http://test.de <a href="http://www.google.com" target="_blank">www.google.com</a></p><p><br></p>'
)
})
it('on blur', () => {
cy.get('@editor').blur()
shouldContain(
'<p>http://test.de <a href="http://www.google.com" target="_blank">www.google.com</a></p>'
)
})
})
})
describe('paste', () => {
it('for single url', () => {
paste('http://test.de')
shouldContainLink('http://test.de')
})
it('for email address', () => {
paste('test@test.de')
shouldContainLink('mailto:test@test.de', 'test@test.de')
})
it('for multiple urls', () => {
paste('http://test.de https://google.de www.test.de')
shouldContainLink('http://test.de')
shouldContainLink('https://google.de')
shouldContainLink('http://www.test.de', 'www.test.de')
})
it('for urls and email addresses', () => {
paste('http://test.de test@test.de https://google.de www.test.de')
shouldContainLink('http://test.de')
shouldContainLink('mailto:test@test.de', 'test@test.de')
shouldContainLink('https://google.de')
shouldContainLink('http://www.test.de', 'www.test.de')
})
it('preserves normal text', () => {
paste(
'i want to be preserved http://test.de my little pony www.google.com look a mail peter@google.com bam!'
)
shouldContain(
'i want to be preserved <a href="http://test.de" target="_blank">http://test.de</a> my little pony <a href="http://www.google.com" target="_blank">www.google.com</a> look a mail <a href="mailto:peter@google.com" target="_blank">peter@google.com</a> bam!'
)
})
})
})