1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-29 09:59:48 +02:00

add unwrapBlock transform tests

This commit is contained in:
Ian Storm Taylor
2016-07-21 15:41:59 -07:00
parent 986e49aaac
commit 49c5754c8e
42 changed files with 742 additions and 84 deletions

View File

@@ -13,6 +13,6 @@ export default function (state) {
return state
.transform()
.wrapBlockAtRange(range, 'quote')
.unwrapBlockAtRange(range, 'quote')
.apply()
}

View File

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

View File

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

View File

@@ -12,6 +12,6 @@ export default function (state) {
return state
.transform()
.wrapBlockAtRange(range, 'quote')
.unwrapBlockAtRange(range, 'quote')
.apply()
}

View File

@@ -4,8 +4,11 @@ nodes:
type: quote
nodes:
- kind: block
type: paragraph
type: quote
nodes:
- kind: text
ranges:
- text: word
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word

View File

@@ -4,11 +4,8 @@ nodes:
type: quote
nodes:
- kind: block
type: quote
type: paragraph
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word
- kind: text
ranges:
- text: word

View File

@@ -12,6 +12,6 @@ export default function (state) {
return state
.transform()
.wrapBlockAtRange(range, 'quote')
.unwrapBlockAtRange(range, 'quote')
.apply()
}

View File

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

View File

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

View File

@@ -12,6 +12,6 @@ export default function (state) {
return state
.transform()
.wrapBlockAtRange(range, 'quote', { key: 'value' })
.unwrapBlockAtRange(range, 'quote', { key: 'value' })
.apply()
}

View File

@@ -1,8 +1,13 @@
nodes:
- kind: block
type: paragraph
type: quote
data:
key: value
nodes:
- kind: text
ranges:
- text: word
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word

View File

@@ -1,13 +1,8 @@
nodes:
- kind: block
type: quote
data:
key: value
type: paragraph
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word
- kind: text
ranges:
- text: word

View File

@@ -14,6 +14,6 @@ export default function (state) {
return state
.transform()
.wrapBlockAtRange(range, 'quote', Data.create({ key: 'value' }))
.unwrapBlockAtRange(range, 'quote', Data.create({ key: 'value' }))
.apply()
}

View File

@@ -1,8 +1,13 @@
nodes:
- kind: block
type: paragraph
type: quote
data:
key: value
nodes:
- kind: text
ranges:
- text: word
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word

View File

@@ -1,13 +1,8 @@
nodes:
- kind: block
type: quote
data:
key: value
type: paragraph
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word
- kind: text
ranges:
- text: word

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)
.unwrapBlock('quote')
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,17 @@
nodes:
- kind: block
type: quote
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: paragraph
nodes:
- kind: text
ranges:
- text: word
- kind: block
type: paragraph
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)
.unwrapBlock('quote')
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,23 @@
nodes:
- kind: block
type: quote
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: 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,28 @@
import assert from 'assert'
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const fifth = texts.get(4)
const sixth = texts.get(5)
const range = selection.merge({
anchorKey: fifth.key,
anchorOffset: 0,
focusKey: sixth.key,
focusOffset: 0
})
const next = state
.transform()
.moveTo(range)
.unwrapBlock('quote')
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,41 @@
nodes:
- kind: block
type: quote
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: one
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: two
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: three
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: four
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: five
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: six

View File

@@ -0,0 +1,41 @@
nodes:
- kind: block
type: quote
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: one
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: two
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: three
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: four
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: five
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: six

View File

@@ -0,0 +1,28 @@
import assert from 'assert'
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const third = texts.get(2)
const fourth = texts.get(3)
const range = selection.merge({
anchorKey: third.key,
anchorOffset: 0,
focusKey: fourth.key,
focusOffset: 0
})
const next = state
.transform()
.moveTo(range)
.unwrapBlock('quote')
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,41 @@
nodes:
- kind: block
type: quote
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: one
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: two
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: three
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: four
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: five
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: six

View File

@@ -0,0 +1,44 @@
nodes:
- kind: block
type: quote
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: one
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: two
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: three
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: four
- kind: block
type: quote
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: five
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: six

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)
.unwrapBlock('quote')
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

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

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,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)
.unwrapBlock('quote')
.apply()
assert.deepEqual(
next.selection.toJS(),
range.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,8 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: word

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.get(0)
const second = texts.get(1)
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 0,
focusKey: second.key,
focusOffset: 0
})
const next = state
.transform()
.moveTo(range)
.unwrapBlock('quote')
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

@@ -0,0 +1,41 @@
nodes:
- kind: block
type: quote
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: one
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: two
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: three
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: four
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: five
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: six

View File

@@ -0,0 +1,41 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: one
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: two
- kind: block
type: quote
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: three
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: four
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: five
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: six

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)
.unwrapBlock('quote', { key: 'value' })
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

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

View File

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

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)
.unwrapBlock('quote', Data.create({ key: 'value' }))
.apply()
assert.deepEqual(
next.selection.toJS(),
range.toJS()
)
return next
}

View File

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

View File

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