diff --git a/test/schema/fixtures/default-no-document-inline/index.js b/test/schema/fixtures/default-document-children/no-inline/index.js similarity index 100% rename from test/schema/fixtures/default-no-document-inline/index.js rename to test/schema/fixtures/default-document-children/no-inline/index.js diff --git a/test/schema/fixtures/default-no-document-inline/input.yaml b/test/schema/fixtures/default-document-children/no-inline/input.yaml similarity index 100% rename from test/schema/fixtures/default-no-document-inline/input.yaml rename to test/schema/fixtures/default-document-children/no-inline/input.yaml diff --git a/test/schema/fixtures/default-no-document-inline/output.yaml b/test/schema/fixtures/default-document-children/no-inline/output.yaml similarity index 100% rename from test/schema/fixtures/default-no-document-inline/output.yaml rename to test/schema/fixtures/default-document-children/no-inline/output.yaml diff --git a/test/schema/fixtures/default-no-document-text/index.js b/test/schema/fixtures/default-document-children/no-text/index.js similarity index 100% rename from test/schema/fixtures/default-no-document-text/index.js rename to test/schema/fixtures/default-document-children/no-text/index.js diff --git a/test/schema/fixtures/default-no-document-text/input.yaml b/test/schema/fixtures/default-document-children/no-text/input.yaml similarity index 100% rename from test/schema/fixtures/default-no-document-text/input.yaml rename to test/schema/fixtures/default-document-children/no-text/input.yaml diff --git a/test/schema/fixtures/default-no-document-text/output.yaml b/test/schema/fixtures/default-document-children/no-text/output.yaml similarity index 100% rename from test/schema/fixtures/default-no-document-text/output.yaml rename to test/schema/fixtures/default-document-children/no-text/output.yaml diff --git a/test/schema/fixtures/default-no-inline-block/index.js b/test/schema/fixtures/default-inline-children/no-block/index.js similarity index 100% rename from test/schema/fixtures/default-no-inline-block/index.js rename to test/schema/fixtures/default-inline-children/no-block/index.js diff --git a/test/schema/fixtures/default-no-inline-block/input.yaml b/test/schema/fixtures/default-inline-children/no-block/input.yaml similarity index 100% rename from test/schema/fixtures/default-no-inline-block/input.yaml rename to test/schema/fixtures/default-inline-children/no-block/input.yaml diff --git a/test/schema/fixtures/default-no-inline-block/output.yaml b/test/schema/fixtures/default-inline-children/no-block/output.yaml similarity index 100% rename from test/schema/fixtures/default-no-inline-block/output.yaml rename to test/schema/fixtures/default-inline-children/no-block/output.yaml diff --git a/test/schema/fixtures/default-void-text-around/index.js b/test/schema/fixtures/default-min-text/in-block/index.js similarity index 100% rename from test/schema/fixtures/default-void-text-around/index.js rename to test/schema/fixtures/default-min-text/in-block/index.js diff --git a/test/schema/fixtures/default-min-text/in-block/input.yaml b/test/schema/fixtures/default-min-text/in-block/input.yaml new file mode 100644 index 000000000..5db70fc35 --- /dev/null +++ b/test/schema/fixtures/default-min-text/in-block/input.yaml @@ -0,0 +1,4 @@ + +nodes: + - kind: block + type: paragraph diff --git a/test/schema/fixtures/default-min-text/in-block/output.yaml b/test/schema/fixtures/default-min-text/in-block/output.yaml new file mode 100644 index 000000000..f6de4d08a --- /dev/null +++ b/test/schema/fixtures/default-min-text/in-block/output.yaml @@ -0,0 +1,7 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + text: "" diff --git a/test/schema/fixtures/default-min-text/in-inline/index.js b/test/schema/fixtures/default-min-text/in-inline/index.js new file mode 100644 index 000000000..9a676e861 --- /dev/null +++ b/test/schema/fixtures/default-min-text/in-inline/index.js @@ -0,0 +1,2 @@ + +export default {} diff --git a/test/schema/fixtures/default-min-text/in-inline/input.yaml b/test/schema/fixtures/default-min-text/in-inline/input.yaml new file mode 100644 index 000000000..e66f67c6f --- /dev/null +++ b/test/schema/fixtures/default-min-text/in-inline/input.yaml @@ -0,0 +1,7 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link diff --git a/test/schema/fixtures/default-min-text/in-inline/output.yaml b/test/schema/fixtures/default-min-text/in-inline/output.yaml new file mode 100644 index 000000000..f6de4d08a --- /dev/null +++ b/test/schema/fixtures/default-min-text/in-inline/output.yaml @@ -0,0 +1,7 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + text: "" diff --git a/test/schema/fixtures/default-void-text-around/only-child/index.js b/test/schema/fixtures/default-void-text-around/only-child/index.js new file mode 100644 index 000000000..9a676e861 --- /dev/null +++ b/test/schema/fixtures/default-void-text-around/only-child/index.js @@ -0,0 +1,2 @@ + +export default {} diff --git a/test/schema/fixtures/default-void-text-around/input.yaml b/test/schema/fixtures/default-void-text-around/only-child/input.yaml similarity index 100% rename from test/schema/fixtures/default-void-text-around/input.yaml rename to test/schema/fixtures/default-void-text-around/only-child/input.yaml diff --git a/test/schema/fixtures/default-void-text-around/output.yaml b/test/schema/fixtures/default-void-text-around/only-child/output.yaml similarity index 100% rename from test/schema/fixtures/default-void-text-around/output.yaml rename to test/schema/fixtures/default-void-text-around/only-child/output.yaml diff --git a/test/schema/index.js b/test/schema/index.js index 2043f2b7c..2ff1546d8 100644 --- a/test/schema/index.js +++ b/test/schema/index.js @@ -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() - const normalized = wrapper.state().state - const output = Raw.serialize(normalized, { terse: true }) - strictEqual(strip(output), strip(expected)) }) } })