discourse/test/javascripts/acceptance/composer-edit-conflict-test.js.es6
Mark VanLandingham 176aa0ac7d
DEV: Import pretender instead of global server var (#8996)
* DEV: Remove server global test variable

* Delete yarn-error.log

* prettier and some eslint fixes

* add global server variable back for plugins

* rename imported server to pretender

* prettier

* support plugin server. usage

* Export pretender as named

* Prettier

* change default pretender export

* fix bad import

* Use pretender() and original default export

* export new Pretender as default

* fix accidental change

* WIP testing

* add pretend handlers in correct location

* move more stuff into the correct pretender

* Consolidated more pretenders

* comment out another bad test

* fix user acceptance tests

* commented out bad test

* fixed another composer server stub

* fix more tests

* fixed tag test pretender

* Fix admin email test

* removed another draft handler

* add back test

* fix and uncomment another test

* remove test that is not useful

* remove commented out lines

* reapply handlers between every test

* no need to re-stub requests now :)

* cleanup from review

* more cleanup
2020-03-02 14:24:31 -05:00

76 lines
2.3 KiB
JavaScript

import { acceptance } from "helpers/qunit-helpers";
import pretender from "helpers/create-pretender";
acceptance("Composer - Edit conflict", {
loggedIn: true
});
QUnit.test("Edit a post that causes an edit conflict", async assert => {
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", "this will 409");
await click("#reply-control button.create");
assert.equal(
find("#reply-control button.create")
.text()
.trim(),
I18n.t("composer.overwrite_edit"),
"it shows the overwrite button"
);
assert.ok(
find("#draft-status .d-icon-user-edit"),
"error icon should be there"
);
await click(".modal .btn-primary");
});
function handleDraftPretender(assert) {
pretender.post("/draft.json", request => {
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 }];
});
}
QUnit.test(
"Should not send originalText when posting a new reply",
async assert => {
handleDraftPretender(assert);
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"
);
}
);
QUnit.test("Should send originalText when editing a reply", async assert => {
handleDraftPretender(assert);
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"
);
});