add paste command to cypress, test the link pasterule for a few domains
This commit is contained in:
@@ -24,13 +24,27 @@ context('/api/extensions/link', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it.skip('links should be auto detected', () => {
|
const validUrls = [
|
||||||
cy.get('.ProseMirror')
|
'https://example.com',
|
||||||
.then($span => {
|
'https://example.com/with-path',
|
||||||
$span.text('https://example.com')
|
'http://example.com/with-http',
|
||||||
})
|
'https://www.example.com/with-www',
|
||||||
|
'https://www.example.com/with-numbers-123',
|
||||||
|
'https://www.example.com/with-parameters?var=true',
|
||||||
|
'https://www.example.com/with-multiple-parameters?var=true&foo=bar',
|
||||||
|
'https://www.example.com/with-spaces?var=true&foo=bar+3',
|
||||||
|
// TODO: 'https://www.example.com/with,comma',
|
||||||
|
'http://thelongestdomainnameintheworldandthensomeandthensomemoreandmore.com/',
|
||||||
|
'https://example.longtopleveldomain',
|
||||||
|
'https://example-with-dashes.com',
|
||||||
|
]
|
||||||
|
|
||||||
|
validUrls.forEach(url => {
|
||||||
|
it(`url should be detected: ${url}`, () => {
|
||||||
|
cy.get('.ProseMirror').paste({ pastePayload: url, pasteType: 'text/plain' })
|
||||||
.find('a')
|
.find('a')
|
||||||
.should('contain', 'https://example.com')
|
.should('contain', url)
|
||||||
.should('have.attr', 'href', 'https://example.com')
|
.should('have.attr', 'href', url)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -70,3 +70,26 @@ Cypress.Commands.overwrite('click', (originalFn, element, text, options) => {
|
|||||||
|
|
||||||
return originalFn(element, text, newOptions)
|
return originalFn(element, text, newOptions)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Cypress.Commands.add(
|
||||||
|
'paste',
|
||||||
|
{ prevSubject: true },
|
||||||
|
(subject, pasteOptions) => {
|
||||||
|
const { pastePayload, pasteType } = pasteOptions
|
||||||
|
const data = pasteType === 'application/json' ? JSON.stringify(pastePayload) : pastePayload
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer
|
||||||
|
const clipboardData = new DataTransfer()
|
||||||
|
clipboardData.setData(pasteType, data)
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/Element/paste_event
|
||||||
|
const pasteEvent = new ClipboardEvent('paste', {
|
||||||
|
bubbles: true,
|
||||||
|
cancelable: true,
|
||||||
|
dataType: pasteType,
|
||||||
|
data,
|
||||||
|
clipboardData,
|
||||||
|
})
|
||||||
|
subject[0].dispatchEvent(pasteEvent)
|
||||||
|
|
||||||
|
return subject
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user