defaults to force: true for type and click
This commit is contained in:
@@ -11,91 +11,91 @@ context('/examples/markdown-shortcuts', () => {
|
||||
|
||||
it('should make a h1', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('# Headline', { force: true })
|
||||
.type('# Headline')
|
||||
.find('h1')
|
||||
.should('contain', 'Headline')
|
||||
})
|
||||
|
||||
it('should make a h2', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('## Headline', { force: true })
|
||||
.type('## Headline')
|
||||
.find('h2')
|
||||
.should('contain', 'Headline')
|
||||
})
|
||||
|
||||
it('should make a h3', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('### Headline', { force: true })
|
||||
.type('### Headline')
|
||||
.find('h3')
|
||||
.should('contain', 'Headline')
|
||||
})
|
||||
|
||||
it('should make a h4', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('#### Headline', { force: true })
|
||||
.type('#### Headline')
|
||||
.find('h4')
|
||||
.should('contain', 'Headline')
|
||||
})
|
||||
|
||||
it('should make a h5', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('##### Headline', { force: true })
|
||||
.type('##### Headline')
|
||||
.find('h5')
|
||||
.should('contain', 'Headline')
|
||||
})
|
||||
|
||||
it('should make a h6', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('###### Headline', { force: true })
|
||||
.type('###### Headline')
|
||||
.find('h6')
|
||||
.should('contain', 'Headline')
|
||||
})
|
||||
|
||||
it('should create inline code', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('`$foobar`', { force: true })
|
||||
.type('`$foobar`')
|
||||
.find('code')
|
||||
.should('contain', '$foobar')
|
||||
})
|
||||
|
||||
it.skip('should create a code block without language', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('``` {enter}const foo = bar{enter}```', { force: true })
|
||||
.type('``` {enter}const foo = bar{enter}```')
|
||||
.find('pre')
|
||||
.should('contain', 'const foo = bar')
|
||||
})
|
||||
|
||||
it.skip('should create a bullet list from asteriks', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('* foobar', { force: true })
|
||||
.type('* foobar')
|
||||
.find('ul')
|
||||
.should('contain', 'foobar')
|
||||
})
|
||||
|
||||
it.skip('should create a bullet list from dashes', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('- foobar', { force: true })
|
||||
.type('- foobar')
|
||||
.find('ul')
|
||||
.should('contain', 'foobar')
|
||||
})
|
||||
|
||||
it.skip('should create a bullet list from pluses', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('+ foobar', { force: true })
|
||||
.type('+ foobar')
|
||||
.find('ul')
|
||||
.should('contain', 'foobar')
|
||||
})
|
||||
|
||||
it.skip('should create a ordered list', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('1. foobar', { force: true })
|
||||
.type('1. foobar')
|
||||
.find('ol')
|
||||
.should('contain', 'foobar')
|
||||
})
|
||||
|
||||
it.skip('should create a blockquote', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('> foobar', { force: true })
|
||||
.type('> foobar')
|
||||
.find('blockquote')
|
||||
.should('contain', 'foobar')
|
||||
})
|
||||
|
||||
@@ -15,7 +15,7 @@ context('/api/extensions/blockquote', () => {
|
||||
.should('not.exist')
|
||||
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.find('blockquote')
|
||||
@@ -27,17 +27,17 @@ context('/api/extensions/blockquote', () => {
|
||||
.should('not.exist')
|
||||
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.find('blockquote')
|
||||
.should('contain', 'Example Text')
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.type('{selectall}', { force: true })
|
||||
.type('{selectall}')
|
||||
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror blockquote')
|
||||
.should('not.exist')
|
||||
@@ -60,7 +60,7 @@ context('/api/extensions/blockquote', () => {
|
||||
.should('contain', 'Example Text')
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.type('{selectall}', { force: true })
|
||||
.type('{selectall}')
|
||||
.trigger('keydown', { shiftKey: true, modKey: true, key: '9' })
|
||||
|
||||
cy.get('.ProseMirror blockquote')
|
||||
@@ -69,7 +69,7 @@ context('/api/extensions/blockquote', () => {
|
||||
|
||||
it('should make a blockquote from markdown shortcuts', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('> Quote', { force: true })
|
||||
.type('> Quote')
|
||||
.find('blockquote')
|
||||
.should('contain', 'Quote')
|
||||
})
|
||||
|
||||
@@ -11,16 +11,18 @@ context('/api/extensions/bold', () => {
|
||||
})
|
||||
|
||||
it('the button should make the selected text bold', () => {
|
||||
cy.get('.demo__preview button:first').click({ force: true })
|
||||
cy.get('.demo__preview button:first')
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.find('strong')
|
||||
.should('contain', 'Example Text')
|
||||
})
|
||||
|
||||
it('the button should toggle the selected text bold', () => {
|
||||
cy.get('.demo__preview button:first').click({ force: true })
|
||||
cy.get('.ProseMirror').type('{selectall}', { force: true })
|
||||
cy.get('.demo__preview button:first').click({ force: true })
|
||||
cy.get('.demo__preview button:first').click()
|
||||
cy.get('.ProseMirror').type('{selectall}')
|
||||
cy.get('.demo__preview button:first').click()
|
||||
cy.get('.ProseMirror strong').should('not.exist')
|
||||
})
|
||||
|
||||
@@ -45,14 +47,14 @@ context('/api/extensions/bold', () => {
|
||||
|
||||
it('should make a bold text from the default markdown shortcut', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('**Bold**', { force: true })
|
||||
.type('**Bold**')
|
||||
.find('strong')
|
||||
.should('contain', 'Bold')
|
||||
})
|
||||
|
||||
it('should make a bold text from the alternative markdown shortcut', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('__Bold__', { force: true })
|
||||
.type('__Bold__')
|
||||
.find('strong')
|
||||
.should('contain', 'Bold')
|
||||
})
|
||||
|
||||
@@ -12,7 +12,7 @@ context('/api/extensions/code', () => {
|
||||
|
||||
it('should mark the selected text as inline code', () => {
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.find('code')
|
||||
@@ -21,13 +21,13 @@ context('/api/extensions/code', () => {
|
||||
|
||||
it('should toggle the selected text as inline code', () => {
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.type('{selectall}', { force: true })
|
||||
.type('{selectall}')
|
||||
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror code')
|
||||
.should('not.exist')
|
||||
|
||||
@@ -12,7 +12,7 @@ context('/api/extensions/code-block', () => {
|
||||
|
||||
it('the button should make the selected line a code block', () => {
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.find('pre')
|
||||
@@ -21,17 +21,17 @@ context('/api/extensions/code-block', () => {
|
||||
|
||||
it('the button should toggle the code block', () => {
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.find('pre')
|
||||
.should('contain', 'Example Text')
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.type('{selectall}', { force: true })
|
||||
.type('{selectall}')
|
||||
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror pre')
|
||||
.should('not.exist')
|
||||
@@ -51,7 +51,7 @@ context('/api/extensions/code-block', () => {
|
||||
.should('contain', 'Example Text')
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.type('{selectall}', { force: true })
|
||||
.type('{selectall}')
|
||||
.trigger('keydown', { shiftKey: true, ctrlKey: true, key: '\\' })
|
||||
|
||||
cy.get('.ProseMirror pre')
|
||||
@@ -60,7 +60,7 @@ context('/api/extensions/code-block', () => {
|
||||
|
||||
it('should make a code block from markdown shortcuts', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('``` {enter}Code', { force: true })
|
||||
.type('``` {enter}Code')
|
||||
.find('pre')
|
||||
.should('contain', 'Code')
|
||||
})
|
||||
|
||||
@@ -14,7 +14,7 @@ context('/api/extensions/hard-break', () => {
|
||||
.should('not.exist')
|
||||
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror br')
|
||||
.should('exist')
|
||||
|
||||
@@ -15,7 +15,7 @@ context('/api/extensions/heading', () => {
|
||||
.should('not.exist')
|
||||
|
||||
cy.get('.demo__preview button:nth-child(1)')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.find('h1')
|
||||
@@ -27,7 +27,7 @@ context('/api/extensions/heading', () => {
|
||||
.should('not.exist')
|
||||
|
||||
cy.get('.demo__preview button:nth-child(2)')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.find('h2')
|
||||
@@ -39,7 +39,7 @@ context('/api/extensions/heading', () => {
|
||||
.should('not.exist')
|
||||
|
||||
cy.get('.demo__preview button:nth-child(3)')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.find('h3')
|
||||
|
||||
@@ -14,7 +14,7 @@ context('/api/extensions/history', () => {
|
||||
.should('contain', 'Mistake')
|
||||
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.should('not.contain', 'Mistake')
|
||||
@@ -31,13 +31,13 @@ context('/api/extensions/history', () => {
|
||||
.should('contain', 'Mistake')
|
||||
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.should('not.contain', 'Mistake')
|
||||
|
||||
cy.get('.demo__preview button:nth-child(2)')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.should('contain', 'Mistake')
|
||||
|
||||
@@ -14,7 +14,7 @@ context('/api/extensions/horizontal-rule', () => {
|
||||
.should('not.exist')
|
||||
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror hr')
|
||||
.should('exist')
|
||||
@@ -28,7 +28,7 @@ context('/api/extensions/horizontal-rule', () => {
|
||||
.should('not.exist')
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.type('---', { force: true })
|
||||
.type('---')
|
||||
|
||||
cy.get('.ProseMirror hr')
|
||||
.should('exist')
|
||||
@@ -43,7 +43,7 @@ context('/api/extensions/horizontal-rule', () => {
|
||||
.should('not.exist')
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.type('___ ', { force: true })
|
||||
.type('___ ')
|
||||
|
||||
cy.get('.ProseMirror hr')
|
||||
.should('exist')
|
||||
|
||||
@@ -12,7 +12,7 @@ context('/api/extensions/italic', () => {
|
||||
|
||||
it('the button should make the selected text italic', () => {
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.find('em')
|
||||
@@ -21,13 +21,13 @@ context('/api/extensions/italic', () => {
|
||||
|
||||
it('the button should toggle the selected text italic', () => {
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.type('{selectall}', { force: true })
|
||||
.type('{selectall}')
|
||||
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror em')
|
||||
.should('not.exist')
|
||||
|
||||
@@ -11,14 +11,14 @@ context('/api/extensions/paragraph', () => {
|
||||
|
||||
it('text should be wrapped in a paragraph by default', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('Example Text', { force: true })
|
||||
.type('Example Text')
|
||||
.find('p')
|
||||
.should('contain', 'Example Text')
|
||||
})
|
||||
|
||||
it('enter should make a new paragraph', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('First Paragraph{enter}Second Paragraph', { force: true })
|
||||
.type('First Paragraph{enter}Second Paragraph')
|
||||
.find('p')
|
||||
.should('have.length', 2)
|
||||
|
||||
@@ -33,12 +33,12 @@ context('/api/extensions/paragraph', () => {
|
||||
|
||||
it('backspace should remove the second paragraph', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('{enter}', { force: true })
|
||||
.type('{enter}')
|
||||
.find('p')
|
||||
.should('have.length', 2)
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.type('{backspace}', { force: true })
|
||||
.type('{backspace}')
|
||||
.find('p')
|
||||
.should('have.length', 1)
|
||||
})
|
||||
|
||||
@@ -12,7 +12,7 @@ context('/api/extensions/strike', () => {
|
||||
|
||||
it('the button should strike the selected text', () => {
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.find('s')
|
||||
@@ -21,13 +21,13 @@ context('/api/extensions/strike', () => {
|
||||
|
||||
it('the button should toggle the selected text striked', () => {
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.type('{selectall}', { force: true })
|
||||
.type('{selectall}')
|
||||
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.find('s')
|
||||
@@ -51,7 +51,7 @@ context('/api/extensions/strike', () => {
|
||||
|
||||
it('should make a striked text from the markdown shortcut', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.type('~Strike~', { force: true })
|
||||
.type('~Strike~')
|
||||
.find('s')
|
||||
.should('contain', 'Strike')
|
||||
})
|
||||
|
||||
@@ -12,7 +12,7 @@ context('/api/extensions/underline', () => {
|
||||
|
||||
it('the button should underline the selected text', () => {
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.find('u')
|
||||
@@ -21,13 +21,13 @@ context('/api/extensions/underline', () => {
|
||||
|
||||
it('the button should toggle the selected text underline', () => {
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.type('{selectall}', { force: true })
|
||||
.type('{selectall}')
|
||||
|
||||
cy.get('.demo__preview button:first')
|
||||
.click({ force: true })
|
||||
.click()
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.find('u')
|
||||
|
||||
@@ -24,6 +24,23 @@
|
||||
// -- This will overwrite an existing command --
|
||||
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
|
||||
|
||||
function defaults(object, name, value) {
|
||||
if (!object) {
|
||||
return {
|
||||
[name]: value,
|
||||
}
|
||||
}
|
||||
|
||||
if (object[name] === undefined) {
|
||||
return {
|
||||
...object,
|
||||
[name]: value,
|
||||
}
|
||||
}
|
||||
|
||||
return object
|
||||
}
|
||||
|
||||
Cypress.Commands.overwrite('trigger', (originalFn, element, text, options) => {
|
||||
if (text === 'keydown') {
|
||||
const isMac = Cypress.platform === 'darwin'
|
||||
@@ -31,7 +48,7 @@ Cypress.Commands.overwrite('trigger', (originalFn, element, text, options) => {
|
||||
|
||||
if (modKey) {
|
||||
const newOptions = {
|
||||
...rest,
|
||||
...defaults(rest, 'force', true),
|
||||
...(isMac ? { metaKey: modKey } : { ctrlKey: modKey }),
|
||||
}
|
||||
|
||||
@@ -40,4 +57,16 @@ Cypress.Commands.overwrite('trigger', (originalFn, element, text, options) => {
|
||||
}
|
||||
|
||||
return originalFn(element, text, options)
|
||||
})
|
||||
|
||||
Cypress.Commands.overwrite('type', (originalFn, element, text, options) => {
|
||||
const newOptions = defaults(options, 'force', true)
|
||||
|
||||
return originalFn(element, text, newOptions)
|
||||
})
|
||||
|
||||
Cypress.Commands.overwrite('click', (originalFn, element, text, options) => {
|
||||
const newOptions = defaults(options, 'force', true)
|
||||
|
||||
return originalFn(element, text, newOptions)
|
||||
})
|
||||
Reference in New Issue
Block a user