1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-25 01:33:37 +01:00
slate/test/rendering/index.js
Samy Pessé 845e284ee4 Add RTL support (#204)
* Add property textAlignment for the whole editor

* textAlignment should be set on Content

* Add basic for directionMap in State

* Add RTL to example

* Use setDocument for updating direction map when inserting blocks

* Remove debug log

* Only add 'dir' to node when is not default value

* Prevent tests from failing because of .DS_Store on OSX

* Add tests for rtl rendering

* Fix rendering tests

* Fix test for rendering "text-direction"

* Remove textAlignment prop on editor

* Don't use a directionMap but directly a "textDir" on nodes

* Remove .setDocument from State
2016-07-29 11:25:07 -07:00

64 lines
1.4 KiB
JavaScript

import React from 'react'
import ReactDOM from 'react-dom/server'
import assert from 'assert'
import cheerio from 'cheerio'
import fs from 'fs'
import readMetadata from 'read-metadata'
import { Editor, Raw } from '../..'
import { resolve } from 'path'
/**
* Tests.
*/
describe('rendering', () => {
const tests = fs.readdirSync(resolve(__dirname, './fixtures'))
for (const test of tests) {
if (test[0] === '.') continue
it(test, () => {
const dir = resolve(__dirname, './fixtures', test)
const input = readMetadata.sync(resolve(dir, 'input.yaml'))
const output = fs.readFileSync(resolve(dir, 'output.html'), 'utf8')
const props = {
state: Raw.deserialize(input, { terse: true }),
onChange: () => {},
...require(dir)
}
const string = ReactDOM.renderToStaticMarkup(<Editor {...props} />)
const expected = cheerio
.load(output)
.html()
.trim()
.replace(/\n/gm, '')
.replace(/>\s*</g, '><')
assert.equal(clean(string), expected)
})
}
})
/**
* Clean a renderer `html` string, removing dynamic attributes.
*
* @param {String} html
* @return {String}
*/
function clean(html) {
const $ = cheerio.load(html)
$('*').each((i, el) => {
$(el).removeAttr('data-key')
$(el).removeAttr('data-offset-key')
})
$.root().children().removeAttr('spellcheck')
$.root().children().removeAttr('style')
return $.html()
}