mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-31 19:01:54 +02:00
add selection assertions to addMark tests
This commit is contained in:
@@ -1,18 +1,25 @@
|
||||
|
||||
import assert from 'assert'
|
||||
|
||||
export default function (state) {
|
||||
const { document, selection } = state
|
||||
const texts = document.getTexts()
|
||||
const first = texts.first()
|
||||
const second = texts.last()
|
||||
const range = selection.merge({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 2,
|
||||
focusKey: second.key,
|
||||
focusOffset: 2
|
||||
})
|
||||
|
||||
return state
|
||||
const next = state
|
||||
.transform()
|
||||
.moveTo({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 2,
|
||||
focusKey: second.key,
|
||||
focusOffset: 2
|
||||
})
|
||||
.moveTo(range)
|
||||
.addMark('bold')
|
||||
.apply()
|
||||
|
||||
assert.deepEqual(next.selection.toJS(), range.toJS())
|
||||
|
||||
return next
|
||||
}
|
||||
|
@@ -1,20 +1,28 @@
|
||||
|
||||
import assert from 'assert'
|
||||
|
||||
export default function (state) {
|
||||
const { document, selection } = state
|
||||
const texts = document.getTexts()
|
||||
const first = texts.first()
|
||||
const range = selection.merge({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 0,
|
||||
focusKey: first.key,
|
||||
focusOffset: 0
|
||||
})
|
||||
|
||||
return state
|
||||
const next = state
|
||||
.transform()
|
||||
.moveTo({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 0,
|
||||
focusKey: first.key,
|
||||
focusOffset: 0
|
||||
})
|
||||
.addMark('bold')
|
||||
.insertText('a')
|
||||
.removeMark('bold')
|
||||
.insertText('b')
|
||||
.apply()
|
||||
|
||||
assert.deepEqual(next.selection.toJS(), range.moveForward().moveForward().toJS())
|
||||
|
||||
return next
|
||||
}
|
||||
|
@@ -1,18 +1,25 @@
|
||||
|
||||
import assert from 'assert'
|
||||
|
||||
export default function (state) {
|
||||
const { document, selection } = state
|
||||
const texts = document.getTexts()
|
||||
const first = texts.first()
|
||||
const range = selection.merge({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 0,
|
||||
focusKey: first.key,
|
||||
focusOffset: 0
|
||||
})
|
||||
|
||||
return state
|
||||
const next = state
|
||||
.transform()
|
||||
.moveTo({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 0,
|
||||
focusKey: first.key,
|
||||
focusOffset: 0
|
||||
})
|
||||
.moveTo(range)
|
||||
.addMark('bold')
|
||||
.insertText('a')
|
||||
.apply()
|
||||
|
||||
assert.deepEqual(next.selection.toJS(), range.moveForward().toJS())
|
||||
|
||||
return next
|
||||
}
|
||||
|
@@ -1,17 +1,24 @@
|
||||
|
||||
import assert from 'assert'
|
||||
|
||||
export default function (state) {
|
||||
const { document, selection } = state
|
||||
const texts = document.getTexts()
|
||||
const first = texts.first()
|
||||
const range = selection.merge({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 0,
|
||||
focusKey: first.key,
|
||||
focusOffset: 2
|
||||
})
|
||||
|
||||
return state
|
||||
const next = state
|
||||
.transform()
|
||||
.moveTo({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 0,
|
||||
focusKey: first.key,
|
||||
focusOffset: 2
|
||||
})
|
||||
.moveTo(range)
|
||||
.addMark('bold')
|
||||
.apply()
|
||||
|
||||
assert.deepEqual(next.selection.toJS(), range.toJS())
|
||||
|
||||
return next
|
||||
}
|
||||
|
@@ -1,17 +1,24 @@
|
||||
|
||||
import assert from 'assert'
|
||||
|
||||
export default function (state) {
|
||||
const { document, selection } = state
|
||||
const texts = document.getTexts()
|
||||
const first = texts.first()
|
||||
const range = selection.merge({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 0,
|
||||
focusKey: first.key,
|
||||
focusOffset: 1
|
||||
})
|
||||
|
||||
return state
|
||||
const next = state
|
||||
.transform()
|
||||
.moveTo({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 0,
|
||||
focusKey: first.key,
|
||||
focusOffset: 1
|
||||
})
|
||||
.moveTo(range)
|
||||
.addMark('bold')
|
||||
.apply()
|
||||
|
||||
assert.deepEqual(next.selection.toJS(), range.toJS())
|
||||
|
||||
return next
|
||||
}
|
||||
|
@@ -1,17 +1,24 @@
|
||||
|
||||
import assert from 'assert'
|
||||
|
||||
export default function (state) {
|
||||
const { document, selection } = state
|
||||
const texts = document.getTexts()
|
||||
const first = texts.first()
|
||||
const range = selection.merge({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: first.length - 1,
|
||||
focusKey: first.key,
|
||||
focusOffset: first.length
|
||||
})
|
||||
|
||||
return state
|
||||
const next = state
|
||||
.transform()
|
||||
.moveTo({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: first.length - 1,
|
||||
focusKey: first.key,
|
||||
focusOffset: first.length
|
||||
})
|
||||
.moveTo(range)
|
||||
.addMark('bold')
|
||||
.apply()
|
||||
|
||||
assert.deepEqual(next.selection.toJS(), range.toJS())
|
||||
|
||||
return next
|
||||
}
|
||||
|
@@ -1,17 +1,24 @@
|
||||
|
||||
import assert from 'assert'
|
||||
|
||||
export default function (state) {
|
||||
const { document, selection } = state
|
||||
const texts = document.getTexts()
|
||||
const first = texts.first()
|
||||
const range = selection.merge({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 1,
|
||||
focusKey: first.key,
|
||||
focusOffset: 2
|
||||
})
|
||||
|
||||
return state
|
||||
const next = state
|
||||
.transform()
|
||||
.moveTo({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 1,
|
||||
focusKey: first.key,
|
||||
focusOffset: 2
|
||||
})
|
||||
.moveTo(range)
|
||||
.addMark('bold')
|
||||
.apply()
|
||||
|
||||
assert.deepEqual(next.selection.toJS(), range.toJS())
|
||||
|
||||
return next
|
||||
}
|
||||
|
@@ -1,17 +1,24 @@
|
||||
|
||||
import assert from 'assert'
|
||||
|
||||
export default function (state) {
|
||||
const { document, selection } = state
|
||||
const texts = document.getTexts()
|
||||
const first = texts.first()
|
||||
const range = selection.merge({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 0,
|
||||
focusKey: first.key,
|
||||
focusOffset: first.length
|
||||
})
|
||||
|
||||
return state
|
||||
const next = state
|
||||
.transform()
|
||||
.moveTo({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 0,
|
||||
focusKey: first.key,
|
||||
focusOffset: first.length
|
||||
})
|
||||
.moveTo(range)
|
||||
.addMark('bold')
|
||||
.apply()
|
||||
|
||||
assert.deepEqual(next.selection.toJS(), range.toJS())
|
||||
|
||||
return next
|
||||
}
|
||||
|
@@ -1,22 +1,28 @@
|
||||
|
||||
import { Mark } from '../../../../..'
|
||||
import assert from 'assert'
|
||||
|
||||
export default function (state) {
|
||||
const { document, selection } = state
|
||||
const texts = document.getTexts()
|
||||
const first = texts.first()
|
||||
const range = selection.merge({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 0,
|
||||
focusKey: first.key,
|
||||
focusOffset: 1
|
||||
})
|
||||
|
||||
return state
|
||||
const next = state
|
||||
.transform()
|
||||
.moveTo({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 0,
|
||||
focusKey: first.key,
|
||||
focusOffset: 1
|
||||
})
|
||||
.moveTo(range)
|
||||
.addMark(Mark.create({
|
||||
type: 'bold',
|
||||
data: { key: 'value' }
|
||||
}))
|
||||
.apply()
|
||||
|
||||
assert.deepEqual(next.selection.toJS(), range.toJS())
|
||||
|
||||
return next
|
||||
}
|
||||
|
@@ -1,20 +1,27 @@
|
||||
|
||||
import assert from 'assert'
|
||||
|
||||
export default function (state) {
|
||||
const { document, selection } = state
|
||||
const texts = document.getTexts()
|
||||
const first = texts.first()
|
||||
const range = selection.merge({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 0,
|
||||
focusKey: first.key,
|
||||
focusOffset: 1
|
||||
})
|
||||
|
||||
return state
|
||||
const next = state
|
||||
.transform()
|
||||
.moveTo({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 0,
|
||||
focusKey: first.key,
|
||||
focusOffset: 1
|
||||
})
|
||||
.moveTo(range)
|
||||
.addMark({
|
||||
type: 'bold',
|
||||
data: { key: 'value' }
|
||||
})
|
||||
.apply()
|
||||
|
||||
assert.deepEqual(next.selection.toJS(), range.toJS())
|
||||
|
||||
return next
|
||||
}
|
||||
|
Reference in New Issue
Block a user