1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-31 10:51:44 +02:00

add selection assertions to addMark tests

This commit is contained in:
Ian Storm Taylor
2016-07-21 12:17:12 -07:00
parent 054aaf419f
commit 4197921946
10 changed files with 138 additions and 68 deletions

View File

@@ -1,18 +1,25 @@
import assert from 'assert'
export default function (state) { export default function (state) {
const { document, selection } = state const { document, selection } = state
const texts = document.getTexts() const texts = document.getTexts()
const first = texts.first() const first = texts.first()
const second = texts.last() const second = texts.last()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 2,
focusKey: second.key,
focusOffset: 2
})
return state const next = state
.transform() .transform()
.moveTo({ .moveTo(range)
anchorKey: first.key,
anchorOffset: 2,
focusKey: second.key,
focusOffset: 2
})
.addMark('bold') .addMark('bold')
.apply() .apply()
assert.deepEqual(next.selection.toJS(), range.toJS())
return next
} }

View File

@@ -1,20 +1,28 @@
import assert from 'assert'
export default function (state) { export default function (state) {
const { document, selection } = state const { document, selection } = state
const texts = document.getTexts() const texts = document.getTexts()
const first = texts.first() const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 0
})
return state const next = state
.transform() .transform()
.moveTo({ .moveTo({
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 0
}) })
.addMark('bold') .addMark('bold')
.insertText('a') .insertText('a')
.removeMark('bold') .removeMark('bold')
.insertText('b') .insertText('b')
.apply() .apply()
assert.deepEqual(next.selection.toJS(), range.moveForward().moveForward().toJS())
return next
} }

View File

@@ -1,18 +1,25 @@
import assert from 'assert'
export default function (state) { export default function (state) {
const { document, selection } = state const { document, selection } = state
const texts = document.getTexts() const texts = document.getTexts()
const first = texts.first() const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 0
})
return state const next = state
.transform() .transform()
.moveTo({ .moveTo(range)
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 0
})
.addMark('bold') .addMark('bold')
.insertText('a') .insertText('a')
.apply() .apply()
assert.deepEqual(next.selection.toJS(), range.moveForward().toJS())
return next
} }

View File

@@ -1,17 +1,24 @@
import assert from 'assert'
export default function (state) { export default function (state) {
const { document, selection } = state const { document, selection } = state
const texts = document.getTexts() const texts = document.getTexts()
const first = texts.first() const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 2
})
return state const next = state
.transform() .transform()
.moveTo({ .moveTo(range)
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 2
})
.addMark('bold') .addMark('bold')
.apply() .apply()
assert.deepEqual(next.selection.toJS(), range.toJS())
return next
} }

View File

@@ -1,17 +1,24 @@
import assert from 'assert'
export default function (state) { export default function (state) {
const { document, selection } = state const { document, selection } = state
const texts = document.getTexts() const texts = document.getTexts()
const first = texts.first() const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 1
})
return state const next = state
.transform() .transform()
.moveTo({ .moveTo(range)
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 1
})
.addMark('bold') .addMark('bold')
.apply() .apply()
assert.deepEqual(next.selection.toJS(), range.toJS())
return next
} }

View File

@@ -1,17 +1,24 @@
import assert from 'assert'
export default function (state) { export default function (state) {
const { document, selection } = state const { document, selection } = state
const texts = document.getTexts() const texts = document.getTexts()
const first = texts.first() 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() .transform()
.moveTo({ .moveTo(range)
anchorKey: first.key,
anchorOffset: first.length - 1,
focusKey: first.key,
focusOffset: first.length
})
.addMark('bold') .addMark('bold')
.apply() .apply()
assert.deepEqual(next.selection.toJS(), range.toJS())
return next
} }

View File

@@ -1,17 +1,24 @@
import assert from 'assert'
export default function (state) { export default function (state) {
const { document, selection } = state const { document, selection } = state
const texts = document.getTexts() const texts = document.getTexts()
const first = texts.first() const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 1,
focusKey: first.key,
focusOffset: 2
})
return state const next = state
.transform() .transform()
.moveTo({ .moveTo(range)
anchorKey: first.key,
anchorOffset: 1,
focusKey: first.key,
focusOffset: 2
})
.addMark('bold') .addMark('bold')
.apply() .apply()
assert.deepEqual(next.selection.toJS(), range.toJS())
return next
} }

View File

@@ -1,17 +1,24 @@
import assert from 'assert'
export default function (state) { export default function (state) {
const { document, selection } = state const { document, selection } = state
const texts = document.getTexts() const texts = document.getTexts()
const first = texts.first() 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() .transform()
.moveTo({ .moveTo(range)
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: first.length
})
.addMark('bold') .addMark('bold')
.apply() .apply()
assert.deepEqual(next.selection.toJS(), range.toJS())
return next
} }

View File

@@ -1,22 +1,28 @@
import { Mark } from '../../../../..' import { Mark } from '../../../../..'
import assert from 'assert'
export default function (state) { export default function (state) {
const { document, selection } = state const { document, selection } = state
const texts = document.getTexts() const texts = document.getTexts()
const first = texts.first() const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 1
})
return state const next = state
.transform() .transform()
.moveTo({ .moveTo(range)
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 1
})
.addMark(Mark.create({ .addMark(Mark.create({
type: 'bold', type: 'bold',
data: { key: 'value' } data: { key: 'value' }
})) }))
.apply() .apply()
assert.deepEqual(next.selection.toJS(), range.toJS())
return next
} }

View File

@@ -1,20 +1,27 @@
import assert from 'assert'
export default function (state) { export default function (state) {
const { document, selection } = state const { document, selection } = state
const texts = document.getTexts() const texts = document.getTexts()
const first = texts.first() const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 1
})
return state const next = state
.transform() .transform()
.moveTo({ .moveTo(range)
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 1
})
.addMark({ .addMark({
type: 'bold', type: 'bold',
data: { key: 'value' } data: { key: 'value' }
}) })
.apply() .apply()
assert.deepEqual(next.selection.toJS(), range.toJS())
return next
} }