From 8bb5bc18409ecdeba4dd8f6127f25d047051eac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Wed, 26 Oct 2016 13:35:00 +0200 Subject: [PATCH] Add test for selection after the insertion --- .../after-selection/index.js | 28 +++++++++++++++++++ .../after-selection/input.yaml | 7 +++++ .../after-selection/output.yaml | 7 +++++ 3 files changed, 42 insertions(+) create mode 100644 test/transforms/fixtures/by-key/insert-text-by-key/after-selection/index.js create mode 100644 test/transforms/fixtures/by-key/insert-text-by-key/after-selection/input.yaml create mode 100644 test/transforms/fixtures/by-key/insert-text-by-key/after-selection/output.yaml diff --git a/test/transforms/fixtures/by-key/insert-text-by-key/after-selection/index.js b/test/transforms/fixtures/by-key/insert-text-by-key/after-selection/index.js new file mode 100644 index 000000000..c39c752a5 --- /dev/null +++ b/test/transforms/fixtures/by-key/insert-text-by-key/after-selection/index.js @@ -0,0 +1,28 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const firstText = texts.first() + + const nextSelection = selection.merge({ + anchorKey: firstText.key, + focusKey: firstText.key, + anchorOffset: 2, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(nextSelection) + .insertTextByKey(firstText.key, 5, 'XX') + .apply() + + assert.deepEqual( + next.selection.toJS(), + nextSelection.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/by-key/insert-text-by-key/after-selection/input.yaml b/test/transforms/fixtures/by-key/insert-text-by-key/after-selection/input.yaml new file mode 100644 index 000000000..98adb1781 --- /dev/null +++ b/test/transforms/fixtures/by-key/insert-text-by-key/after-selection/input.yaml @@ -0,0 +1,7 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + text: hello diff --git a/test/transforms/fixtures/by-key/insert-text-by-key/after-selection/output.yaml b/test/transforms/fixtures/by-key/insert-text-by-key/after-selection/output.yaml new file mode 100644 index 000000000..c3dba6a90 --- /dev/null +++ b/test/transforms/fixtures/by-key/insert-text-by-key/after-selection/output.yaml @@ -0,0 +1,7 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + text: helloXX