2020-05-14 22:04:08 +08:00
|
|
|
import I18n from "I18n";
|
2018-10-18 11:05:47 +08:00
|
|
|
import { acceptance } from "helpers/qunit-helpers";
|
2020-03-03 03:24:31 +08:00
|
|
|
import pretender from "helpers/create-pretender";
|
2018-10-17 21:35:32 +08:00
|
|
|
|
2018-10-18 11:05:47 +08:00
|
|
|
acceptance("Composer - Edit conflict", {
|
2020-09-04 19:42:47 +08:00
|
|
|
loggedIn: true,
|
2018-10-18 11:05:47 +08:00
|
|
|
});
|
2018-10-17 21:35:32 +08:00
|
|
|
|
2020-09-04 19:42:47 +08:00
|
|
|
QUnit.test("Edit a post that causes an edit conflict", async (assert) => {
|
2018-11-15 01:01:29 +08:00
|
|
|
await visit("/t/internationalization-localization/280");
|
2018-10-18 11:05:47 +08:00
|
|
|
await click(".topic-post:eq(0) button.show-more-actions");
|
|
|
|
await click(".topic-post:eq(0) button.edit");
|
2020-03-03 03:24:31 +08:00
|
|
|
await fillIn(".d-editor-input", "this will 409");
|
2018-10-18 11:05:47 +08:00
|
|
|
await click("#reply-control button.create");
|
|
|
|
assert.equal(
|
2020-09-04 19:42:47 +08:00
|
|
|
find("#reply-control button.create").text().trim(),
|
2018-10-18 11:05:47 +08:00
|
|
|
I18n.t("composer.overwrite_edit"),
|
|
|
|
"it shows the overwrite button"
|
|
|
|
);
|
2019-04-19 15:18:01 +08:00
|
|
|
assert.ok(
|
|
|
|
find("#draft-status .d-icon-user-edit"),
|
|
|
|
"error icon should be there"
|
|
|
|
);
|
|
|
|
await click(".modal .btn-primary");
|
2018-10-18 11:05:47 +08:00
|
|
|
});
|
2018-11-15 01:01:29 +08:00
|
|
|
|
2020-03-03 03:24:31 +08:00
|
|
|
function handleDraftPretender(assert) {
|
2020-09-04 19:42:47 +08:00
|
|
|
pretender.post("/draft.json", (request) => {
|
2020-03-03 03:24:31 +08:00
|
|
|
if (
|
|
|
|
request.requestBody.indexOf("%22reply%22%3A%22%22") === -1 &&
|
|
|
|
request.requestBody.indexOf("Any+plans+to+support+localization") !== -1
|
|
|
|
) {
|
|
|
|
assert.notEqual(request.requestBody.indexOf("originalText"), -1);
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
request.requestBody.indexOf(
|
|
|
|
"draft_key=topic_280&sequence=4&data=%7B%22reply%22%3A%22hello+world+hello+world+hello+world+hello+world+hello+world%22%2C%22action%22%3A%22reply%22%2C%22categoryId%22%3A2%2C%22archetypeId%22%3A%22regular%22%2C%22metaData"
|
|
|
|
) !== -1
|
|
|
|
) {
|
|
|
|
assert.equal(
|
|
|
|
request.requestBody.indexOf("originalText"),
|
|
|
|
-1,
|
|
|
|
request.requestBody
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return [200, { "Content-Type": "application/json" }, { success: true }];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-15 01:01:29 +08:00
|
|
|
QUnit.test(
|
|
|
|
"Should not send originalText when posting a new reply",
|
2020-09-04 19:42:47 +08:00
|
|
|
async (assert) => {
|
2020-03-03 03:24:31 +08:00
|
|
|
handleDraftPretender(assert);
|
2018-11-15 01:01:29 +08:00
|
|
|
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await click(".topic-post:eq(0) button.reply");
|
|
|
|
await fillIn(
|
|
|
|
".d-editor-input",
|
|
|
|
"hello world hello world hello world hello world hello world"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-09-04 19:42:47 +08:00
|
|
|
QUnit.test("Should send originalText when editing a reply", async (assert) => {
|
2020-03-03 03:24:31 +08:00
|
|
|
handleDraftPretender(assert);
|
2018-11-15 01:01:29 +08:00
|
|
|
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await click(".topic-post:eq(0) button.show-more-actions");
|
|
|
|
await click(".topic-post:eq(0) button.edit");
|
|
|
|
await fillIn(
|
|
|
|
".d-editor-input",
|
|
|
|
"hello world hello world hello world hello world hello world"
|
|
|
|
);
|
|
|
|
});
|