Skip to content

Commit cbfd93a

Browse files
committed
test: add test for marks on nodes
1 parent c9dc701 commit cbfd93a

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

tests/y-prosemirror.test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { findWrapping } from 'prosemirror-transform'
2323
import { schema as complexSchema } from './complexSchema.js'
2424
import * as promise from 'lib0/promise'
2525

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

2828
/**
2929
* Verify that update events in plugins are only fired once.
@@ -452,6 +452,30 @@ export const testAddToHistoryIgnore = (_tc) => {
452452
)
453453
}
454454

455+
/**
456+
* @param {t.TestCase} tc
457+
*/
458+
export const testMarksOnNodes = (_tc) => {
459+
const view = createNewProsemirrorView(new Y.Doc())
460+
view.dispatch(
461+
view.state.tr.insert(
462+
0,
463+
/** @type {any} */ (schema.node('image', { src: 'http://example.com', alt: null, title: null }, [], [schema.mark('link', { href: 'https://yjs.dev', title: null })]))
464+
)
465+
)
466+
// convert to JSON and back because the ProseMirror schema messes with the constructors
467+
const stateJSON = JSON.parse(JSON.stringify(view.state.doc.toJSON()))
468+
// test if transforming back and forth from Yjs doc works
469+
const backandforth = JSON.parse(JSON.stringify(yDocToProsemirrorJSON(
470+
prosemirrorJSONToYDoc(/** @type {any} */ (schema), stateJSON)
471+
)))
472+
// Add the missing alt and title attributes, these are defaults for the image mark
473+
backandforth.content[0].content[0].attrs.alt = null
474+
backandforth.content[0].content[0].attrs.title = null
475+
476+
t.compare(stateJSON, backandforth, 'marks on nodes are preserved')
477+
}
478+
455479
const createNewProsemirrorViewWithSchema = (y, schema, undoManager = false) => {
456480
const view = new EditorView(null, {
457481
// @ts-ignore

0 commit comments

Comments
 (0)