1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-16 04:04:06 +02:00

add wrapInline transform tests

This commit is contained in:
Ian Storm Taylor
2016-07-21 16:03:02 -07:00
parent 1bf729db5f
commit eb95b79a00
18 changed files with 411 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
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)
.wrapInline('hashtag')
.apply()
const two = next.document.getTexts().get(1)
const three = next.document.getTexts().get(2)
// assert.deepEqual(
// next.selection.toJS(),
// range.merge({
// anchorKey: two.key,
// anchorOffset: 0,
// focusKey: three.key,
// focusOffset: three.length
// }).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,26 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: wo
- kind: inline
type: hashtag
nodes:
- kind: text
ranges:
- text: rd
- kind: block
type: paragraph
nodes:
- kind: inline
type: hashtag
nodes:
- kind: text
ranges:
- text: an
- kind: text
ranges:
- text: other

View File

@@ -0,0 +1,36 @@
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)
.wrapInline('hashtag')
.apply()
const two = next.document.getTexts().get(1)
const three = next.document.getTexts().get(2)
// assert.deepEqual(
// next.selection.toJS(),
// range.merge({
// anchorKey: two.key,
// anchorOffset: 0,
// focusKey: three.key,
// focusOffset: three.length
// }).toJS()
// )
return next
}

View File

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

View File

@@ -0,0 +1,35 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: wo
- kind: inline
type: hashtag
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: rd
- kind: inline
type: hashtag
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: an
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: other

View File

@@ -0,0 +1,34 @@
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: 3
})
const next = state
.transform()
.moveTo(range)
.wrapInline('hashtag')
.apply()
const updated = next.document.getTexts().get(1)
assert.deepEqual(
next.selection.toJS(),
range.merge({
anchorKey: updated.key,
anchorOffset: 0,
focusKey: updated.key,
focusOffset: updated.length
}).toJS()
)
return next
}

View File

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

View File

@@ -0,0 +1,20 @@
nodes:
- kind: block
type: quote
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: w
- kind: inline
type: hashtag
nodes:
- kind: text
ranges:
- text: or
- kind: text
ranges:
- text: d

View File

@@ -0,0 +1,34 @@
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: 3
})
const next = state
.transform()
.moveTo(range)
.wrapInline('hashtag')
.apply()
const updated = next.document.getTexts().get(1)
assert.deepEqual(
next.selection.toJS(),
range.merge({
anchorKey: updated.key,
anchorOffset: 0,
focusKey: updated.key,
focusOffset: updated.length
}).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,17 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: w
- kind: inline
type: hashtag
nodes:
- kind: text
ranges:
- text: or
- kind: text
ranges:
- text: d

View File

@@ -0,0 +1,34 @@
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: 3
})
const next = state
.transform()
.moveTo(range)
.wrapInline('hashtag', { key: 'value' })
.apply()
const updated = next.document.getTexts().get(1)
assert.deepEqual(
next.selection.toJS(),
range.merge({
anchorKey: updated.key,
anchorOffset: 0,
focusKey: updated.key,
focusOffset: updated.length
}).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,19 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: w
- kind: inline
type: hashtag
data:
key: value
nodes:
- kind: text
ranges:
- text: or
- kind: text
ranges:
- text: d

View File

@@ -0,0 +1,35 @@
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: 1,
focusKey: first.key,
focusOffset: 3
})
const next = state
.transform()
.moveTo(range)
.wrapInline('hashtag', Data.create({ key: 'value' }))
.apply()
const updated = next.document.getTexts().get(1)
assert.deepEqual(
next.selection.toJS(),
range.merge({
anchorKey: updated.key,
anchorOffset: 0,
focusKey: updated.key,
focusOffset: updated.length
}).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,19 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: w
- kind: inline
type: hashtag
data:
key: value
nodes:
- kind: text
ranges:
- text: or
- kind: text
ranges:
- text: d