mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-24 04:35:35 +08:00
93 lines
2.4 KiB
JavaScript
93 lines
2.4 KiB
JavaScript
context('/api/extensions/code-block', () => {
|
|
before(() => {
|
|
cy.visit('/api/extensions/code-block')
|
|
})
|
|
|
|
beforeEach(() => {
|
|
cy.get('.ProseMirror').then(([{ editor }]) => {
|
|
editor.setContent('<p>Example Text</p>')
|
|
editor.selectAll()
|
|
})
|
|
})
|
|
|
|
it('the button should make the selected line a code block', () => {
|
|
cy.get('.demo__preview button:first')
|
|
.click()
|
|
|
|
cy.get('.ProseMirror')
|
|
.find('pre')
|
|
.should('contain', 'Example Text')
|
|
})
|
|
|
|
it('the button should toggle the code block', () => {
|
|
cy.get('.demo__preview button:first')
|
|
.click()
|
|
|
|
cy.get('.ProseMirror')
|
|
.find('pre')
|
|
.should('contain', 'Example Text')
|
|
|
|
cy.get('.ProseMirror')
|
|
.type('{selectall}')
|
|
|
|
cy.get('.demo__preview button:first')
|
|
.click()
|
|
|
|
cy.get('.ProseMirror pre')
|
|
.should('not.exist')
|
|
})
|
|
|
|
it('the keyboard shortcut should make the selected line a code block', () => {
|
|
cy.get('.ProseMirror')
|
|
.trigger('keydown', { shiftKey: true, ctrlKey: true, key: '\\' })
|
|
.find('pre')
|
|
.should('contain', 'Example Text')
|
|
})
|
|
|
|
it('the keyboard shortcut should toggle the code block', () => {
|
|
cy.get('.ProseMirror')
|
|
.trigger('keydown', { shiftKey: true, ctrlKey: true, key: '\\' })
|
|
.find('pre')
|
|
.should('contain', 'Example Text')
|
|
|
|
cy.get('.ProseMirror')
|
|
.type('{selectall}')
|
|
.trigger('keydown', { shiftKey: true, ctrlKey: true, key: '\\' })
|
|
|
|
cy.get('.ProseMirror pre')
|
|
.should('not.exist')
|
|
})
|
|
|
|
it('should make a code block from markdown shortcuts', () => {
|
|
cy.get('.ProseMirror').then(([{ editor }]) => {
|
|
editor.clearContent()
|
|
|
|
cy.get('.ProseMirror')
|
|
.type('``` Code')
|
|
.find('pre>code')
|
|
.should('contain', 'Code')
|
|
})
|
|
})
|
|
|
|
it('should parse the language from a HTML code block', () => {
|
|
cy.get('.ProseMirror').then(([{ editor }]) => {
|
|
editor.setContent('<pre><code class="language-css">body { display: none; }</code></pre>')
|
|
|
|
cy.get('.ProseMirror')
|
|
.find('pre>code.language-css')
|
|
.should('have.length', 1)
|
|
})
|
|
})
|
|
|
|
it('should make a code block for js', () => {
|
|
cy.get('.ProseMirror').then(([{ editor }]) => {
|
|
editor.clearContent()
|
|
|
|
cy.get('.ProseMirror')
|
|
.type('```js Code')
|
|
.find('pre>code.language-js')
|
|
.should('contain', 'Code')
|
|
})
|
|
})
|
|
})
|