add paste command to cypress, test the link pasterule for a few domains

This commit is contained in:
Hans Pagel
2020-09-25 21:54:19 +02:00
parent f0e42e1858
commit 4a508fbf2b
2 changed files with 45 additions and 8 deletions

View File

@@ -70,3 +70,26 @@ Cypress.Commands.overwrite('click', (originalFn, element, text, options) => {
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
},
)