1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-31 02:49:56 +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 fs from 'fs'
import jsdom from 'mocha-jsdom'
import readMetadata from 'read-metadata'
import strip from '../helpers/strip-dynamic'
import { Raw, Editor, Schema } from '../..'
import { Raw, Schema } from '../..'
import { mount } from 'enzyme'
import { resolve } from 'path'
import { strictEqual } from '../helpers/assert-json'
@@ -14,29 +13,29 @@ import { strictEqual } from '../helpers/assert-json'
*/
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
for (const test of tests) {
if (test[0] == '.') continue
describe(category, () => {
const tests = fs.readdirSync(resolve(__dirname, './fixtures', category))
it(test, () => {
const dir = resolve(__dirname, './fixtures', test)
const input = readMetadata.sync(resolve(dir, 'input.yaml'))
const expected = readMetadata.sync(resolve(dir, 'output.yaml'))
const schema = Schema.create(require(dir))
const state = Raw.deserialize(input, { terse: true })
const props = {
onChange: value => value,
schema,
state,
for (const test of tests) {
if (test[0] == '.') continue
it(test, () => {
const testDir = resolve(__dirname, './fixtures', category, test)
const input = readMetadata.sync(resolve(testDir, 'input.yaml'))
const expected = readMetadata.sync(resolve(testDir, 'output.yaml'))
const schema = Schema.create(require(testDir))
const state = Raw.deserialize(input, { terse: true })
const normalized = state.transform().normalizeWith(schema).apply()
const output = Raw.serialize(normalized, { terse: true })
strictEqual(strip(output), strip(expected))
})
}
const wrapper = mount(<Editor {...props} />)
const normalized = wrapper.state().state
const output = Raw.serialize(normalized, { terse: true })
strictEqual(strip(output), strip(expected))
})
}
})