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:
36
test/transforms/fixtures/wrap-inline/across-blocks/index.js
Normal file
36
test/transforms/fixtures/wrap-inline/across-blocks/index.js
Normal 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
|
||||
}
|
@@ -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
|
@@ -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
|
36
test/transforms/fixtures/wrap-inline/across-inlines/index.js
Normal file
36
test/transforms/fixtures/wrap-inline/across-inlines/index.js
Normal 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
|
||||
}
|
@@ -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
|
@@ -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
|
34
test/transforms/fixtures/wrap-inline/nested-block/index.js
Normal file
34
test/transforms/fixtures/wrap-inline/nested-block/index.js
Normal 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
|
||||
}
|
11
test/transforms/fixtures/wrap-inline/nested-block/input.yaml
Normal file
11
test/transforms/fixtures/wrap-inline/nested-block/input.yaml
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: quote
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: word
|
@@ -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
|
34
test/transforms/fixtures/wrap-inline/single-block/index.js
Normal file
34
test/transforms/fixtures/wrap-inline/single-block/index.js
Normal 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
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: word
|
@@ -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
|
@@ -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
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: word
|
@@ -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
|
35
test/transforms/fixtures/wrap-inline/with-data/index.js
Normal file
35
test/transforms/fixtures/wrap-inline/with-data/index.js
Normal 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
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: word
|
19
test/transforms/fixtures/wrap-inline/with-data/output.yaml
Normal file
19
test/transforms/fixtures/wrap-inline/with-data/output.yaml
Normal 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
|
Reference in New Issue
Block a user