add more tests
This commit is contained in:
@@ -1,15 +1,68 @@
|
|||||||
context('Basic', () => {
|
context('basic', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cy.visit('/tests/basic')
|
cy.visit('/tests/basic')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('export', () => {
|
||||||
|
it('should return html', () => {
|
||||||
|
cy.get('.ProseMirror').window().then(window => {
|
||||||
|
const { editor } = window
|
||||||
|
const html = editor.html()
|
||||||
|
|
||||||
|
expect(html).to.equal('<p>foo</p>')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return json', () => {
|
||||||
|
cy.get('.ProseMirror').window().then(window => {
|
||||||
|
const { editor } = window
|
||||||
|
const json = editor.json()
|
||||||
|
|
||||||
|
expect(json).to.deep.equal({
|
||||||
|
type: 'doc',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'paragraph',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text: 'foo'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('insertText', () => {
|
describe('insertText', () => {
|
||||||
it('should prepend text', () => {
|
it('should prepend text', () => {
|
||||||
cy.get('.ProseMirror').should('contain', 'foo')
|
cy.get('.ProseMirror').window().then(window => {
|
||||||
|
const { editor } = window
|
||||||
|
|
||||||
cy.window().then(win => {
|
editor.insertText('bar')
|
||||||
win.editor.insertText('bar')
|
cy.get('.ProseMirror p:first').should('contain', 'barfoo')
|
||||||
cy.get('.ProseMirror').should('contain', 'barfoo')
|
//.contains('barfoo')
|
||||||
|
// .should('contain', 'barfoo')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should append text', () => {
|
||||||
|
cy.get('.ProseMirror').window().then(window => {
|
||||||
|
const { editor } = window
|
||||||
|
|
||||||
|
editor.focus('end').insertText('bar')
|
||||||
|
cy.get('.ProseMirror p:first').should('contain', 'foobar')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should append html', () => {
|
||||||
|
cy.get('.ProseMirror').window().then(window => {
|
||||||
|
const { editor } = window
|
||||||
|
|
||||||
|
editor.focus('end').insertHTML('<p>bar</p>')
|
||||||
|
cy.get('.ProseMirror p:first').should('contain', 'foobar')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
"build:docs": "gridsome build",
|
"build:docs": "gridsome build",
|
||||||
"build:packages": "yarn clean:packages && lerna exec --parallel -- microbundle --raw --compress",
|
"build:packages": "yarn clean:packages && lerna exec --parallel -- microbundle --raw --compress",
|
||||||
"clean:packages": "rm -rf ./packages/*/dist",
|
"clean:packages": "rm -rf ./packages/*/dist",
|
||||||
"test:debug": "cypress start",
|
"test:debug": "cypress open",
|
||||||
"test": "cypress run",
|
"test": "cypress run",
|
||||||
"startandtest": "start-server-and-test start http://localhost:3000 test"
|
"startandtest": "start-server-and-test start http://localhost:3000 test"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {EditorState, Plugin} from "prosemirror-state"
|
import {EditorState, Plugin} from "prosemirror-state"
|
||||||
import {EditorView} from "prosemirror-view"
|
import {EditorView} from "prosemirror-view"
|
||||||
import {Schema, DOMParser} from "prosemirror-model"
|
import {Schema, DOMParser, DOMSerializer} from "prosemirror-model"
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import {schema} from "prosemirror-schema-basic"
|
import {schema} from "prosemirror-schema-basic"
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -134,4 +134,19 @@ export class Editor {
|
|||||||
return this[name](...args)
|
return this[name](...args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public json() {
|
||||||
|
return this.state.doc.toJSON()
|
||||||
|
}
|
||||||
|
|
||||||
|
public html() {
|
||||||
|
const div = document.createElement('div')
|
||||||
|
const fragment = DOMSerializer
|
||||||
|
.fromSchema(this.schema)
|
||||||
|
.serializeFragment(this.state.doc.content)
|
||||||
|
|
||||||
|
div.appendChild(fragment)
|
||||||
|
|
||||||
|
return div.innerHTML
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ function resolveSelection(editor: Editor, position: Position = null): ResolvedSe
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
from: size,
|
from: size,
|
||||||
to: size,
|
to: size - 1, // TODO: -1 only for nodes with content
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user