From 37829137c664a4d1eb0dcfcacc6d87de06dd342d Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Thu, 21 Jul 2016 15:15:50 -0700 Subject: [PATCH] add setBlock and setInline transform tests --- .../fixtures/set-block/across-blocks/index.js | 28 +++++++++++++++++ .../set-block/across-blocks/input.yaml | 14 +++++++++ .../set-block/across-blocks/output.yaml | 14 +++++++++ .../set-block/across-inlines/index.js | 28 +++++++++++++++++ .../set-block/across-inlines/input.yaml | 20 ++++++++++++ .../set-block/across-inlines/output.yaml | 20 ++++++++++++ .../fixtures/set-block/data-only/index.js | 28 +++++++++++++++++ .../fixtures/set-block/data-only/input.yaml | 8 +++++ .../fixtures/set-block/data-only/output.yaml | 10 ++++++ .../fixtures/set-block/nested-block/index.js | 27 ++++++++++++++++ .../set-block/nested-block/input.yaml | 11 +++++++ .../set-block/nested-block/output.yaml | 11 +++++++ .../single-block-string-shorthand/index.js | 27 ++++++++++++++++ .../single-block-string-shorthand/input.yaml | 8 +++++ .../single-block-string-shorthand/output.yaml | 8 +++++ .../fixtures/set-block/single-block/index.js | 27 ++++++++++++++++ .../set-block/single-block/input.yaml | 8 +++++ .../set-block/single-block/output.yaml | 8 +++++ .../set-block/with-data-object/index.js | 30 ++++++++++++++++++ .../set-block/with-data-object/input.yaml | 8 +++++ .../set-block/with-data-object/output.yaml | 10 ++++++ .../fixtures/set-block/with-data/index.js | 31 +++++++++++++++++++ .../fixtures/set-block/with-data/input.yaml | 8 +++++ .../fixtures/set-block/with-data/output.yaml | 10 ++++++ .../fixtures/set-block/with-is-void/index.js | 30 ++++++++++++++++++ .../set-block/with-is-void/input.yaml | 8 +++++ .../set-block/with-is-void/output.yaml | 9 ++++++ .../set-inline/across-inlines/index.js | 28 +++++++++++++++++ .../set-inline/across-inlines/input.yaml | 20 ++++++++++++ .../set-inline/across-inlines/output.yaml | 20 ++++++++++++ .../fixtures/set-inline/data-only/index.js | 28 +++++++++++++++++ .../fixtures/set-inline/data-only/input.yaml | 11 +++++++ .../fixtures/set-inline/data-only/output.yaml | 13 ++++++++ .../set-inline/nested-inline/index.js | 27 ++++++++++++++++ .../set-inline/nested-inline/input.yaml | 14 +++++++++ .../set-inline/nested-inline/output.yaml | 14 +++++++++ .../single-inline-string-shorthand/index.js | 27 ++++++++++++++++ .../single-inline-string-shorthand/input.yaml | 11 +++++++ .../output.yaml | 11 +++++++ .../set-inline/single-inline/index.js | 27 ++++++++++++++++ .../set-inline/single-inline/input.yaml | 11 +++++++ .../set-inline/single-inline/output.yaml | 11 +++++++ .../set-inline/with-data-object/index.js | 30 ++++++++++++++++++ .../set-inline/with-data-object/input.yaml | 11 +++++++ .../set-inline/with-data-object/output.yaml | 13 ++++++++ .../fixtures/set-inline/with-data/index.js | 31 +++++++++++++++++++ .../fixtures/set-inline/with-data/input.yaml | 11 +++++++ .../fixtures/set-inline/with-data/output.yaml | 13 ++++++++ .../fixtures/set-inline/with-is-void/index.js | 30 ++++++++++++++++++ .../set-inline/with-is-void/input.yaml | 11 +++++++ .../set-inline/with-is-void/output.yaml | 12 +++++++ 51 files changed, 884 insertions(+) create mode 100644 test/transforms/fixtures/set-block/across-blocks/index.js create mode 100644 test/transforms/fixtures/set-block/across-blocks/input.yaml create mode 100644 test/transforms/fixtures/set-block/across-blocks/output.yaml create mode 100644 test/transforms/fixtures/set-block/across-inlines/index.js create mode 100644 test/transforms/fixtures/set-block/across-inlines/input.yaml create mode 100644 test/transforms/fixtures/set-block/across-inlines/output.yaml create mode 100644 test/transforms/fixtures/set-block/data-only/index.js create mode 100644 test/transforms/fixtures/set-block/data-only/input.yaml create mode 100644 test/transforms/fixtures/set-block/data-only/output.yaml create mode 100644 test/transforms/fixtures/set-block/nested-block/index.js create mode 100644 test/transforms/fixtures/set-block/nested-block/input.yaml create mode 100644 test/transforms/fixtures/set-block/nested-block/output.yaml create mode 100644 test/transforms/fixtures/set-block/single-block-string-shorthand/index.js create mode 100644 test/transforms/fixtures/set-block/single-block-string-shorthand/input.yaml create mode 100644 test/transforms/fixtures/set-block/single-block-string-shorthand/output.yaml create mode 100644 test/transforms/fixtures/set-block/single-block/index.js create mode 100644 test/transforms/fixtures/set-block/single-block/input.yaml create mode 100644 test/transforms/fixtures/set-block/single-block/output.yaml create mode 100644 test/transforms/fixtures/set-block/with-data-object/index.js create mode 100644 test/transforms/fixtures/set-block/with-data-object/input.yaml create mode 100644 test/transforms/fixtures/set-block/with-data-object/output.yaml create mode 100644 test/transforms/fixtures/set-block/with-data/index.js create mode 100644 test/transforms/fixtures/set-block/with-data/input.yaml create mode 100644 test/transforms/fixtures/set-block/with-data/output.yaml create mode 100644 test/transforms/fixtures/set-block/with-is-void/index.js create mode 100644 test/transforms/fixtures/set-block/with-is-void/input.yaml create mode 100644 test/transforms/fixtures/set-block/with-is-void/output.yaml create mode 100644 test/transforms/fixtures/set-inline/across-inlines/index.js create mode 100644 test/transforms/fixtures/set-inline/across-inlines/input.yaml create mode 100644 test/transforms/fixtures/set-inline/across-inlines/output.yaml create mode 100644 test/transforms/fixtures/set-inline/data-only/index.js create mode 100644 test/transforms/fixtures/set-inline/data-only/input.yaml create mode 100644 test/transforms/fixtures/set-inline/data-only/output.yaml create mode 100644 test/transforms/fixtures/set-inline/nested-inline/index.js create mode 100644 test/transforms/fixtures/set-inline/nested-inline/input.yaml create mode 100644 test/transforms/fixtures/set-inline/nested-inline/output.yaml create mode 100644 test/transforms/fixtures/set-inline/single-inline-string-shorthand/index.js create mode 100644 test/transforms/fixtures/set-inline/single-inline-string-shorthand/input.yaml create mode 100644 test/transforms/fixtures/set-inline/single-inline-string-shorthand/output.yaml create mode 100644 test/transforms/fixtures/set-inline/single-inline/index.js create mode 100644 test/transforms/fixtures/set-inline/single-inline/input.yaml create mode 100644 test/transforms/fixtures/set-inline/single-inline/output.yaml create mode 100644 test/transforms/fixtures/set-inline/with-data-object/index.js create mode 100644 test/transforms/fixtures/set-inline/with-data-object/input.yaml create mode 100644 test/transforms/fixtures/set-inline/with-data-object/output.yaml create mode 100644 test/transforms/fixtures/set-inline/with-data/index.js create mode 100644 test/transforms/fixtures/set-inline/with-data/input.yaml create mode 100644 test/transforms/fixtures/set-inline/with-data/output.yaml create mode 100644 test/transforms/fixtures/set-inline/with-is-void/index.js create mode 100644 test/transforms/fixtures/set-inline/with-is-void/input.yaml create mode 100644 test/transforms/fixtures/set-inline/with-is-void/output.yaml diff --git a/test/transforms/fixtures/set-block/across-blocks/index.js b/test/transforms/fixtures/set-block/across-blocks/index.js new file mode 100644 index 000000000..e7aacb5a0 --- /dev/null +++ b/test/transforms/fixtures/set-block/across-blocks/index.js @@ -0,0 +1,28 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const second = texts.last() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 2, + focusKey: second.key, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(range) + .setBlock({ type: 'code' }) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/set-block/across-blocks/input.yaml b/test/transforms/fixtures/set-block/across-blocks/input.yaml new file mode 100644 index 000000000..4960c06f9 --- /dev/null +++ b/test/transforms/fixtures/set-block/across-blocks/input.yaml @@ -0,0 +1,14 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: another diff --git a/test/transforms/fixtures/set-block/across-blocks/output.yaml b/test/transforms/fixtures/set-block/across-blocks/output.yaml new file mode 100644 index 000000000..885a28729 --- /dev/null +++ b/test/transforms/fixtures/set-block/across-blocks/output.yaml @@ -0,0 +1,14 @@ + +nodes: + - kind: block + type: code + nodes: + - kind: text + ranges: + - text: word + - kind: block + type: code + nodes: + - kind: text + ranges: + - text: another diff --git a/test/transforms/fixtures/set-block/across-inlines/index.js b/test/transforms/fixtures/set-block/across-inlines/index.js new file mode 100644 index 000000000..e7aacb5a0 --- /dev/null +++ b/test/transforms/fixtures/set-block/across-inlines/index.js @@ -0,0 +1,28 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const second = texts.last() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 2, + focusKey: second.key, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(range) + .setBlock({ type: 'code' }) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/set-block/across-inlines/input.yaml b/test/transforms/fixtures/set-block/across-inlines/input.yaml new file mode 100644 index 000000000..c31f583e3 --- /dev/null +++ b/test/transforms/fixtures/set-block/across-inlines/input.yaml @@ -0,0 +1,20 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: another diff --git a/test/transforms/fixtures/set-block/across-inlines/output.yaml b/test/transforms/fixtures/set-block/across-inlines/output.yaml new file mode 100644 index 000000000..33daef92b --- /dev/null +++ b/test/transforms/fixtures/set-block/across-inlines/output.yaml @@ -0,0 +1,20 @@ + +nodes: + - kind: block + type: code + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word + - kind: block + type: code + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: another diff --git a/test/transforms/fixtures/set-block/data-only/index.js b/test/transforms/fixtures/set-block/data-only/index.js new file mode 100644 index 000000000..86dd79e24 --- /dev/null +++ b/test/transforms/fixtures/set-block/data-only/index.js @@ -0,0 +1,28 @@ + +import { Data } from '../../../../..' +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 0, + focusKey: first.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .setBlock({ data: Data.create({ key: 'value' }) }) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/set-block/data-only/input.yaml b/test/transforms/fixtures/set-block/data-only/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/set-block/data-only/input.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-block/data-only/output.yaml b/test/transforms/fixtures/set-block/data-only/output.yaml new file mode 100644 index 000000000..591f9d1e1 --- /dev/null +++ b/test/transforms/fixtures/set-block/data-only/output.yaml @@ -0,0 +1,10 @@ + +nodes: + - kind: block + type: paragraph + data: + key: value + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-block/nested-block/index.js b/test/transforms/fixtures/set-block/nested-block/index.js new file mode 100644 index 000000000..78086bfd1 --- /dev/null +++ b/test/transforms/fixtures/set-block/nested-block/index.js @@ -0,0 +1,27 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 0, + focusKey: first.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .setBlock({ type: 'code' }) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/set-block/nested-block/input.yaml b/test/transforms/fixtures/set-block/nested-block/input.yaml new file mode 100644 index 000000000..ae0ad40e5 --- /dev/null +++ b/test/transforms/fixtures/set-block/nested-block/input.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-block/nested-block/output.yaml b/test/transforms/fixtures/set-block/nested-block/output.yaml new file mode 100644 index 000000000..9b66aa6c3 --- /dev/null +++ b/test/transforms/fixtures/set-block/nested-block/output.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: block + type: code + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-block/single-block-string-shorthand/index.js b/test/transforms/fixtures/set-block/single-block-string-shorthand/index.js new file mode 100644 index 000000000..94a44ba1c --- /dev/null +++ b/test/transforms/fixtures/set-block/single-block-string-shorthand/index.js @@ -0,0 +1,27 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 0, + focusKey: first.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .setBlock('code') + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/set-block/single-block-string-shorthand/input.yaml b/test/transforms/fixtures/set-block/single-block-string-shorthand/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/set-block/single-block-string-shorthand/input.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-block/single-block-string-shorthand/output.yaml b/test/transforms/fixtures/set-block/single-block-string-shorthand/output.yaml new file mode 100644 index 000000000..e20ab29e7 --- /dev/null +++ b/test/transforms/fixtures/set-block/single-block-string-shorthand/output.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: code + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-block/single-block/index.js b/test/transforms/fixtures/set-block/single-block/index.js new file mode 100644 index 000000000..78086bfd1 --- /dev/null +++ b/test/transforms/fixtures/set-block/single-block/index.js @@ -0,0 +1,27 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 0, + focusKey: first.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .setBlock({ type: 'code' }) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/set-block/single-block/input.yaml b/test/transforms/fixtures/set-block/single-block/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/set-block/single-block/input.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-block/single-block/output.yaml b/test/transforms/fixtures/set-block/single-block/output.yaml new file mode 100644 index 000000000..e20ab29e7 --- /dev/null +++ b/test/transforms/fixtures/set-block/single-block/output.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: code + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-block/with-data-object/index.js b/test/transforms/fixtures/set-block/with-data-object/index.js new file mode 100644 index 000000000..b86fe0b0b --- /dev/null +++ b/test/transforms/fixtures/set-block/with-data-object/index.js @@ -0,0 +1,30 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 0, + focusKey: first.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .setBlock({ + type: 'code', + data: { key: 'value' } + }) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/set-block/with-data-object/input.yaml b/test/transforms/fixtures/set-block/with-data-object/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/set-block/with-data-object/input.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-block/with-data-object/output.yaml b/test/transforms/fixtures/set-block/with-data-object/output.yaml new file mode 100644 index 000000000..f56d4e280 --- /dev/null +++ b/test/transforms/fixtures/set-block/with-data-object/output.yaml @@ -0,0 +1,10 @@ + +nodes: + - kind: block + type: code + data: + key: value + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-block/with-data/index.js b/test/transforms/fixtures/set-block/with-data/index.js new file mode 100644 index 000000000..7e06bbf96 --- /dev/null +++ b/test/transforms/fixtures/set-block/with-data/index.js @@ -0,0 +1,31 @@ + +import { Data } from '../../../../..' +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 0, + focusKey: first.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .setBlock({ + type: 'code', + data: Data.create({ key: 'value' }) + }) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/set-block/with-data/input.yaml b/test/transforms/fixtures/set-block/with-data/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/set-block/with-data/input.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-block/with-data/output.yaml b/test/transforms/fixtures/set-block/with-data/output.yaml new file mode 100644 index 000000000..f56d4e280 --- /dev/null +++ b/test/transforms/fixtures/set-block/with-data/output.yaml @@ -0,0 +1,10 @@ + +nodes: + - kind: block + type: code + data: + key: value + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-block/with-is-void/index.js b/test/transforms/fixtures/set-block/with-is-void/index.js new file mode 100644 index 000000000..459b8b054 --- /dev/null +++ b/test/transforms/fixtures/set-block/with-is-void/index.js @@ -0,0 +1,30 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 0, + focusKey: first.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .setBlock({ + type: 'image', + isVoid: true + }) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/set-block/with-is-void/input.yaml b/test/transforms/fixtures/set-block/with-is-void/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/set-block/with-is-void/input.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-block/with-is-void/output.yaml b/test/transforms/fixtures/set-block/with-is-void/output.yaml new file mode 100644 index 000000000..43146f431 --- /dev/null +++ b/test/transforms/fixtures/set-block/with-is-void/output.yaml @@ -0,0 +1,9 @@ + +nodes: + - kind: block + type: image + isVoid: true + nodes: + - kind: text + ranges: + - text: "" diff --git a/test/transforms/fixtures/set-inline/across-inlines/index.js b/test/transforms/fixtures/set-inline/across-inlines/index.js new file mode 100644 index 000000000..f107fe04d --- /dev/null +++ b/test/transforms/fixtures/set-inline/across-inlines/index.js @@ -0,0 +1,28 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const second = texts.last() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 2, + focusKey: second.key, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(range) + .setInline({ type: 'code' }) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/set-inline/across-inlines/input.yaml b/test/transforms/fixtures/set-inline/across-inlines/input.yaml new file mode 100644 index 000000000..c31f583e3 --- /dev/null +++ b/test/transforms/fixtures/set-inline/across-inlines/input.yaml @@ -0,0 +1,20 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: another diff --git a/test/transforms/fixtures/set-inline/across-inlines/output.yaml b/test/transforms/fixtures/set-inline/across-inlines/output.yaml new file mode 100644 index 000000000..4263a23c5 --- /dev/null +++ b/test/transforms/fixtures/set-inline/across-inlines/output.yaml @@ -0,0 +1,20 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: code + nodes: + - kind: text + ranges: + - text: word + - kind: block + type: paragraph + nodes: + - kind: inline + type: code + nodes: + - kind: text + ranges: + - text: another diff --git a/test/transforms/fixtures/set-inline/data-only/index.js b/test/transforms/fixtures/set-inline/data-only/index.js new file mode 100644 index 000000000..c9902910e --- /dev/null +++ b/test/transforms/fixtures/set-inline/data-only/index.js @@ -0,0 +1,28 @@ + +import { Data } from '../../../../..' +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 0, + focusKey: first.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .setInline({ data: Data.create({ key: 'value' }) }) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/set-inline/data-only/input.yaml b/test/transforms/fixtures/set-inline/data-only/input.yaml new file mode 100644 index 000000000..395351b4f --- /dev/null +++ b/test/transforms/fixtures/set-inline/data-only/input.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-inline/data-only/output.yaml b/test/transforms/fixtures/set-inline/data-only/output.yaml new file mode 100644 index 000000000..8dc03cf88 --- /dev/null +++ b/test/transforms/fixtures/set-inline/data-only/output.yaml @@ -0,0 +1,13 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + data: + key: value + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-inline/nested-inline/index.js b/test/transforms/fixtures/set-inline/nested-inline/index.js new file mode 100644 index 000000000..a442b35c7 --- /dev/null +++ b/test/transforms/fixtures/set-inline/nested-inline/index.js @@ -0,0 +1,27 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 0, + focusKey: first.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .setInline({ type: 'code' }) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/set-inline/nested-inline/input.yaml b/test/transforms/fixtures/set-inline/nested-inline/input.yaml new file mode 100644 index 000000000..6ed138519 --- /dev/null +++ b/test/transforms/fixtures/set-inline/nested-inline/input.yaml @@ -0,0 +1,14 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: hashtag + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-inline/nested-inline/output.yaml b/test/transforms/fixtures/set-inline/nested-inline/output.yaml new file mode 100644 index 000000000..b1b7e276e --- /dev/null +++ b/test/transforms/fixtures/set-inline/nested-inline/output.yaml @@ -0,0 +1,14 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: hashtag + nodes: + - kind: inline + type: code + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-inline/single-inline-string-shorthand/index.js b/test/transforms/fixtures/set-inline/single-inline-string-shorthand/index.js new file mode 100644 index 000000000..d333b8b6e --- /dev/null +++ b/test/transforms/fixtures/set-inline/single-inline-string-shorthand/index.js @@ -0,0 +1,27 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 0, + focusKey: first.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .setInline('code') + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/set-inline/single-inline-string-shorthand/input.yaml b/test/transforms/fixtures/set-inline/single-inline-string-shorthand/input.yaml new file mode 100644 index 000000000..395351b4f --- /dev/null +++ b/test/transforms/fixtures/set-inline/single-inline-string-shorthand/input.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-inline/single-inline-string-shorthand/output.yaml b/test/transforms/fixtures/set-inline/single-inline-string-shorthand/output.yaml new file mode 100644 index 000000000..5db5042f6 --- /dev/null +++ b/test/transforms/fixtures/set-inline/single-inline-string-shorthand/output.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: code + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-inline/single-inline/index.js b/test/transforms/fixtures/set-inline/single-inline/index.js new file mode 100644 index 000000000..a442b35c7 --- /dev/null +++ b/test/transforms/fixtures/set-inline/single-inline/index.js @@ -0,0 +1,27 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 0, + focusKey: first.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .setInline({ type: 'code' }) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/set-inline/single-inline/input.yaml b/test/transforms/fixtures/set-inline/single-inline/input.yaml new file mode 100644 index 000000000..395351b4f --- /dev/null +++ b/test/transforms/fixtures/set-inline/single-inline/input.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-inline/single-inline/output.yaml b/test/transforms/fixtures/set-inline/single-inline/output.yaml new file mode 100644 index 000000000..5db5042f6 --- /dev/null +++ b/test/transforms/fixtures/set-inline/single-inline/output.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: code + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-inline/with-data-object/index.js b/test/transforms/fixtures/set-inline/with-data-object/index.js new file mode 100644 index 000000000..7f78e0116 --- /dev/null +++ b/test/transforms/fixtures/set-inline/with-data-object/index.js @@ -0,0 +1,30 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 0, + focusKey: first.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .setInline({ + type: 'code', + data: { key: 'value' } + }) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/set-inline/with-data-object/input.yaml b/test/transforms/fixtures/set-inline/with-data-object/input.yaml new file mode 100644 index 000000000..395351b4f --- /dev/null +++ b/test/transforms/fixtures/set-inline/with-data-object/input.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-inline/with-data-object/output.yaml b/test/transforms/fixtures/set-inline/with-data-object/output.yaml new file mode 100644 index 000000000..0e2088cd8 --- /dev/null +++ b/test/transforms/fixtures/set-inline/with-data-object/output.yaml @@ -0,0 +1,13 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: code + data: + key: value + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-inline/with-data/index.js b/test/transforms/fixtures/set-inline/with-data/index.js new file mode 100644 index 000000000..d54658514 --- /dev/null +++ b/test/transforms/fixtures/set-inline/with-data/index.js @@ -0,0 +1,31 @@ + +import { Data } from '../../../../..' +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 0, + focusKey: first.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .setInline({ + type: 'code', + data: Data.create({ key: 'value' }) + }) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/set-inline/with-data/input.yaml b/test/transforms/fixtures/set-inline/with-data/input.yaml new file mode 100644 index 000000000..395351b4f --- /dev/null +++ b/test/transforms/fixtures/set-inline/with-data/input.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-inline/with-data/output.yaml b/test/transforms/fixtures/set-inline/with-data/output.yaml new file mode 100644 index 000000000..0e2088cd8 --- /dev/null +++ b/test/transforms/fixtures/set-inline/with-data/output.yaml @@ -0,0 +1,13 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: code + data: + key: value + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-inline/with-is-void/index.js b/test/transforms/fixtures/set-inline/with-is-void/index.js new file mode 100644 index 000000000..f33b19612 --- /dev/null +++ b/test/transforms/fixtures/set-inline/with-is-void/index.js @@ -0,0 +1,30 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 0, + focusKey: first.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .setInline({ + type: 'emoji', + isVoid: true + }) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/set-inline/with-is-void/input.yaml b/test/transforms/fixtures/set-inline/with-is-void/input.yaml new file mode 100644 index 000000000..395351b4f --- /dev/null +++ b/test/transforms/fixtures/set-inline/with-is-void/input.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/set-inline/with-is-void/output.yaml b/test/transforms/fixtures/set-inline/with-is-void/output.yaml new file mode 100644 index 000000000..1a0304231 --- /dev/null +++ b/test/transforms/fixtures/set-inline/with-is-void/output.yaml @@ -0,0 +1,12 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: emoji + isVoid: true + nodes: + - kind: text + ranges: + - text: ""