From f8f01949e404685facd886502273ffaac9b20420 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Fri, 22 Jul 2016 20:22:01 -0700 Subject: [PATCH] add tests for insertText with marks --- .../insert-text-at-range/with-marks/index.js | 25 ++++++++++++++ .../with-marks/input.yaml | 8 +++++ .../with-marks/output.yaml | 11 ++++++ .../fixtures/insert-text/with-marks/index.js | 34 +++++++++++++++++++ .../insert-text/with-marks/input.yaml | 8 +++++ .../insert-text/with-marks/output.yaml | 11 ++++++ 6 files changed, 97 insertions(+) create mode 100644 test/transforms/fixtures/insert-text-at-range/with-marks/index.js create mode 100644 test/transforms/fixtures/insert-text-at-range/with-marks/input.yaml create mode 100644 test/transforms/fixtures/insert-text-at-range/with-marks/output.yaml create mode 100644 test/transforms/fixtures/insert-text/with-marks/index.js create mode 100644 test/transforms/fixtures/insert-text/with-marks/input.yaml create mode 100644 test/transforms/fixtures/insert-text/with-marks/output.yaml diff --git a/test/transforms/fixtures/insert-text-at-range/with-marks/index.js b/test/transforms/fixtures/insert-text-at-range/with-marks/index.js new file mode 100644 index 000000000..187bae62f --- /dev/null +++ b/test/transforms/fixtures/insert-text-at-range/with-marks/index.js @@ -0,0 +1,25 @@ + +import { Mark } from '../../../../..' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: first.length, + focusKey: first.key, + focusOffset: first.length + }) + + const marks = Mark.createSet([ + Mark.create({ + type: 'bold' + }) + ]) + + return state + .transform() + .insertTextAtRange(range, 'a', marks) + .apply() +} diff --git a/test/transforms/fixtures/insert-text-at-range/with-marks/input.yaml b/test/transforms/fixtures/insert-text-at-range/with-marks/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/insert-text-at-range/with-marks/input.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/insert-text-at-range/with-marks/output.yaml b/test/transforms/fixtures/insert-text-at-range/with-marks/output.yaml new file mode 100644 index 000000000..5f30e04cf --- /dev/null +++ b/test/transforms/fixtures/insert-text-at-range/with-marks/output.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word + - text: a + marks: + - type: bold diff --git a/test/transforms/fixtures/insert-text/with-marks/index.js b/test/transforms/fixtures/insert-text/with-marks/index.js new file mode 100644 index 000000000..040809a9c --- /dev/null +++ b/test/transforms/fixtures/insert-text/with-marks/index.js @@ -0,0 +1,34 @@ + +import { Mark } 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: first.length, + focusKey: first.key, + focusOffset: first.length + }) + + const marks = Mark.createSet([ + Mark.create({ + type: 'bold' + }) + ]) + + const next = state + .transform() + .moveTo(range) + .insertText('a', marks) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.moveForward().toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/insert-text/with-marks/input.yaml b/test/transforms/fixtures/insert-text/with-marks/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/insert-text/with-marks/input.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/insert-text/with-marks/output.yaml b/test/transforms/fixtures/insert-text/with-marks/output.yaml new file mode 100644 index 000000000..5f30e04cf --- /dev/null +++ b/test/transforms/fixtures/insert-text/with-marks/output.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word + - text: a + marks: + - type: bold