Skip to content

Commit

Permalink
test: add test for marks on nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
nperez0111 committed Nov 22, 2024
1 parent d6c99ab commit 6a5ea81
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/y-prosemirror.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { findWrapping } from 'prosemirror-transform'
import { schema as complexSchema } from './complexSchema.js'
import * as promise from 'lib0/promise'

const schema = /** @type {any} */ (basicSchema.schema)
const schema = /** @type {import('prosemirror-model').Schema} */ (basicSchema.schema)

/**
* Verify that update events in plugins are only fired once.
Expand Down Expand Up @@ -452,6 +452,30 @@ export const testAddToHistoryIgnore = (_tc) => {
)
}

/**
* @param {t.TestCase} tc
*/
export const testMarksOnNodes = (_tc) => {
const view = createNewProsemirrorView(new Y.Doc())
view.dispatch(
view.state.tr.insert(
0,
/** @type {any} */ (schema.node('image', { src: 'http://example.com', alt: null, title: null }, [], [schema.mark('link', { href: 'https://yjs.dev', title: null })]))
)
)
// convert to JSON and back because the ProseMirror schema messes with the constructors
const stateJSON = JSON.parse(JSON.stringify(view.state.doc.toJSON()))
// test if transforming back and forth from Yjs doc works
const backandforth = JSON.parse(JSON.stringify(yDocToProsemirrorJSON(
prosemirrorJSONToYDoc(/** @type {any} */ (schema), stateJSON)
)))
// Add the missing alt and title attributes, these are defaults for the image mark
backandforth.content[0].content[0].attrs.alt = null
backandforth.content[0].content[0].attrs.title = null

t.compare(stateJSON, backandforth, 'marks on nodes are preserved')
}

const createNewProsemirrorViewWithSchema = (y, schema, undoManager = false) => {
const view = new EditorView(null, {
// @ts-ignore
Expand Down

0 comments on commit 6a5ea81

Please sign in to comment.