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

add setBlock and setInline transform tests

This commit is contained in:
Ian Storm Taylor
2016-07-21 15:15:50 -07:00
parent a66aa1e5e6
commit 37829137c6
51 changed files with 884 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
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
})
const next = state
.transform()
.moveTo(range)
.setBlock({ type: 'code' })
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,14 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: another

View File

@@ -0,0 +1,14 @@
nodes:
- kind: block
type: code
nodes:
- kind: text
ranges:
- text: word
- kind: block
type: code
nodes:
- kind: text
ranges:
- text: another

View File

@@ -0,0 +1,28 @@
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
})
const next = state
.transform()
.moveTo(range)
.setBlock({ type: 'code' })
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,20 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: word
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: another

View File

@@ -0,0 +1,20 @@
nodes:
- kind: block
type: code
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: word
- kind: block
type: code
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: another

View File

@@ -0,0 +1,28 @@
import { Data } 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: 0
})
const next = state
.transform()
.moveTo(range)
.setBlock({ data: Data.create({ key: 'value' }) })
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,8 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,10 @@
nodes:
- kind: block
type: paragraph
data:
key: value
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +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: 0
})
const next = state
.transform()
.moveTo(range)
.setBlock({ type: 'code' })
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,11 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,11 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: block
type: code
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +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: 0
})
const next = state
.transform()
.moveTo(range)
.setBlock('code')
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,8 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,8 @@
nodes:
- kind: block
type: code
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +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: 0
})
const next = state
.transform()
.moveTo(range)
.setBlock({ type: 'code' })
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,8 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,8 @@
nodes:
- kind: block
type: code
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,30 @@
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
})
const next = state
.transform()
.moveTo(range)
.setBlock({
type: 'code',
data: { key: 'value' }
})
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,8 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,10 @@
nodes:
- kind: block
type: code
data:
key: value
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,31 @@
import { Data } 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: 0
})
const next = state
.transform()
.moveTo(range)
.setBlock({
type: 'code',
data: Data.create({ key: 'value' })
})
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,8 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,10 @@
nodes:
- kind: block
type: code
data:
key: value
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,30 @@
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
})
const next = state
.transform()
.moveTo(range)
.setBlock({
type: 'image',
isVoid: true
})
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,8 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,9 @@
nodes:
- kind: block
type: image
isVoid: true
nodes:
- kind: text
ranges:
- text: ""

View File

@@ -0,0 +1,28 @@
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
})
const next = state
.transform()
.moveTo(range)
.setInline({ type: 'code' })
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,20 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: word
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: another

View File

@@ -0,0 +1,20 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: code
nodes:
- kind: text
ranges:
- text: word
- kind: block
type: paragraph
nodes:
- kind: inline
type: code
nodes:
- kind: text
ranges:
- text: another

View File

@@ -0,0 +1,28 @@
import { Data } 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: 0
})
const next = state
.transform()
.moveTo(range)
.setInline({ data: Data.create({ key: 'value' }) })
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,11 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,13 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
data:
key: value
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +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: 0
})
const next = state
.transform()
.moveTo(range)
.setInline({ type: 'code' })
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,14 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: hashtag
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,14 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: hashtag
nodes:
- kind: inline
type: code
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +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: 0
})
const next = state
.transform()
.moveTo(range)
.setInline('code')
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,11 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,11 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: code
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +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: 0
})
const next = state
.transform()
.moveTo(range)
.setInline({ type: 'code' })
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,11 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,11 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: code
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,30 @@
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
})
const next = state
.transform()
.moveTo(range)
.setInline({
type: 'code',
data: { key: 'value' }
})
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,11 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,13 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: code
data:
key: value
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,31 @@
import { Data } 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: 0
})
const next = state
.transform()
.moveTo(range)
.setInline({
type: 'code',
data: Data.create({ key: 'value' })
})
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,11 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,13 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: code
data:
key: value
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,30 @@
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
})
const next = state
.transform()
.moveTo(range)
.setInline({
type: 'emoji',
isVoid: true
})
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,11 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,12 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: emoji
isVoid: true
nodes:
- kind: text
ranges:
- text: ""