2019-10-30 21:48:24 +08:00
|
|
|
import { next } from "@ember/runloop";
|
2018-06-15 23:03:24 +08:00
|
|
|
import componentTest from "helpers/component-test";
|
2019-06-17 16:24:20 +08:00
|
|
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
2019-06-05 20:52:38 +08:00
|
|
|
import formatTextWithSelection from "helpers/d-editor-helper";
|
2019-06-06 01:20:46 +08:00
|
|
|
import {
|
|
|
|
setTextareaSelection,
|
|
|
|
getTextareaSelection
|
|
|
|
} from "helpers/textarea-selection-helper";
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
moduleForComponent("d-editor", { integration: true });
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("preview updates with markdown", {
|
|
|
|
template: "{{d-editor value=value}}",
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
async test(assert) {
|
2019-02-25 23:04:55 +08:00
|
|
|
assert.ok(find(".d-editor-button-bar").length);
|
2018-07-30 04:51:32 +08:00
|
|
|
await fillIn(".d-editor-input", "hello **world**");
|
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "hello **world**");
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(
|
2019-02-25 23:04:55 +08:00
|
|
|
find(".d-editor-preview")
|
2018-07-30 04:51:32 +08:00
|
|
|
.html()
|
|
|
|
.trim(),
|
|
|
|
"<p>hello <strong>world</strong></p>"
|
|
|
|
);
|
2015-09-29 02:01:16 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("preview sanitizes HTML", {
|
|
|
|
template: "{{d-editor value=value}}",
|
2015-10-21 00:09:59 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
async test(assert) {
|
|
|
|
await fillIn(".d-editor-input", `"><svg onload="prompt(/xss/)"></svg>`);
|
|
|
|
assert.equal(
|
2019-02-25 23:04:55 +08:00
|
|
|
find(".d-editor-preview")
|
2018-07-30 04:51:32 +08:00
|
|
|
.html()
|
|
|
|
.trim(),
|
|
|
|
'<p>"></p>'
|
|
|
|
);
|
2015-10-21 00:09:59 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("updating the value refreshes the preview", {
|
|
|
|
template: "{{d-editor value=value}}",
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("value", "evil trout");
|
2015-09-29 02:01:16 +08:00
|
|
|
},
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
async test(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.equal(
|
2019-02-25 23:04:55 +08:00
|
|
|
find(".d-editor-preview")
|
2018-06-15 23:03:24 +08:00
|
|
|
.html()
|
|
|
|
.trim(),
|
|
|
|
"<p>evil trout</p>"
|
|
|
|
);
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await this.set("value", "zogstrip");
|
|
|
|
assert.equal(
|
2019-02-25 23:04:55 +08:00
|
|
|
find(".d-editor-preview")
|
2018-07-30 04:51:32 +08:00
|
|
|
.html()
|
|
|
|
.trim(),
|
|
|
|
"<p>zogstrip</p>"
|
2018-06-15 23:03:24 +08:00
|
|
|
);
|
2015-09-29 02:01:16 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-11-07 05:44:38 +08:00
|
|
|
function jumpEnd(textarea) {
|
|
|
|
textarea.selectionStart = textarea.value.length;
|
|
|
|
textarea.selectionEnd = textarea.value.length;
|
|
|
|
return textarea;
|
|
|
|
}
|
|
|
|
|
2015-09-29 02:01:16 +08:00
|
|
|
function testCase(title, testFunc) {
|
|
|
|
componentTest(title, {
|
2018-06-15 23:03:24 +08:00
|
|
|
template: "{{d-editor value=value}}",
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("value", "hello world.");
|
2015-09-29 02:01:16 +08:00
|
|
|
},
|
|
|
|
test(assert) {
|
2019-02-25 23:04:55 +08:00
|
|
|
const textarea = jumpEnd(find("textarea.d-editor-input")[0]);
|
2015-09-29 02:01:16 +08:00
|
|
|
testFunc.call(this, assert, textarea);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-06 00:59:34 +08:00
|
|
|
function composerTestCase(title, testFunc) {
|
|
|
|
componentTest(title, {
|
2018-06-15 23:03:24 +08:00
|
|
|
template: "{{d-editor value=value composerEvents=true}}",
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("value", "hello world.");
|
2017-05-06 00:59:34 +08:00
|
|
|
},
|
|
|
|
test(assert) {
|
2019-02-25 23:04:55 +08:00
|
|
|
const textarea = jumpEnd(find("textarea.d-editor-input")[0]);
|
2017-05-06 00:59:34 +08:00
|
|
|
testFunc.call(this, assert, textarea);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
testCase(`selecting the space before a word`, async function(assert, textarea) {
|
2016-03-10 19:43:08 +08:00
|
|
|
textarea.selectionStart = 5;
|
|
|
|
textarea.selectionEnd = 7;
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.bold`);
|
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, `hello **w**orld.`);
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 8);
|
|
|
|
assert.equal(textarea.selectionEnd, 9);
|
2016-03-10 19:43:08 +08:00
|
|
|
});
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
testCase(`selecting the space after a word`, async function(assert, textarea) {
|
2015-11-25 02:41:56 +08:00
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = 6;
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.bold`);
|
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, `**hello** world.`);
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 2);
|
|
|
|
assert.equal(textarea.selectionEnd, 7);
|
2015-11-25 02:41:56 +08:00
|
|
|
});
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
testCase(`bold button with no selection`, async function(assert, textarea) {
|
|
|
|
await click(`button.bold`);
|
|
|
|
|
|
|
|
const example = I18n.t(`composer.bold_text`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, `hello world.**${example}**`);
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 14);
|
|
|
|
assert.equal(textarea.selectionEnd, 14 + example.length);
|
2015-09-29 02:01:16 +08:00
|
|
|
});
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
testCase(`bold button with a selection`, async function(assert, textarea) {
|
2015-09-29 02:01:16 +08:00
|
|
|
textarea.selectionStart = 6;
|
|
|
|
textarea.selectionEnd = 11;
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.bold`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, `hello **world**.`);
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 8);
|
|
|
|
assert.equal(textarea.selectionEnd, 13);
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.bold`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "hello world.");
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 6);
|
|
|
|
assert.equal(textarea.selectionEnd, 11);
|
2015-09-29 02:01:16 +08:00
|
|
|
});
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
testCase(`bold with a multiline selection`, async function(assert, textarea) {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("value", "hello\n\nworld\n\ntest.");
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = 12;
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.bold`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, `**hello**\n\n**world**\n\ntest.`);
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 0);
|
|
|
|
assert.equal(textarea.selectionEnd, 20);
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.bold`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, `hello\n\nworld\n\ntest.`);
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 0);
|
|
|
|
assert.equal(textarea.selectionEnd, 12);
|
2015-09-29 02:01:16 +08:00
|
|
|
});
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
testCase(`italic button with no selection`, async function(assert, textarea) {
|
|
|
|
await click(`button.italic`);
|
|
|
|
const example = I18n.t(`composer.italic_text`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, `hello world.*${example}*`);
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 13);
|
|
|
|
assert.equal(textarea.selectionEnd, 13 + example.length);
|
2015-09-29 02:01:16 +08:00
|
|
|
});
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
testCase(`italic button with a selection`, async function(assert, textarea) {
|
2015-09-29 02:01:16 +08:00
|
|
|
textarea.selectionStart = 6;
|
|
|
|
textarea.selectionEnd = 11;
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.italic`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, `hello *world*.`);
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 7);
|
|
|
|
assert.equal(textarea.selectionEnd, 12);
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.italic`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "hello world.");
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 6);
|
|
|
|
assert.equal(textarea.selectionEnd, 11);
|
2015-09-29 02:01:16 +08:00
|
|
|
});
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
testCase(`italic with a multiline selection`, async function(assert, textarea) {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("value", "hello\n\nworld\n\ntest.");
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = 12;
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.italic`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, `*hello*\n\n*world*\n\ntest.`);
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 0);
|
|
|
|
assert.equal(textarea.selectionEnd, 16);
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.italic`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, `hello\n\nworld\n\ntest.`);
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 0);
|
|
|
|
assert.equal(textarea.selectionEnd, 12);
|
2015-09-29 02:01:16 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("advanced code", {
|
|
|
|
template: "{{d-editor value=value}}",
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.siteSettings.code_formatting_style = "4-spaces-indent";
|
|
|
|
this.set(
|
|
|
|
"value",
|
|
|
|
`
|
2016-08-23 09:51:01 +08:00
|
|
|
function xyz(x, y, z) {
|
2015-11-25 02:03:37 +08:00
|
|
|
if (y === z) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-08-23 09:51:01 +08:00
|
|
|
}
|
2018-06-15 23:03:24 +08:00
|
|
|
`
|
|
|
|
);
|
2015-11-25 02:03:37 +08:00
|
|
|
},
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
async test(assert) {
|
2019-02-25 23:04:55 +08:00
|
|
|
const textarea = find("textarea.d-editor-input")[0];
|
2015-11-25 02:41:56 +08:00
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = textarea.value.length;
|
2015-11-25 02:03:37 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.code");
|
|
|
|
assert.equal(
|
2019-05-27 16:15:39 +08:00
|
|
|
this.value,
|
2018-07-30 04:51:32 +08:00
|
|
|
`
|
2016-08-23 09:51:01 +08:00
|
|
|
function xyz(x, y, z) {
|
2015-11-25 02:03:37 +08:00
|
|
|
if (y === z) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-08-23 09:51:01 +08:00
|
|
|
}
|
|
|
|
`
|
2018-07-30 04:51:32 +08:00
|
|
|
);
|
2015-11-25 02:03:37 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("code button", {
|
|
|
|
template: "{{d-editor value=value}}",
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.siteSettings.code_formatting_style = "4-spaces-indent";
|
2015-09-29 02:01:16 +08:00
|
|
|
},
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
async test(assert) {
|
2019-02-25 23:04:55 +08:00
|
|
|
const textarea = jumpEnd(find("textarea.d-editor-input")[0]);
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.code");
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, ` ${I18n.t("composer.code_text")}`);
|
2016-08-23 14:56:08 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
this.set("value", "first line\n\nsecond line\n\nthird line");
|
2016-08-23 14:56:08 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
textarea.selectionStart = 11;
|
|
|
|
textarea.selectionEnd = 11;
|
2016-08-23 14:56:08 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.code");
|
|
|
|
assert.equal(
|
2019-05-27 16:15:39 +08:00
|
|
|
this.value,
|
2018-07-30 04:51:32 +08:00
|
|
|
`first line
|
2018-06-15 23:03:24 +08:00
|
|
|
${I18n.t("composer.code_text")}
|
2016-08-23 14:56:08 +08:00
|
|
|
second line
|
|
|
|
|
|
|
|
third line`
|
2018-07-30 04:51:32 +08:00
|
|
|
);
|
2016-08-23 14:56:08 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
this.set("value", "first line\n\nsecond line\n\nthird line");
|
2016-08-23 14:56:08 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.code");
|
|
|
|
assert.equal(
|
2019-05-27 16:15:39 +08:00
|
|
|
this.value,
|
2018-07-30 04:51:32 +08:00
|
|
|
`first line
|
2016-08-23 14:56:08 +08:00
|
|
|
|
|
|
|
second line
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
third line\`${I18n.t("composer.code_title")}\``
|
2018-07-30 04:51:32 +08:00
|
|
|
);
|
|
|
|
this.set("value", "first line\n\nsecond line\n\nthird line");
|
2016-08-23 14:56:08 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
textarea.selectionStart = 5;
|
|
|
|
textarea.selectionEnd = 5;
|
2016-08-23 14:56:08 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.code");
|
|
|
|
assert.equal(
|
2019-05-27 16:15:39 +08:00
|
|
|
this.value,
|
2018-07-30 04:51:32 +08:00
|
|
|
`first\`${I18n.t("composer.code_title")}\` line
|
2016-08-23 14:56:08 +08:00
|
|
|
|
|
|
|
second line
|
|
|
|
|
|
|
|
third line`
|
2018-07-30 04:51:32 +08:00
|
|
|
);
|
|
|
|
this.set("value", "first line\n\nsecond line\n\nthird line");
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
textarea.selectionStart = 6;
|
|
|
|
textarea.selectionEnd = 10;
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.code");
|
2019-05-27 16:42:53 +08:00
|
|
|
assert.equal(this.value, "first `line`\n\nsecond line\n\nthird line");
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 7);
|
|
|
|
assert.equal(textarea.selectionEnd, 11);
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.code");
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "first line\n\nsecond line\n\nthird line");
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 6);
|
|
|
|
assert.equal(textarea.selectionEnd, 10);
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = 23;
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.code");
|
2019-05-27 16:42:53 +08:00
|
|
|
assert.equal(this.value, " first line\n\n second line\n\nthird line");
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 0);
|
|
|
|
assert.equal(textarea.selectionEnd, 31);
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.code");
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "first line\n\nsecond line\n\nthird line");
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 0);
|
|
|
|
assert.equal(textarea.selectionEnd, 23);
|
2015-09-29 02:01:16 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("code fences", {
|
|
|
|
template: "{{d-editor value=value}}",
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("value", "");
|
2016-08-23 09:51:01 +08:00
|
|
|
},
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
async test(assert) {
|
2019-02-25 23:04:55 +08:00
|
|
|
const textarea = jumpEnd(find("textarea.d-editor-input")[0]);
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.code");
|
|
|
|
assert.equal(
|
2019-05-27 16:15:39 +08:00
|
|
|
this.value,
|
2018-07-30 04:51:32 +08:00
|
|
|
`\`\`\`
|
2016-08-23 09:51:01 +08:00
|
|
|
${I18n.t("composer.paste_code_text")}
|
2016-08-23 14:56:08 +08:00
|
|
|
\`\`\``
|
2018-07-30 04:51:32 +08:00
|
|
|
);
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 4);
|
|
|
|
assert.equal(textarea.selectionEnd, 27);
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
this.set("value", "first line\nsecond line\nthird line");
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = textarea.value.length;
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.code");
|
|
|
|
|
|
|
|
assert.equal(
|
2019-05-27 16:15:39 +08:00
|
|
|
this.value,
|
2018-07-30 04:51:32 +08:00
|
|
|
`\`\`\`
|
2016-08-23 09:51:01 +08:00
|
|
|
first line
|
|
|
|
second line
|
|
|
|
third line
|
|
|
|
\`\`\`
|
|
|
|
`
|
2018-07-30 04:51:32 +08:00
|
|
|
);
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, textarea.value.length);
|
|
|
|
assert.equal(textarea.selectionEnd, textarea.value.length);
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
this.set("value", "first line\nsecond line\nthird line");
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = 0;
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.code");
|
|
|
|
|
|
|
|
assert.equal(
|
2019-05-27 16:15:39 +08:00
|
|
|
this.value,
|
2018-07-30 04:51:32 +08:00
|
|
|
`\`${I18n.t("composer.code_title")}\`first line
|
2016-08-23 09:51:01 +08:00
|
|
|
second line
|
|
|
|
third line`
|
2018-07-30 04:51:32 +08:00
|
|
|
);
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 1);
|
|
|
|
assert.equal(
|
|
|
|
textarea.selectionEnd,
|
|
|
|
I18n.t("composer.code_title").length + 1
|
|
|
|
);
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
this.set("value", "first line\nsecond line\nthird line");
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = 10;
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.code");
|
|
|
|
|
|
|
|
assert.equal(
|
2019-05-27 16:15:39 +08:00
|
|
|
this.value,
|
2018-07-30 04:51:32 +08:00
|
|
|
`\`first line\`
|
2016-08-23 09:51:01 +08:00
|
|
|
second line
|
|
|
|
third line`
|
2018-07-30 04:51:32 +08:00
|
|
|
);
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 1);
|
|
|
|
assert.equal(textarea.selectionEnd, 11);
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
this.set("value", "first line\nsecond line\nthird line");
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = 23;
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.code");
|
|
|
|
|
|
|
|
assert.equal(
|
2019-05-27 16:15:39 +08:00
|
|
|
this.value,
|
2018-07-30 04:51:32 +08:00
|
|
|
`\`\`\`
|
2016-08-23 09:51:01 +08:00
|
|
|
first line
|
|
|
|
second line
|
|
|
|
\`\`\`
|
|
|
|
third line`
|
2018-07-30 04:51:32 +08:00
|
|
|
);
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 30);
|
|
|
|
assert.equal(textarea.selectionEnd, 30);
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
this.set("value", "first line\nsecond line\nthird line");
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
textarea.selectionStart = 6;
|
|
|
|
textarea.selectionEnd = 17;
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.code");
|
2016-08-23 09:51:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(
|
2019-05-27 16:15:39 +08:00
|
|
|
this.value,
|
2018-07-30 04:51:32 +08:00
|
|
|
`first \n\`\`\`\nline\nsecond\n\`\`\`\n line\nthird line`
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(textarea.selectionStart, 27);
|
|
|
|
assert.equal(textarea.selectionEnd, 27);
|
2016-08-23 09:51:01 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-07-22 04:32:10 +08:00
|
|
|
componentTest("quote button - empty lines", {
|
2018-06-15 23:03:24 +08:00
|
|
|
template: "{{d-editor value=value composerEvents=true}}",
|
2017-07-22 04:32:10 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("value", "one\n\ntwo\n\nthree");
|
2017-07-22 04:32:10 +08:00
|
|
|
},
|
2018-07-30 04:51:32 +08:00
|
|
|
async test(assert) {
|
2019-02-25 23:04:55 +08:00
|
|
|
const textarea = jumpEnd(find("textarea.d-editor-input")[0]);
|
2017-07-22 04:32:10 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
textarea.selectionStart = 0;
|
2017-07-22 04:32:10 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.quote");
|
2017-07-22 04:32:10 +08:00
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "> one\n> \n> two\n> \n> three");
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 0);
|
|
|
|
assert.equal(textarea.selectionEnd, 25);
|
|
|
|
|
|
|
|
await click("button.quote");
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "one\n\ntwo\n\nthree");
|
2017-07-22 04:32:10 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-11-21 02:46:19 +08:00
|
|
|
componentTest("quote button - selecting empty lines", {
|
2018-06-15 23:03:24 +08:00
|
|
|
template: "{{d-editor value=value composerEvents=true}}",
|
2017-11-21 02:46:19 +08:00
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("value", "one\n\n\n\ntwo");
|
2017-11-21 02:46:19 +08:00
|
|
|
},
|
2018-07-30 04:51:32 +08:00
|
|
|
async test(assert) {
|
2019-02-25 23:04:55 +08:00
|
|
|
const textarea = jumpEnd(find("textarea.d-editor-input")[0]);
|
2017-11-21 02:46:19 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
textarea.selectionStart = 6;
|
|
|
|
textarea.selectionEnd = 10;
|
2017-11-21 02:46:19 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.quote");
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "one\n\n\n> \n> two");
|
2017-11-21 02:46:19 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
testCase("quote button", async function(assert, textarea) {
|
|
|
|
textarea.selectionStart = 6;
|
|
|
|
textarea.selectionEnd = 9;
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.quote");
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "hello\n\n> wor\n\nld.");
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 7);
|
|
|
|
assert.equal(textarea.selectionEnd, 12);
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.quote");
|
2017-06-28 01:32:20 +08:00
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "hello\n\nwor\n\nld.");
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 7);
|
|
|
|
assert.equal(textarea.selectionEnd, 10);
|
2017-06-28 01:32:20 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
textarea.selectionStart = 15;
|
|
|
|
textarea.selectionEnd = 15;
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.quote");
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "hello\n\nwor\n\nld.\n\n> Blockquote");
|
2015-09-29 02:01:16 +08:00
|
|
|
});
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
testCase(`bullet button with no selection`, async function(assert, textarea) {
|
2018-06-15 23:03:24 +08:00
|
|
|
const example = I18n.t("composer.list_item");
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.bullet`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, `hello world.\n\n* ${example}`);
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 14);
|
|
|
|
assert.equal(textarea.selectionEnd, 16 + example.length);
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.bullet`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, `hello world.\n\n${example}`);
|
2015-09-29 02:01:16 +08:00
|
|
|
});
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
testCase(`bullet button with a selection`, async function(assert, textarea) {
|
2015-09-29 02:01:16 +08:00
|
|
|
textarea.selectionStart = 6;
|
|
|
|
textarea.selectionEnd = 11;
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.bullet`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, `hello\n\n* world\n\n.`);
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 7);
|
|
|
|
assert.equal(textarea.selectionEnd, 14);
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.bullet`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, `hello\n\nworld\n\n.`);
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 7);
|
|
|
|
assert.equal(textarea.selectionEnd, 12);
|
2015-09-29 02:01:16 +08:00
|
|
|
});
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
testCase(`bullet button with a multiple line selection`, async function(
|
2018-06-15 23:03:24 +08:00
|
|
|
assert,
|
|
|
|
textarea
|
|
|
|
) {
|
|
|
|
this.set("value", "* Hello\n\nWorld\n\nEvil");
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = 20;
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.bullet`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "Hello\n\nWorld\n\nEvil");
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 0);
|
|
|
|
assert.equal(textarea.selectionEnd, 18);
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.bullet`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "* Hello\n\n* World\n\n* Evil");
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 0);
|
|
|
|
assert.equal(textarea.selectionEnd, 24);
|
2015-09-29 02:01:16 +08:00
|
|
|
});
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
testCase(`list button with no selection`, async function(assert, textarea) {
|
2018-06-15 23:03:24 +08:00
|
|
|
const example = I18n.t("composer.list_item");
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.list`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, `hello world.\n\n1. ${example}`);
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 14);
|
|
|
|
assert.equal(textarea.selectionEnd, 17 + example.length);
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.list`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, `hello world.\n\n${example}`);
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 14);
|
|
|
|
assert.equal(textarea.selectionEnd, 14 + example.length);
|
2015-09-29 02:01:16 +08:00
|
|
|
});
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
testCase(`list button with a selection`, async function(assert, textarea) {
|
2015-09-29 02:01:16 +08:00
|
|
|
textarea.selectionStart = 6;
|
|
|
|
textarea.selectionEnd = 11;
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.list`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, `hello\n\n1. world\n\n.`);
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 7);
|
|
|
|
assert.equal(textarea.selectionEnd, 15);
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.list`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, `hello\n\nworld\n\n.`);
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 7);
|
|
|
|
assert.equal(textarea.selectionEnd, 12);
|
2015-09-29 02:01:16 +08:00
|
|
|
});
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
testCase(`list button with line sequence`, async function(assert, textarea) {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("value", "Hello\n\nWorld\n\nEvil");
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = 18;
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.list`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "1. Hello\n\n2. World\n\n3. Evil");
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 0);
|
|
|
|
assert.equal(textarea.selectionEnd, 27);
|
2015-09-29 02:01:16 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click(`button.list`);
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "Hello\n\nWorld\n\nEvil");
|
2018-07-30 04:51:32 +08:00
|
|
|
assert.equal(textarea.selectionStart, 0);
|
|
|
|
assert.equal(textarea.selectionEnd, 18);
|
2015-09-29 02:01:16 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
componentTest("clicking the toggle-direction button toggles the direction", {
|
|
|
|
template: "{{d-editor value=value}}",
|
2018-01-30 09:42:19 +08:00
|
|
|
beforeEach() {
|
|
|
|
this.siteSettings.support_mixed_text_direction = true;
|
2019-05-16 05:43:00 +08:00
|
|
|
this.siteSettings.default_locale = "en_US";
|
2018-01-30 09:42:19 +08:00
|
|
|
},
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
async test(assert) {
|
2019-02-25 23:04:55 +08:00
|
|
|
const textarea = find("textarea.d-editor-input");
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.toggle-direction");
|
|
|
|
assert.equal(textarea.attr("dir"), "rtl");
|
|
|
|
await click("button.toggle-direction");
|
|
|
|
assert.equal(textarea.attr("dir"), "ltr");
|
2018-01-30 09:42:19 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
testCase(`doesn't jump to bottom with long text`, async function(
|
|
|
|
assert,
|
|
|
|
textarea
|
|
|
|
) {
|
2018-06-15 23:03:24 +08:00
|
|
|
let longText = "hello world.";
|
|
|
|
for (let i = 0; i < 8; i++) {
|
2015-12-30 03:59:12 +08:00
|
|
|
longText = longText + longText;
|
|
|
|
}
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("value", longText);
|
2015-12-30 03:59:12 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
$(textarea).scrollTop(0);
|
|
|
|
textarea.selectionStart = 3;
|
|
|
|
textarea.selectionEnd = 3;
|
2015-12-30 03:59:12 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await click("button.bold");
|
|
|
|
assert.equal($(textarea).scrollTop(), 0, "it stays scrolled up");
|
2015-12-30 03:59:12 +08:00
|
|
|
});
|
|
|
|
|
2019-06-17 16:24:20 +08:00
|
|
|
componentTest("emoji", {
|
|
|
|
skip: true,
|
|
|
|
template: "{{d-editor value=value}}",
|
|
|
|
beforeEach() {
|
|
|
|
// Test adding a custom button
|
|
|
|
withPluginApi("0.1", api => {
|
|
|
|
api.onToolbarCreate(toolbar => {
|
|
|
|
toolbar.addButton({
|
|
|
|
id: "emoji",
|
|
|
|
group: "extras",
|
|
|
|
icon: "far-smile",
|
|
|
|
action: () => toolbar.context.send("emoji")
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.set("value", "hello world.");
|
|
|
|
},
|
|
|
|
async test(assert) {
|
|
|
|
jumpEnd(find("textarea.d-editor-input")[0]);
|
|
|
|
await click("button.emoji");
|
|
|
|
|
|
|
|
await click(
|
|
|
|
'.emoji-picker .section[data-section="smileys_&_emotion"] button.emoji[title="grinning"]'
|
|
|
|
);
|
|
|
|
assert.equal(this.value, "hello world.:grinning:");
|
|
|
|
}
|
|
|
|
});
|
2016-07-26 03:31:21 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
testCase("replace-text event by default", async function(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("value", "red green blue");
|
2017-05-06 00:59:34 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await this.container
|
2019-10-04 22:06:08 +08:00
|
|
|
.lookup("service:app-events")
|
2018-07-30 04:51:32 +08:00
|
|
|
.trigger("composer:replace-text", "green", "yellow");
|
2016-07-26 03:31:21 +08:00
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "red green blue");
|
2017-05-06 00:59:34 +08:00
|
|
|
});
|
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
composerTestCase("replace-text event for composer", async function(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("value", "red green blue");
|
2016-07-26 03:31:21 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
await this.container
|
2019-10-04 22:06:08 +08:00
|
|
|
.lookup("service:app-events")
|
2018-07-30 04:51:32 +08:00
|
|
|
.trigger("composer:replace-text", "green", "yellow");
|
2016-07-26 03:31:21 +08:00
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
assert.equal(this.value, "red yellow blue");
|
2016-07-26 03:31:21 +08:00
|
|
|
});
|
2016-12-29 16:54:15 +08:00
|
|
|
|
|
|
|
(() => {
|
|
|
|
// Tests to check cursor/selection after replace-text event.
|
2018-06-15 23:03:24 +08:00
|
|
|
const BEFORE = "red green blue";
|
|
|
|
const NEEDLE = "green";
|
|
|
|
const REPLACE = "yellow";
|
2016-12-29 16:54:15 +08:00
|
|
|
const AFTER = BEFORE.replace(NEEDLE, REPLACE);
|
|
|
|
|
|
|
|
const CASES = [
|
|
|
|
{
|
2018-06-15 23:03:24 +08:00
|
|
|
description: "cursor at start remains there",
|
2016-12-29 16:54:15 +08:00
|
|
|
before: [0, 0],
|
|
|
|
after: [0, 0]
|
2018-06-15 23:03:24 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "cursor before needle becomes cursor before replacement",
|
2016-12-29 16:54:15 +08:00
|
|
|
before: [BEFORE.indexOf(NEEDLE), 0],
|
|
|
|
after: [AFTER.indexOf(REPLACE), 0]
|
2018-06-15 23:03:24 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "cursor at needle start + 1 moves behind replacement",
|
2016-12-29 16:54:15 +08:00
|
|
|
before: [BEFORE.indexOf(NEEDLE) + 1, 0],
|
|
|
|
after: [AFTER.indexOf(REPLACE) + REPLACE.length, 0]
|
2018-06-15 23:03:24 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "cursor at needle end - 1 stays behind replacement",
|
2016-12-29 16:54:15 +08:00
|
|
|
before: [BEFORE.indexOf(NEEDLE) + NEEDLE.length - 1, 0],
|
|
|
|
after: [AFTER.indexOf(REPLACE) + REPLACE.length, 0]
|
2018-06-15 23:03:24 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "cursor behind needle becomes cursor behind replacement",
|
2016-12-29 16:54:15 +08:00
|
|
|
before: [BEFORE.indexOf(NEEDLE) + NEEDLE.length, 0],
|
|
|
|
after: [AFTER.indexOf(REPLACE) + REPLACE.length, 0]
|
2018-06-15 23:03:24 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "cursor at end remains there",
|
2016-12-29 16:54:15 +08:00
|
|
|
before: [BEFORE.length, 0],
|
|
|
|
after: [AFTER.length, 0]
|
2018-06-15 23:03:24 +08:00
|
|
|
},
|
2019-05-16 20:42:01 +08:00
|
|
|
{
|
|
|
|
description:
|
|
|
|
"selection spanning needle start becomes selection until replacement start",
|
|
|
|
before: [BEFORE.indexOf(NEEDLE) - 1, 2],
|
|
|
|
after: [AFTER.indexOf(REPLACE) - 1, 1]
|
|
|
|
},
|
2018-06-15 23:03:24 +08:00
|
|
|
{
|
|
|
|
description:
|
|
|
|
"selection spanning needle end becomes selection from replacement end",
|
2016-12-29 16:54:15 +08:00
|
|
|
before: [BEFORE.indexOf(NEEDLE) + NEEDLE.length - 1, 2],
|
|
|
|
after: [AFTER.indexOf(REPLACE) + REPLACE.length, 1]
|
2018-06-15 23:03:24 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description:
|
|
|
|
"selection spanning needle becomes selection spanning replacement",
|
2016-12-29 16:54:15 +08:00
|
|
|
before: [BEFORE.indexOf(NEEDLE) - 1, NEEDLE.length + 2],
|
|
|
|
after: [AFTER.indexOf(REPLACE) - 1, REPLACE.length + 2]
|
2018-06-15 23:03:24 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
description: "complete selection remains complete",
|
2016-12-29 16:54:15 +08:00
|
|
|
before: [0, BEFORE.length],
|
|
|
|
after: [0, AFTER.length]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
for (let i = 0; i < CASES.length; i++) {
|
|
|
|
const CASE = CASES[i];
|
2018-07-30 04:51:32 +08:00
|
|
|
// prettier-ignore
|
|
|
|
composerTestCase(`replace-text event: ${CASE.description}`, async function( // eslint-disable-line no-loop-func
|
2018-06-15 23:03:24 +08:00
|
|
|
assert,
|
|
|
|
textarea
|
|
|
|
) {
|
|
|
|
this.set("value", BEFORE);
|
2019-05-16 20:42:01 +08:00
|
|
|
|
2019-05-27 23:31:11 +08:00
|
|
|
await focus(textarea);
|
2019-05-16 20:42:01 +08:00
|
|
|
|
|
|
|
assert.ok(textarea.value === BEFORE);
|
|
|
|
|
2019-05-27 22:33:27 +08:00
|
|
|
const [start, len] = CASE.before;
|
|
|
|
setTextareaSelection(textarea, start, start + len);
|
2019-05-16 20:42:01 +08:00
|
|
|
|
2018-07-30 04:51:32 +08:00
|
|
|
this.container
|
2019-10-04 22:06:08 +08:00
|
|
|
.lookup("service:app-events")
|
2019-05-27 22:33:27 +08:00
|
|
|
.trigger("composer:replace-text", "green", "yellow", { forceFocus: true });
|
2019-05-16 20:42:01 +08:00
|
|
|
|
2019-10-30 21:48:24 +08:00
|
|
|
next(() => {
|
2019-06-05 20:52:38 +08:00
|
|
|
let expect = formatTextWithSelection(AFTER, CASE.after);
|
|
|
|
let actual = formatTextWithSelection(
|
|
|
|
this.value,
|
|
|
|
getTextareaSelection(textarea)
|
|
|
|
);
|
|
|
|
assert.equal(actual, expect);
|
|
|
|
});
|
2016-12-29 16:54:15 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
})();
|