The previous excerpt was a simple truncated raw message. Starting with this commit, the raw content of the draft is cooked and an excerpt is extracted from it. The logic for extracting the excerpt mimics the the `ExcerptParser` class, but does not implement all functionality, being a much simpler implementation. The two draft controllers have been merged into one and the /draft.json route has been changed to /drafts.json to be consistent with the other route names.
54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
import {
|
|
acceptance,
|
|
exists,
|
|
query,
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
|
import { click, fillIn, visit } from "@ember/test-helpers";
|
|
import { test } from "qunit";
|
|
import I18n from "I18n";
|
|
|
|
acceptance("Composer - Draft saving", function (needs) {
|
|
needs.user();
|
|
|
|
const draftThatWillBeSaved = "This_will_be_saved_successfully";
|
|
|
|
needs.pretender((server, helper) => {
|
|
server.post("/drafts.json", (request) => {
|
|
const success = request.requestBody.includes(draftThatWillBeSaved);
|
|
return success
|
|
? helper.response({ success: true })
|
|
: helper.response(500, {});
|
|
});
|
|
});
|
|
|
|
test("Shows a warning if a draft wasn't saved", async function (assert) {
|
|
await visit("/t/internationalization-localization/280");
|
|
await click(".topic-post:nth-of-type(1) button.show-more-actions");
|
|
await click(".topic-post:nth-of-type(1) button.edit");
|
|
|
|
await fillIn(".d-editor-input", draftThatWillBeSaved);
|
|
|
|
assert.notOk(
|
|
exists("div#draft-status span"),
|
|
"the draft was saved, there's no warning"
|
|
);
|
|
|
|
await fillIn(".d-editor-input", "This won't be saved because of error");
|
|
assert.equal(
|
|
query("div#draft-status span").innerText.trim(),
|
|
I18n.t("composer.drafts_offline"),
|
|
"the draft wasn't saved, a warning is rendered"
|
|
);
|
|
assert.ok(
|
|
exists("div#draft-status svg.d-icon-exclamation-triangle"),
|
|
"an exclamation icon is rendered"
|
|
);
|
|
|
|
await fillIn(".d-editor-input", draftThatWillBeSaved);
|
|
assert.notOk(
|
|
exists("div#draft-status span"),
|
|
"the draft was saved again, the warning has disappeared"
|
|
);
|
|
});
|
|
});
|