1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-19 13:41:19 +02:00

Add test to joinNodeByKey

This commit is contained in:
Soreine
2016-10-26 14:26:55 +02:00
parent 7e5f0b4779
commit 947513fc58
6 changed files with 111 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import assert from 'assert'
export default function (state) {
const { selection } = state
const range = selection.merge({
anchorKey: 'anchor',
anchorOffset: 1,
focusKey: 'focus',
focusOffset: 2
})
const next = state
.transform()
.moveTo(range)
.joinNodeByKey('key2', 'key1')
.apply()
assert.deepEqual(
next.selection.toJS(),
range.merge({
focusKey: 'anchor',
focusOffset: 5
}).toJS()
)
return next
}

View File

@@ -0,0 +1,16 @@
nodes:
- kind: block
key: 'key1'
type: paragraph
nodes:
- kind: text
key: 'anchor'
text: The
- kind: block
key: 'key2'
type: paragraph
nodes:
- kind: text
key: 'focus'
text: text

View File

@@ -0,0 +1,8 @@
nodes:
- kind: block
key: key1
type: paragraph
nodes:
- kind: text
text: Thetext

View File

@@ -0,0 +1,29 @@
import assert from 'assert'
export default function (state) {
const { selection } = state
const range = selection.merge({
anchorKey: 'anchor',
anchorOffset: 1,
focusKey: 'focus',
focusOffset: 2
})
const next = state
.transform()
.moveTo(range)
.joinNodeByKey('focus', 'anchor')
.apply()
assert.deepEqual(
next.selection.toJS(),
range.merge({
focusKey: 'anchor',
focusOffset: 5
}).toJS()
)
return next
}

View File

@@ -0,0 +1,16 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
key: 'anchor'
text: one
- kind: inline
type: link
nodes:
- kind: text
text: two
- kind: text
key: 'focus'
text: three

View File

@@ -0,0 +1,13 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
key: 'anchor'
text: onethree
- kind: inline
type: link
nodes:
- kind: text
text: two