1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-13 11:44:55 +01:00

39 lines
1.1 KiB
JavaScript
Raw Normal View History

import React from 'react'
import ReactDOM from 'react-dom/server'
import assert from 'assert'
import clean from '../helpers/clean'
import fs from 'fs-promise' // eslint-disable-line import/no-extraneous-dependencies
import parse5 from 'parse5' // eslint-disable-line import/no-extraneous-dependencies
start removing raw serializer (#1098) * start removing raw serializer * convert first tests to use jsx * simplify jsx tests for raw serializer * allow for options in raw serializer tests * add more preserve option tests * convert plain serializer tests * convert html serialize * start converting html deserialize * add hyperscript util * remove slate-sugar copy-pasted * finish converting html deserialize * convert plugins tests * update rendering tests * convert schemas tests * convert core plugin tests * update hyperscript utl * refactor changes test directory structure * fix changes before migration * add migrated changes test files * remove <x- prefixes from migration * get addMark at-current-range tests passing * get delete at-current-range tests passing * remove old tests * convert deleteForward and deleteBackward * convert insertBlock, insertInline, insertFragment, insertText * convert removeMark, setBlock, setInline, splitBlock, splitInline * add unstaged tests * convert toggleMark, unwrapBlock, unwrapInline, wrapBlock, wrapInline, wrapText * convert call, setData * convert on-selection tests * remove old on-selection tests * convert history tests * convert insertFragmentByKey, insertNodeByKey, insertTextByKey, mergeNodeByKey, moveNodeByKey * convert removeNodeByKey, removeTextByKey, setMarkByKey, setNodeByKey * convert splitDescendantsByKey, splitNodeByKey, unwrapBlockByKey, unwrapInlineByKey, unwrapNodeByKey, wrapBlockByKey * fix tests * port missing at-range tests to at-current-range * remove at-range tests * fix raw serializer tests * fix linter * fix to prefer toJSON as the canonical method name * fix todos * remove internal references to Raw * add deprecation helper to Text.fromJSON * convert examples to not use Raw, and not rely on terse * remove focus-blur example, rename large document example * refactor Raw serialize to deprecate, not remove, terse * deprecate defaultBlockType, toRaw, cleanup serializers
2017-09-10 14:56:03 -07:00
import { Editor } from '../..'
import { basename, extname, resolve } from 'path'
/**
* Tests.
*/
describe('rendering', () => {
start removing raw serializer (#1098) * start removing raw serializer * convert first tests to use jsx * simplify jsx tests for raw serializer * allow for options in raw serializer tests * add more preserve option tests * convert plain serializer tests * convert html serialize * start converting html deserialize * add hyperscript util * remove slate-sugar copy-pasted * finish converting html deserialize * convert plugins tests * update rendering tests * convert schemas tests * convert core plugin tests * update hyperscript utl * refactor changes test directory structure * fix changes before migration * add migrated changes test files * remove <x- prefixes from migration * get addMark at-current-range tests passing * get delete at-current-range tests passing * remove old tests * convert deleteForward and deleteBackward * convert insertBlock, insertInline, insertFragment, insertText * convert removeMark, setBlock, setInline, splitBlock, splitInline * add unstaged tests * convert toggleMark, unwrapBlock, unwrapInline, wrapBlock, wrapInline, wrapText * convert call, setData * convert on-selection tests * remove old on-selection tests * convert history tests * convert insertFragmentByKey, insertNodeByKey, insertTextByKey, mergeNodeByKey, moveNodeByKey * convert removeNodeByKey, removeTextByKey, setMarkByKey, setNodeByKey * convert splitDescendantsByKey, splitNodeByKey, unwrapBlockByKey, unwrapInlineByKey, unwrapNodeByKey, wrapBlockByKey * fix tests * port missing at-range tests to at-current-range * remove at-range tests * fix raw serializer tests * fix linter * fix to prefer toJSON as the canonical method name * fix todos * remove internal references to Raw * add deprecation helper to Text.fromJSON * convert examples to not use Raw, and not rely on terse * remove focus-blur example, rename large document example * refactor Raw serialize to deprecate, not remove, terse * deprecate defaultBlockType, toRaw, cleanup serializers
2017-09-10 14:56:03 -07:00
const dir = resolve(__dirname, './fixtures')
const tests = fs.readdirSync(dir).filter(t => t[0] != '.' && !!~t.indexOf('.js')).map(t => basename(t, extname(t)))
for (const test of tests) {
it(test, async () => {
start removing raw serializer (#1098) * start removing raw serializer * convert first tests to use jsx * simplify jsx tests for raw serializer * allow for options in raw serializer tests * add more preserve option tests * convert plain serializer tests * convert html serialize * start converting html deserialize * add hyperscript util * remove slate-sugar copy-pasted * finish converting html deserialize * convert plugins tests * update rendering tests * convert schemas tests * convert core plugin tests * update hyperscript utl * refactor changes test directory structure * fix changes before migration * add migrated changes test files * remove <x- prefixes from migration * get addMark at-current-range tests passing * get delete at-current-range tests passing * remove old tests * convert deleteForward and deleteBackward * convert insertBlock, insertInline, insertFragment, insertText * convert removeMark, setBlock, setInline, splitBlock, splitInline * add unstaged tests * convert toggleMark, unwrapBlock, unwrapInline, wrapBlock, wrapInline, wrapText * convert call, setData * convert on-selection tests * remove old on-selection tests * convert history tests * convert insertFragmentByKey, insertNodeByKey, insertTextByKey, mergeNodeByKey, moveNodeByKey * convert removeNodeByKey, removeTextByKey, setMarkByKey, setNodeByKey * convert splitDescendantsByKey, splitNodeByKey, unwrapBlockByKey, unwrapInlineByKey, unwrapNodeByKey, wrapBlockByKey * fix tests * port missing at-range tests to at-current-range * remove at-range tests * fix raw serializer tests * fix linter * fix to prefer toJSON as the canonical method name * fix todos * remove internal references to Raw * add deprecation helper to Text.fromJSON * convert examples to not use Raw, and not rely on terse * remove focus-blur example, rename large document example * refactor Raw serialize to deprecate, not remove, terse * deprecate defaultBlockType, toRaw, cleanup serializers
2017-09-10 14:56:03 -07:00
const module = require(resolve(dir, test))
const { state, schema, output } = module
const props = {
start removing raw serializer (#1098) * start removing raw serializer * convert first tests to use jsx * simplify jsx tests for raw serializer * allow for options in raw serializer tests * add more preserve option tests * convert plain serializer tests * convert html serialize * start converting html deserialize * add hyperscript util * remove slate-sugar copy-pasted * finish converting html deserialize * convert plugins tests * update rendering tests * convert schemas tests * convert core plugin tests * update hyperscript utl * refactor changes test directory structure * fix changes before migration * add migrated changes test files * remove <x- prefixes from migration * get addMark at-current-range tests passing * get delete at-current-range tests passing * remove old tests * convert deleteForward and deleteBackward * convert insertBlock, insertInline, insertFragment, insertText * convert removeMark, setBlock, setInline, splitBlock, splitInline * add unstaged tests * convert toggleMark, unwrapBlock, unwrapInline, wrapBlock, wrapInline, wrapText * convert call, setData * convert on-selection tests * remove old on-selection tests * convert history tests * convert insertFragmentByKey, insertNodeByKey, insertTextByKey, mergeNodeByKey, moveNodeByKey * convert removeNodeByKey, removeTextByKey, setMarkByKey, setNodeByKey * convert splitDescendantsByKey, splitNodeByKey, unwrapBlockByKey, unwrapInlineByKey, unwrapNodeByKey, wrapBlockByKey * fix tests * port missing at-range tests to at-current-range * remove at-range tests * fix raw serializer tests * fix linter * fix to prefer toJSON as the canonical method name * fix todos * remove internal references to Raw * add deprecation helper to Text.fromJSON * convert examples to not use Raw, and not rely on terse * remove focus-blur example, rename large document example * refactor Raw serialize to deprecate, not remove, terse * deprecate defaultBlockType, toRaw, cleanup serializers
2017-09-10 14:56:03 -07:00
state,
schema,
onChange() {},
}
const string = ReactDOM.renderToStaticMarkup(<Editor {...props} />)
const expected = parse5.serialize(parse5.parseFragment(output))
.trim()
.replace(/\n/gm, '')
.replace(/>\s*</g, '><')
assert.equal(clean(string), expected)
})
}
})