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:
@@ -0,0 +1,4 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
@@ -0,0 +1,7 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: ""
|
2
test/schema/fixtures/default-min-text/in-inline/index.js
Normal file
2
test/schema/fixtures/default-min-text/in-inline/index.js
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
export default {}
|
@@ -0,0 +1,7 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: inline
|
||||
type: link
|
@@ -0,0 +1,7 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: ""
|
@@ -0,0 +1,2 @@
|
||||
|
||||
export default {}
|
@@ -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))
|
||||
})
|
||||
}
|
||||
})
|
||||
|
Reference in New Issue
Block a user