1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-09-02 19:52:32 +02:00

Refactor tests for schema

This commit is contained in:
Samy Pesse
2016-10-22 18:04:31 +02:00
parent f73f63e6b9
commit 7d1279ffe9
19 changed files with 49 additions and 21 deletions

View File

@@ -0,0 +1,4 @@
nodes:
- kind: block
type: paragraph

View File

@@ -0,0 +1,7 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: ""

View File

@@ -0,0 +1,2 @@
export default {}

View File

@@ -0,0 +1,7 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: inline
type: link

View File

@@ -0,0 +1,7 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: ""

View File

@@ -0,0 +1,2 @@
export default {}

View File

@@ -1,10 +1,9 @@
import React from 'react' import React from 'react'
import fs from 'fs' import fs from 'fs'
import jsdom from 'mocha-jsdom'
import readMetadata from 'read-metadata' import readMetadata from 'read-metadata'
import strip from '../helpers/strip-dynamic' import strip from '../helpers/strip-dynamic'
import { Raw, Editor, Schema } from '../..' import { Raw, Schema } from '../..'
import { mount } from 'enzyme' import { mount } from 'enzyme'
import { resolve } from 'path' import { resolve } from 'path'
import { strictEqual } from '../helpers/assert-json' import { strictEqual } from '../helpers/assert-json'
@@ -14,29 +13,29 @@ import { strictEqual } from '../helpers/assert-json'
*/ */
describe('schema', () => { describe('schema', () => {
jsdom() const dir = resolve(__dirname, './fixtures/')
const categories = fs.readdirSync(dir)
const tests = fs.readdirSync(resolve(__dirname, './fixtures')) for (const category of categories) {
if (category[0] == '.') continue
describe(category, () => {
const tests = fs.readdirSync(resolve(__dirname, './fixtures', category))
for (const test of tests) { for (const test of tests) {
if (test[0] == '.') continue if (test[0] == '.') continue
it(test, () => { it(test, () => {
const dir = resolve(__dirname, './fixtures', test) const testDir = resolve(__dirname, './fixtures', category, test)
const input = readMetadata.sync(resolve(dir, 'input.yaml')) const input = readMetadata.sync(resolve(testDir, 'input.yaml'))
const expected = readMetadata.sync(resolve(dir, 'output.yaml')) const expected = readMetadata.sync(resolve(testDir, 'output.yaml'))
const schema = Schema.create(require(dir)) const schema = Schema.create(require(testDir))
const state = Raw.deserialize(input, { terse: true }) const state = Raw.deserialize(input, { terse: true })
const props = { const normalized = state.transform().normalizeWith(schema).apply()
onChange: value => value,
schema,
state,
}
const wrapper = mount(<Editor {...props} />)
const normalized = wrapper.state().state
const output = Raw.serialize(normalized, { terse: true }) const output = Raw.serialize(normalized, { terse: true })
strictEqual(strip(output), strip(expected)) strictEqual(strip(output), strip(expected))
}) })
} }
})
}
}) })