This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/acceptance/fast-edit-test.js
Robin Ward 6f25f17360
DEV: Revisit skipped tests (#15769)
* Some are no longer flaky or easily fixed

* Some are out of date or test things we can't do accurately (scroll
  position) and are removed.

* Unwinds some uppy tests and makes sure all promises and runloops are
  resolved.

Everything has been run in legacy/ember cli multiple times to ensure no
obvious suite regressions.
2022-02-02 12:09:03 -05:00

77 lines
2.2 KiB
JavaScript

import {
acceptance,
exists,
query,
selectText,
} from "discourse/tests/helpers/qunit-helpers";
import { click, fillIn, triggerKeyEvent, visit } from "@ember/test-helpers";
import { test } from "qunit";
import postFixtures from "discourse/tests/fixtures/post";
import { cloneJSON } from "discourse-common/lib/object";
acceptance("Fast Edit", function (needs) {
needs.user();
needs.settings({
enable_fast_edit: true,
});
needs.pretender((server, helper) => {
server.get("/posts/419", () => {
return helper.response(cloneJSON(postFixtures["/posts/398"]));
});
});
test("Fast edit button works", async function (assert) {
await visit("/t/internationalization-localization/280");
const textNode = query("#post_1 .cooked p").childNodes[0];
await selectText(textNode, 9);
await click(".quote-button .quote-edit-label");
assert.ok(exists("#fast-edit-input"), "fast editor is open");
assert.strictEqual(
query("#fast-edit-input").value,
"Any plans",
"contains selected text"
);
await fillIn("#fast-edit-input", "My edit");
await click(".save-fast-edit");
assert.notOk(exists("#fast-edit-input"), "fast editor is closed");
});
test("Works with keyboard shortcut", async function (assert) {
await visit("/t/internationalization-localization/280");
const textNode = query("#post_1 .cooked p").childNodes[0];
await selectText(textNode, 9);
await triggerKeyEvent(document, "keypress", "e".charCodeAt(0));
assert.ok(exists("#fast-edit-input"), "fast editor is open");
assert.strictEqual(
query("#fast-edit-input").value,
"Any plans",
"contains selected text"
);
await fillIn("#fast-edit-input", "My edit");
await click(".save-fast-edit");
assert.notOk(exists("#fast-edit-input"), "fast editor is closed");
});
test("Opens full composer for multi-line selection", async function (assert) {
await visit("/t/internationalization-localization/280");
const textNode = query("#post_2 .cooked");
await selectText(textNode);
await click(".quote-button .quote-edit-label");
assert.notOk(exists("#fast-edit-input"), "fast editor is not open");
assert.ok(exists(".d-editor-input"), "the composer is open");
});
});