mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-25 16:20:49 +02:00
Adapt existing tests
This commit is contained in:
@@ -2,14 +2,11 @@
|
|||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
|
|
||||||
export default function (state) {
|
export default function (state) {
|
||||||
const { document, selection } = state
|
const { selection } = state
|
||||||
const texts = document.getTexts()
|
|
||||||
let first = texts.first()
|
|
||||||
const second = texts.last()
|
|
||||||
const range = selection.merge({
|
const range = selection.merge({
|
||||||
anchorKey: first.key,
|
anchorKey: 'anchor',
|
||||||
anchorOffset: 2,
|
anchorOffset: 1,
|
||||||
focusKey: second.key,
|
focusKey: 'focus',
|
||||||
focusOffset: 2
|
focusOffset: 2
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -19,15 +16,18 @@ export default function (state) {
|
|||||||
.unwrapInline('hashtag')
|
.unwrapInline('hashtag')
|
||||||
.apply()
|
.apply()
|
||||||
|
|
||||||
// Selection is reset, in theory it should me on the image
|
// Test selection
|
||||||
first = next.document.getTexts().first()
|
const { document } = next
|
||||||
|
const first = document.getTexts().first()
|
||||||
|
const last = document.getTexts().last()
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
next.selection.toJS(),
|
next.selection.toJS(),
|
||||||
range.merge({
|
range.merge({
|
||||||
anchorKey: first.key,
|
anchorKey: first.key,
|
||||||
anchorOffset: 0,
|
anchorOffset: 1,
|
||||||
focusKey: first.key,
|
focusKey: last.key,
|
||||||
focusOffset: 0
|
focusOffset: 4
|
||||||
}).toJS()
|
}).toJS()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@ nodes:
|
|||||||
type: paragraph
|
type: paragraph
|
||||||
nodes:
|
nodes:
|
||||||
- kind: text
|
- kind: text
|
||||||
|
key: 'anchor' # w[o
|
||||||
text: wo
|
text: wo
|
||||||
- kind: inline
|
- kind: inline
|
||||||
type: hashtag
|
type: hashtag
|
||||||
@@ -19,4 +20,5 @@ nodes:
|
|||||||
- kind: text
|
- kind: text
|
||||||
text: an
|
text: an
|
||||||
- kind: text
|
- kind: text
|
||||||
|
key: 'focus' # ot]her
|
||||||
text: other
|
text: other
|
||||||
|
@@ -10,3 +10,5 @@ nodes:
|
|||||||
nodes:
|
nodes:
|
||||||
- kind: text
|
- kind: text
|
||||||
text: another
|
text: another
|
||||||
|
# Selection
|
||||||
|
# w[ordanot]her
|
@@ -2,14 +2,11 @@
|
|||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
|
|
||||||
export default function (state) {
|
export default function (state) {
|
||||||
const { document, selection } = state
|
const { selection } = state
|
||||||
const texts = document.getTexts()
|
|
||||||
const first = texts.first()
|
|
||||||
const last = texts.get(1)
|
|
||||||
const range = selection.merge({
|
const range = selection.merge({
|
||||||
anchorKey: first.key,
|
anchorKey: 'anchor',
|
||||||
anchorOffset: 1,
|
anchorOffset: 1,
|
||||||
focusKey: last.key,
|
focusKey: 'focus',
|
||||||
focusOffset: 2
|
focusOffset: 2
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -21,7 +18,10 @@ export default function (state) {
|
|||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
next.selection.toJS(),
|
next.selection.toJS(),
|
||||||
range.collapseToStartOf(next.document).toJS()
|
range.merge({
|
||||||
|
focusKey: 'anchor',
|
||||||
|
focusOffset: 3
|
||||||
|
}).toJS()
|
||||||
)
|
)
|
||||||
|
|
||||||
return next
|
return next
|
||||||
|
@@ -7,11 +7,15 @@ nodes:
|
|||||||
type: paragraph
|
type: paragraph
|
||||||
nodes:
|
nodes:
|
||||||
- kind: text
|
- kind: text
|
||||||
|
key: 'anchor'
|
||||||
text: w
|
text: w
|
||||||
- kind: inline
|
- kind: inline
|
||||||
type: hashtag
|
type: hashtag
|
||||||
nodes:
|
nodes:
|
||||||
- kind: text
|
- kind: text
|
||||||
|
key: 'focus'
|
||||||
text: or
|
text: or
|
||||||
- kind: text
|
- kind: text
|
||||||
text: d
|
text: d
|
||||||
|
# Selection
|
||||||
|
# w[or]d
|
@@ -2,14 +2,11 @@
|
|||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
|
|
||||||
export default function (state) {
|
export default function (state) {
|
||||||
const { document, selection } = state
|
const { selection } = state
|
||||||
const texts = document.getTexts()
|
|
||||||
const first = texts.get(2)
|
|
||||||
const last = texts.get(3)
|
|
||||||
const range = selection.merge({
|
const range = selection.merge({
|
||||||
anchorKey: first.key,
|
anchorKey: 'anchor',
|
||||||
anchorOffset: 2,
|
anchorOffset: 2,
|
||||||
focusKey: last.key,
|
focusKey: 'focus',
|
||||||
focusOffset: 2
|
focusOffset: 2
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -21,7 +18,10 @@ export default function (state) {
|
|||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
next.selection.toJS(),
|
next.selection.toJS(),
|
||||||
range.collapseToStartOf(next.document).toJS()
|
range.merge({
|
||||||
|
focusKey: 'anchor',
|
||||||
|
focusOffset: 5
|
||||||
|
}).toJS()
|
||||||
)
|
)
|
||||||
|
|
||||||
return next
|
return next
|
||||||
|
@@ -11,11 +11,16 @@ nodes:
|
|||||||
- kind: text
|
- kind: text
|
||||||
text: ll
|
text: ll
|
||||||
- kind: text
|
- kind: text
|
||||||
|
key: 'anchor'
|
||||||
text: "o w"
|
text: "o w"
|
||||||
- kind: inline
|
- kind: inline
|
||||||
type: hashtag
|
type: hashtag
|
||||||
nodes:
|
nodes:
|
||||||
- kind: text
|
- kind: text
|
||||||
|
key: 'focus'
|
||||||
text: or
|
text: or
|
||||||
- kind: text
|
- kind: text
|
||||||
text: d
|
text: d
|
||||||
|
|
||||||
|
# Selection
|
||||||
|
# hello [wor]d
|
@@ -12,3 +12,5 @@ nodes:
|
|||||||
text: ll
|
text: ll
|
||||||
- kind: text
|
- kind: text
|
||||||
text: "o word"
|
text: "o word"
|
||||||
|
# Selection
|
||||||
|
# hello [wor]d
|
@@ -2,14 +2,11 @@
|
|||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
|
|
||||||
export default function (state) {
|
export default function (state) {
|
||||||
const { document, selection } = state
|
const { selection } = state
|
||||||
const texts = document.getTexts()
|
|
||||||
const first = texts.first()
|
|
||||||
const last = texts.get(1)
|
|
||||||
const range = selection.merge({
|
const range = selection.merge({
|
||||||
anchorKey: first.key,
|
anchorKey: 'anchor',
|
||||||
anchorOffset: 1,
|
anchorOffset: 1,
|
||||||
focusKey: last.key,
|
focusKey: 'focus',
|
||||||
focusOffset: 2
|
focusOffset: 2
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -21,7 +18,10 @@ export default function (state) {
|
|||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
next.selection.toJS(),
|
next.selection.toJS(),
|
||||||
range.collapseToStartOf(next.document).toJS()
|
range.merge({
|
||||||
|
focusKey: 'anchor',
|
||||||
|
focusOffset: 3
|
||||||
|
}).toJS()
|
||||||
)
|
)
|
||||||
|
|
||||||
return next
|
return next
|
||||||
|
@@ -4,11 +4,16 @@ nodes:
|
|||||||
type: paragraph
|
type: paragraph
|
||||||
nodes:
|
nodes:
|
||||||
- kind: text
|
- kind: text
|
||||||
|
key: 'anchor'
|
||||||
text: w
|
text: w
|
||||||
- kind: inline
|
- kind: inline
|
||||||
type: hashtag
|
type: hashtag
|
||||||
nodes:
|
nodes:
|
||||||
- kind: text
|
- kind: text
|
||||||
|
key: 'focus'
|
||||||
text: or
|
text: or
|
||||||
- kind: text
|
- kind: text
|
||||||
text: d
|
text: d
|
||||||
|
|
||||||
|
# selection:
|
||||||
|
# w[or]d
|
Reference in New Issue
Block a user