mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 03:39:01 +08:00
fix shortcuts
This commit is contained in:
parent
c7af0b6782
commit
7afcb0250e
@ -28,17 +28,17 @@ context('/api/extensions/blockquote', () => {
|
||||
})
|
||||
|
||||
it('the keyboard shortcut should make the selected line a blockquote', () => {
|
||||
cy.get('.ProseMirror').trigger('keydown', { shiftKey: true, metaKey: true, key: '9' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { shiftKey: true, modKey: true, key: '9' })
|
||||
cy.get('.ProseMirror').find('blockquote').should('contain', 'Example Text')
|
||||
})
|
||||
|
||||
it('the keyboard shortcut should toggle the blockquote', () => {
|
||||
cy.get('.ProseMirror blockquote').should('not.exist')
|
||||
cy.get('.ProseMirror').trigger('keydown', { shiftKey: true, metaKey: true, key: '9' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { shiftKey: true, modKey: true, key: '9' })
|
||||
cy.get('.ProseMirror').find('blockquote').should('contain', 'Example Text')
|
||||
|
||||
cy.get('.ProseMirror').type('{selectall}', { force: true })
|
||||
cy.get('.ProseMirror').trigger('keydown', { shiftKey: true, metaKey: true, key: '9' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { shiftKey: true, modKey: true, key: '9' })
|
||||
cy.get('.ProseMirror blockquote').should('not.exist')
|
||||
})
|
||||
|
||||
|
@ -25,19 +25,19 @@ context('/api/extensions/bold', () => {
|
||||
|
||||
it('the keyboard shortcut should make the selected text bold', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.trigger('keydown', { metaKey: true, key: 'b' })
|
||||
.trigger('keydown', { modKey: true, key: 'b' })
|
||||
.find('strong')
|
||||
.should('contain', 'Example Text')
|
||||
})
|
||||
|
||||
it('the keyboard shortcut should toggle the selected text bold', () => {
|
||||
cy.get('.ProseMirror')
|
||||
.trigger('keydown', { metaKey: true, key: 'b' })
|
||||
.trigger('keydown', { modKey: true, key: 'b' })
|
||||
.find('strong')
|
||||
.should('contain', 'Example Text')
|
||||
|
||||
cy.get('.ProseMirror')
|
||||
.trigger('keydown', { metaKey: true, key: 'b' })
|
||||
.trigger('keydown', { modKey: true, key: 'b' })
|
||||
|
||||
cy.get('.ProseMirror strong').should('not.exist')
|
||||
})
|
||||
|
@ -18,13 +18,13 @@ context('/api/extensions/hard-break', () => {
|
||||
|
||||
it('the default keyboard shortcut should add a line break', () => {
|
||||
cy.get('.ProseMirror br').should('not.exist')
|
||||
cy.get('.ProseMirror').trigger('keydown', { metaKey: true, shiftKey: true, key: 'Enter' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { shiftKey: true, key: 'Enter' })
|
||||
cy.get('.ProseMirror br').should('exist')
|
||||
})
|
||||
|
||||
it('the alternative keyboard shortcut should add a line break', () => {
|
||||
cy.get('.ProseMirror br').should('not.exist')
|
||||
cy.get('.ProseMirror').trigger('keydown', { metaKey: true, key: 'Enter' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'Enter' })
|
||||
cy.get('.ProseMirror br').should('exist')
|
||||
})
|
||||
})
|
@ -17,7 +17,7 @@ context('/api/extensions/history', () => {
|
||||
})
|
||||
|
||||
it('the keyboard shortcut should make the last change undone', () => {
|
||||
cy.get('.ProseMirror').trigger('keydown', { metaKey: true, key: 'z' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'z' })
|
||||
cy.get('.ProseMirror').should('not.contain', 'Mistake')
|
||||
})
|
||||
|
||||
@ -30,10 +30,10 @@ context('/api/extensions/history', () => {
|
||||
})
|
||||
|
||||
it.skip('the keyboard shortcut should apply the last undone change again', () => {
|
||||
cy.get('.ProseMirror').trigger('keydown', { metaKey: true, key: 'z' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'z' })
|
||||
cy.get('.ProseMirror').should('not.contain', 'Mistake')
|
||||
|
||||
cy.get('.ProseMirror').trigger('keydown', { metaKey: true, shiftKey: true, key: 'z' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { modKey: true, shiftKey: true, key: 'z' })
|
||||
cy.get('.ProseMirror').should('contain', 'Mistake')
|
||||
})
|
||||
})
|
||||
|
@ -24,13 +24,13 @@ context('/api/extensions/italic', () => {
|
||||
})
|
||||
|
||||
it('the keyboard shortcut should make the selected text italic', () => {
|
||||
cy.get('.ProseMirror').trigger('keydown', { metaKey: true, key: 'i' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'i' })
|
||||
cy.get('.ProseMirror').find('em').should('contain', 'Example Text')
|
||||
})
|
||||
|
||||
it('the keyboard shortcut should toggle the selected text italic', () => {
|
||||
cy.get('.ProseMirror').trigger('keydown', { metaKey: true, key: 'i' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { metaKey: true, key: 'i' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'i' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'i' })
|
||||
cy.get('.ProseMirror em').should('not.exist')
|
||||
})
|
||||
})
|
@ -24,13 +24,13 @@ context('/api/extensions/strike', () => {
|
||||
})
|
||||
|
||||
it('the keyboard shortcut should strike the selected text', () => {
|
||||
cy.get('.ProseMirror').trigger('keydown', { metaKey: true, key: 'd' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'd' })
|
||||
cy.get('.ProseMirror').find('s').should('contain', 'Example Text')
|
||||
})
|
||||
|
||||
it('the keyboard shortcut should toggle the selected text striked', () => {
|
||||
cy.get('.ProseMirror').trigger('keydown', { metaKey: true, key: 'd' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { metaKey: true, key: 'd' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'd' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'd' })
|
||||
cy.get('.ProseMirror s').should('not.exist')
|
||||
})
|
||||
|
||||
|
@ -24,13 +24,13 @@ context('/api/extensions/underline', () => {
|
||||
})
|
||||
|
||||
it('the keyboard shortcut should underline the selected text', () => {
|
||||
cy.get('.ProseMirror').trigger('keydown', { metaKey: true, key: 'u' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'u' })
|
||||
cy.get('.ProseMirror').find('u').should('contain', 'Example Text')
|
||||
})
|
||||
|
||||
it('the keyboard shortcut should toggle the selected text underline', () => {
|
||||
cy.get('.ProseMirror').trigger('keydown', { metaKey: true, key: 'u' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { metaKey: true, key: 'u' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'u' })
|
||||
cy.get('.ProseMirror').trigger('keydown', { modKey: true, key: 'u' })
|
||||
cy.get('.ProseMirror u').should('not.exist')
|
||||
})
|
||||
})
|
@ -23,3 +23,21 @@
|
||||
//
|
||||
// -- This will overwrite an existing command --
|
||||
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
|
||||
|
||||
Cypress.Commands.overwrite('trigger', (originalFn, element, text, options) => {
|
||||
if (text === 'keydown') {
|
||||
const isMac = Cypress.platform === 'darwin'
|
||||
const { modKey, ...rest } = options
|
||||
|
||||
if (modKey) {
|
||||
const newOptions = {
|
||||
...rest,
|
||||
...(isMac ? { metaKey: modKey } : { ctrlKey: modKey }),
|
||||
}
|
||||
|
||||
return originalFn(element, text, newOptions)
|
||||
}
|
||||
}
|
||||
|
||||
return originalFn(element, text, options)
|
||||
})
|
Loading…
Reference in New Issue
Block a user