1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-11 01:33:58 +02:00

add more tests

This commit is contained in:
Ian Storm Taylor
2016-06-27 15:19:51 -07:00
parent cb2dda5bf4
commit 5d21a315f7
24 changed files with 345 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
nodes:
- kind: block
type: list-item
nodes:
- kind: text
ranges:
- text: fragment

View File

@@ -0,0 +1,25 @@
import path from 'path'
import readMetadata from 'read-metadata'
import { Raw } from '../../../../..'
export default function (state) {
const file = path.resolve(__dirname, 'fragment.yaml')
const raw = readMetadata.sync(file)
const fragment = Raw.deserialize(raw).document
const { document, selection } = state
const texts = document.getTextNodes()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: first.length,
focusKey: first.key,
focusOffset: first.length
})
return state
.transform()
.insertFragmentAtRange(range, fragment)
.apply()
}

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: paragraph
nodes:
- kind: text
ranges:
- text: wordfragment

View File

@@ -0,0 +1,8 @@
nodes:
- kind: block
type: list-item
nodes:
- kind: text
ranges:
- text: fragment

View File

@@ -0,0 +1,25 @@
import path from 'path'
import readMetadata from 'read-metadata'
import { Raw } from '../../../../..'
export default function (state) {
const file = path.resolve(__dirname, 'fragment.yaml')
const raw = readMetadata.sync(file)
const fragment = Raw.deserialize(raw).document
const { document, selection } = state
const texts = document.getTextNodes()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: first.length,
focusKey: first.key,
focusOffset: first.length
})
return state
.transform()
.insertFragmentAtRange(range, fragment)
.apply()
}

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,14 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: word
- kind: text
ranges:
- text: fragment

View File

@@ -0,0 +1,11 @@
nodes:
- kind: block
type: list-item
nodes:
- kind: inline
type: hashtag
nodes:
- kind: text
ranges:
- text: fragment

View File

@@ -0,0 +1,25 @@
import path from 'path'
import readMetadata from 'read-metadata'
import { Raw } from '../../../../..'
export default function (state) {
const file = path.resolve(__dirname, 'fragment.yaml')
const raw = readMetadata.sync(file)
const fragment = Raw.deserialize(raw).document
const { document, selection } = state
const texts = document.getTextNodes()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 2,
focusKey: first.key,
focusOffset: 2
})
return state
.transform()
.insertFragmentAtRange(range, fragment)
.apply()
}

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,23 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: wo
- kind: inline
type: hashtag
nodes:
- kind: text
ranges:
- text: fragment
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: rd

View File

@@ -0,0 +1,8 @@
nodes:
- kind: block
type: list-item
nodes:
- kind: text
ranges:
- text: fragment

View File

@@ -0,0 +1,25 @@
import path from 'path'
import readMetadata from 'read-metadata'
import { Raw } from '../../../../..'
export default function (state) {
const file = path.resolve(__dirname, 'fragment.yaml')
const raw = readMetadata.sync(file)
const fragment = Raw.deserialize(raw).document
const { document, selection } = state
const texts = document.getTextNodes()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 0
})
return state
.transform()
.insertFragmentAtRange(range, fragment)
.apply()
}

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: paragraph
nodes:
- kind: text
ranges:
- text: fragmentword

View File

@@ -0,0 +1,8 @@
nodes:
- kind: block
type: list-item
nodes:
- kind: text
ranges:
- text: fragment

View File

@@ -0,0 +1,25 @@
import path from 'path'
import readMetadata from 'read-metadata'
import { Raw } from '../../../../..'
export default function (state) {
const file = path.resolve(__dirname, 'fragment.yaml')
const raw = readMetadata.sync(file)
const fragment = Raw.deserialize(raw).document
const { document, selection } = state
const texts = document.getTextNodes()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 0
})
return state
.transform()
.insertFragmentAtRange(range, fragment)
.apply()
}

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,14 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: fragment
- kind: inline
type: link
nodes:
- kind: text
ranges:
- text: word

View File

@@ -0,0 +1,8 @@
nodes:
- kind: block
type: list-item
nodes:
- kind: text
ranges:
- text: fragment

View File

@@ -0,0 +1,25 @@
import path from 'path'
import readMetadata from 'read-metadata'
import { Raw } from '../../../../..'
export default function (state) {
const file = path.resolve(__dirname, 'fragment.yaml')
const raw = readMetadata.sync(file)
const fragment = Raw.deserialize(raw).document
const { document, selection } = state
const texts = document.getTextNodes()
const second = texts.get(1)
const range = selection.merge({
anchorKey: second.key,
anchorOffset: 0,
focusKey: second.key,
focusOffset: 0
})
return state
.transform()
.insertFragmentAtRange(range, fragment)
.apply()
}

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: paragraph
nodes:
- kind: text
ranges:
- text: word
- kind: block
type: paragraph
nodes:
- kind: text
ranges:
- text: fragmentanother