fix: format changes are not saved in editor

This commit is contained in:
thecodrr
2021-12-10 10:08:20 +05:00
parent a0b4d0ae8a
commit dd9fb21933
5 changed files with 46 additions and 11 deletions

View File

@@ -15,6 +15,7 @@ const {
editNote, editNote,
getEditorTitle, getEditorTitle,
getEditorContent, getEditorContent,
getEditorContentAsHTML,
} = require("./utils"); } = require("./utils");
const { const {
navigateTo, navigateTo,
@@ -508,7 +509,7 @@ test.describe("run tests independently", () => {
); );
}); });
test.only("creating a new title-only note should add it to the list", async () => { test("creating a new title-only note should add it to the list", async () => {
const selector = await createNoteAndCheckPresence(); const selector = await createNoteAndCheckPresence();
await page.click(getTestId("notes-action-button")); await page.click(getTestId("notes-action-button"));
@@ -517,6 +518,26 @@ test.describe("run tests independently", () => {
await createNoteAndCheckPresence({ title: "Hello World" }); await createNoteAndCheckPresence({ title: "Hello World" });
}); });
test.only("format changes should get saved", async () => {
const selector = await createNoteAndCheckPresence();
await page.click(getTestId("notes-action-button"));
await page.click(selector);
await page.keyboard.press("Control+a");
await page.click(`#editorToolbar button[title="Bold"]`);
await page.click(getTestId("notes-action-button"));
await page.click(selector);
const content = await getEditorContentAsHTML();
expect(content).toMatchSnapshot(`format-changes-should-get-saved.txt`);
});
}); });
test.describe("stress tests", () => { test.describe("stress tests", () => {

View File

@@ -0,0 +1 @@
<p><strong>This is Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1</strong></p>

View File

@@ -68,6 +68,10 @@ async function getEditorContent() {
.replace(/\n+/gm, "\n"); .replace(/\n+/gm, "\n");
} }
async function getEditorContentAsHTML() {
return await page.innerHTML(".mce-content-body");
}
module.exports = { module.exports = {
NOTE, NOTE,
NOTEBOOK, NOTEBOOK,
@@ -78,4 +82,5 @@ module.exports = {
downloadFile, downloadFile,
getEditorTitle, getEditorTitle,
getEditorContent, getEditorContent,
getEditorContentAsHTML,
}; };

View File

@@ -18,14 +18,14 @@ const projects = IS_CI
browserName: "chromium", browserName: "chromium",
}, },
}, },
{ // {
name: "Firefox", // name: "Firefox",
use: { browserName: "firefox" }, // use: { browserName: "firefox" },
}, // },
{ // {
name: "WebKit", // name: "WebKit",
use: { browserName: "webkit" }, // use: { browserName: "webkit" },
}, // },
]; ];
module.exports = { module.exports = {
@@ -44,7 +44,7 @@ module.exports = {
reporter: "list", reporter: "list",
retries: IS_CI ? 3 : 1, retries: IS_CI ? 3 : 1,
use: { use: {
headless: true, headless: false,
acceptDownloads: true, acceptDownloads: true,
// Artifacts // Artifacts

View File

@@ -128,10 +128,12 @@ const plugins = {
* 1. input - called on every change * 1. input - called on every change
* 2. compositionend - (Android only) called on change * 2. compositionend - (Android only) called on change
* 3. paste - called after content is pasted * 3. paste - called after content is pasted
* 4. ExecCommand - called after changes such as formatting.
* We do not include the "change" event here as it is only * We do not include the "change" event here as it is only
* invoked after the editor loses focus. * invoked after the editor loses focus.
*/ */
const changeEvents = "input compositionend paste"; const changeEvents = "input compositionend paste ExecCommand";
const ignoredCommand = ["mcerepaint", "mcefocus"];
function TinyMCE(props) { function TinyMCE(props) {
const { const {
@@ -243,7 +245,13 @@ function TinyMCE(props) {
} }
const onEditorChange = debounce((e) => { const onEditorChange = debounce((e) => {
if (
e.type === "execcommand" &&
ignoredCommand.includes(e.command.toLowerCase())
)
return;
if (!editor.getHTML) return; if (!editor.getHTML) return;
editor.getHTML().then((html) => { editor.getHTML().then((html) => {
onChange(html, editor); onChange(html, editor);
}); });