From eb95b79a004d03c4b1d0d4046a5a5d86d76ebf6e Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Thu, 21 Jul 2016 16:03:02 -0700 Subject: [PATCH] add wrapInline transform tests --- .../wrap-inline/across-blocks/index.js | 36 +++++++++++++++++++ .../wrap-inline/across-blocks/input.yaml | 14 ++++++++ .../wrap-inline/across-blocks/output.yaml | 26 ++++++++++++++ .../wrap-inline/across-inlines/index.js | 36 +++++++++++++++++++ .../wrap-inline/across-inlines/input.yaml | 17 +++++++++ .../wrap-inline/across-inlines/output.yaml | 35 ++++++++++++++++++ .../wrap-inline/nested-block/index.js | 34 ++++++++++++++++++ .../wrap-inline/nested-block/input.yaml | 11 ++++++ .../wrap-inline/nested-block/output.yaml | 20 +++++++++++ .../wrap-inline/single-block/index.js | 34 ++++++++++++++++++ .../wrap-inline/single-block/input.yaml | 8 +++++ .../wrap-inline/single-block/output.yaml | 17 +++++++++ .../wrap-inline/with-data-object/index.js | 34 ++++++++++++++++++ .../wrap-inline/with-data-object/input.yaml | 8 +++++ .../wrap-inline/with-data-object/output.yaml | 19 ++++++++++ .../fixtures/wrap-inline/with-data/index.js | 35 ++++++++++++++++++ .../fixtures/wrap-inline/with-data/input.yaml | 8 +++++ .../wrap-inline/with-data/output.yaml | 19 ++++++++++ 18 files changed, 411 insertions(+) create mode 100644 test/transforms/fixtures/wrap-inline/across-blocks/index.js create mode 100644 test/transforms/fixtures/wrap-inline/across-blocks/input.yaml create mode 100644 test/transforms/fixtures/wrap-inline/across-blocks/output.yaml create mode 100644 test/transforms/fixtures/wrap-inline/across-inlines/index.js create mode 100644 test/transforms/fixtures/wrap-inline/across-inlines/input.yaml create mode 100644 test/transforms/fixtures/wrap-inline/across-inlines/output.yaml create mode 100644 test/transforms/fixtures/wrap-inline/nested-block/index.js create mode 100644 test/transforms/fixtures/wrap-inline/nested-block/input.yaml create mode 100644 test/transforms/fixtures/wrap-inline/nested-block/output.yaml create mode 100644 test/transforms/fixtures/wrap-inline/single-block/index.js create mode 100644 test/transforms/fixtures/wrap-inline/single-block/input.yaml create mode 100644 test/transforms/fixtures/wrap-inline/single-block/output.yaml create mode 100644 test/transforms/fixtures/wrap-inline/with-data-object/index.js create mode 100644 test/transforms/fixtures/wrap-inline/with-data-object/input.yaml create mode 100644 test/transforms/fixtures/wrap-inline/with-data-object/output.yaml create mode 100644 test/transforms/fixtures/wrap-inline/with-data/index.js create mode 100644 test/transforms/fixtures/wrap-inline/with-data/input.yaml create mode 100644 test/transforms/fixtures/wrap-inline/with-data/output.yaml diff --git a/test/transforms/fixtures/wrap-inline/across-blocks/index.js b/test/transforms/fixtures/wrap-inline/across-blocks/index.js new file mode 100644 index 000000000..67102af9d --- /dev/null +++ b/test/transforms/fixtures/wrap-inline/across-blocks/index.js @@ -0,0 +1,36 @@ + +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) + .wrapInline('hashtag') + .apply() + + const two = next.document.getTexts().get(1) + const three = next.document.getTexts().get(2) + + // assert.deepEqual( + // next.selection.toJS(), + // range.merge({ + // anchorKey: two.key, + // anchorOffset: 0, + // focusKey: three.key, + // focusOffset: three.length + // }).toJS() + // ) + + return next +} diff --git a/test/transforms/fixtures/wrap-inline/across-blocks/input.yaml b/test/transforms/fixtures/wrap-inline/across-blocks/input.yaml new file mode 100644 index 000000000..4960c06f9 --- /dev/null +++ b/test/transforms/fixtures/wrap-inline/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/wrap-inline/across-blocks/output.yaml b/test/transforms/fixtures/wrap-inline/across-blocks/output.yaml new file mode 100644 index 000000000..2fabb8799 --- /dev/null +++ b/test/transforms/fixtures/wrap-inline/across-blocks/output.yaml @@ -0,0 +1,26 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: wo + - kind: inline + type: hashtag + nodes: + - kind: text + ranges: + - text: rd + - kind: block + type: paragraph + nodes: + - kind: inline + type: hashtag + nodes: + - kind: text + ranges: + - text: an + - kind: text + ranges: + - text: other diff --git a/test/transforms/fixtures/wrap-inline/across-inlines/index.js b/test/transforms/fixtures/wrap-inline/across-inlines/index.js new file mode 100644 index 000000000..67102af9d --- /dev/null +++ b/test/transforms/fixtures/wrap-inline/across-inlines/index.js @@ -0,0 +1,36 @@ + +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) + .wrapInline('hashtag') + .apply() + + const two = next.document.getTexts().get(1) + const three = next.document.getTexts().get(2) + + // assert.deepEqual( + // next.selection.toJS(), + // range.merge({ + // anchorKey: two.key, + // anchorOffset: 0, + // focusKey: three.key, + // focusOffset: three.length + // }).toJS() + // ) + + return next +} diff --git a/test/transforms/fixtures/wrap-inline/across-inlines/input.yaml b/test/transforms/fixtures/wrap-inline/across-inlines/input.yaml new file mode 100644 index 000000000..877fc950a --- /dev/null +++ b/test/transforms/fixtures/wrap-inline/across-inlines/input.yaml @@ -0,0 +1,17 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: another diff --git a/test/transforms/fixtures/wrap-inline/across-inlines/output.yaml b/test/transforms/fixtures/wrap-inline/across-inlines/output.yaml new file mode 100644 index 000000000..21f86cab1 --- /dev/null +++ b/test/transforms/fixtures/wrap-inline/across-inlines/output.yaml @@ -0,0 +1,35 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: wo + - kind: inline + type: hashtag + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: rd + - kind: inline + type: hashtag + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: an + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: other diff --git a/test/transforms/fixtures/wrap-inline/nested-block/index.js b/test/transforms/fixtures/wrap-inline/nested-block/index.js new file mode 100644 index 000000000..fb1b8087e --- /dev/null +++ b/test/transforms/fixtures/wrap-inline/nested-block/index.js @@ -0,0 +1,34 @@ + +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: 1, + focusKey: first.key, + focusOffset: 3 + }) + + const next = state + .transform() + .moveTo(range) + .wrapInline('hashtag') + .apply() + + const updated = next.document.getTexts().get(1) + + assert.deepEqual( + next.selection.toJS(), + range.merge({ + anchorKey: updated.key, + anchorOffset: 0, + focusKey: updated.key, + focusOffset: updated.length + }).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/wrap-inline/nested-block/input.yaml b/test/transforms/fixtures/wrap-inline/nested-block/input.yaml new file mode 100644 index 000000000..c4ac2e6c5 --- /dev/null +++ b/test/transforms/fixtures/wrap-inline/nested-block/input.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: quote + nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/wrap-inline/nested-block/output.yaml b/test/transforms/fixtures/wrap-inline/nested-block/output.yaml new file mode 100644 index 000000000..8847000bf --- /dev/null +++ b/test/transforms/fixtures/wrap-inline/nested-block/output.yaml @@ -0,0 +1,20 @@ + +nodes: + - kind: block + type: quote + nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: w + - kind: inline + type: hashtag + nodes: + - kind: text + ranges: + - text: or + - kind: text + ranges: + - text: d diff --git a/test/transforms/fixtures/wrap-inline/single-block/index.js b/test/transforms/fixtures/wrap-inline/single-block/index.js new file mode 100644 index 000000000..fb1b8087e --- /dev/null +++ b/test/transforms/fixtures/wrap-inline/single-block/index.js @@ -0,0 +1,34 @@ + +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: 1, + focusKey: first.key, + focusOffset: 3 + }) + + const next = state + .transform() + .moveTo(range) + .wrapInline('hashtag') + .apply() + + const updated = next.document.getTexts().get(1) + + assert.deepEqual( + next.selection.toJS(), + range.merge({ + anchorKey: updated.key, + anchorOffset: 0, + focusKey: updated.key, + focusOffset: updated.length + }).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/wrap-inline/single-block/input.yaml b/test/transforms/fixtures/wrap-inline/single-block/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/wrap-inline/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/wrap-inline/single-block/output.yaml b/test/transforms/fixtures/wrap-inline/single-block/output.yaml new file mode 100644 index 000000000..fc07c88f4 --- /dev/null +++ b/test/transforms/fixtures/wrap-inline/single-block/output.yaml @@ -0,0 +1,17 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: w + - kind: inline + type: hashtag + nodes: + - kind: text + ranges: + - text: or + - kind: text + ranges: + - text: d diff --git a/test/transforms/fixtures/wrap-inline/with-data-object/index.js b/test/transforms/fixtures/wrap-inline/with-data-object/index.js new file mode 100644 index 000000000..5e3ac2f60 --- /dev/null +++ b/test/transforms/fixtures/wrap-inline/with-data-object/index.js @@ -0,0 +1,34 @@ + +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: 1, + focusKey: first.key, + focusOffset: 3 + }) + + const next = state + .transform() + .moveTo(range) + .wrapInline('hashtag', { key: 'value' }) + .apply() + + const updated = next.document.getTexts().get(1) + + assert.deepEqual( + next.selection.toJS(), + range.merge({ + anchorKey: updated.key, + anchorOffset: 0, + focusKey: updated.key, + focusOffset: updated.length + }).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/wrap-inline/with-data-object/input.yaml b/test/transforms/fixtures/wrap-inline/with-data-object/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/wrap-inline/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/wrap-inline/with-data-object/output.yaml b/test/transforms/fixtures/wrap-inline/with-data-object/output.yaml new file mode 100644 index 000000000..0d3866aa6 --- /dev/null +++ b/test/transforms/fixtures/wrap-inline/with-data-object/output.yaml @@ -0,0 +1,19 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: w + - kind: inline + type: hashtag + data: + key: value + nodes: + - kind: text + ranges: + - text: or + - kind: text + ranges: + - text: d diff --git a/test/transforms/fixtures/wrap-inline/with-data/index.js b/test/transforms/fixtures/wrap-inline/with-data/index.js new file mode 100644 index 000000000..68a698c0e --- /dev/null +++ b/test/transforms/fixtures/wrap-inline/with-data/index.js @@ -0,0 +1,35 @@ + +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: 1, + focusKey: first.key, + focusOffset: 3 + }) + + const next = state + .transform() + .moveTo(range) + .wrapInline('hashtag', Data.create({ key: 'value' })) + .apply() + + const updated = next.document.getTexts().get(1) + + assert.deepEqual( + next.selection.toJS(), + range.merge({ + anchorKey: updated.key, + anchorOffset: 0, + focusKey: updated.key, + focusOffset: updated.length + }).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/wrap-inline/with-data/input.yaml b/test/transforms/fixtures/wrap-inline/with-data/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/wrap-inline/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/wrap-inline/with-data/output.yaml b/test/transforms/fixtures/wrap-inline/with-data/output.yaml new file mode 100644 index 000000000..0d3866aa6 --- /dev/null +++ b/test/transforms/fixtures/wrap-inline/with-data/output.yaml @@ -0,0 +1,19 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: w + - kind: inline + type: hashtag + data: + key: value + nodes: + - kind: text + ranges: + - text: or + - kind: text + ranges: + - text: d