Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: editor word count is not cleared in new note

thecodrr983d6fa2d060
diff --git a/apps/web/__e2e__/notes.test.js b/apps/web/__e2e__/notes.test.js
index 87fe3a7df..efe880a27 100644
--- a/apps/web/__e2e__/notes.test.js
+++ b/apps/web/__e2e__/notes.test.js
@@ -493,6 +493,20 @@ test.describe("run tests independently", () => {
expect(await getEditorContent()).toBe("");
});
+
+ test.only("creating a new note should clear the word count", async () => {
+ const selector = await createNoteAndCheckPresence();
+
+ await page.click(getTestId("notes-action-button"));
+
+ await page.click(selector);
+
+ await createNote({ title: "Hello World" }, "notes");
+
+ await expect(page.innerText(getTestId("editor-word-count"))).resolves.toBe(
+ "0 words"
+ );
+ });
});
test.describe("stress tests", () => {
diff --git a/apps/web/__e2e__/utils/index.js b/apps/web/__e2e__/utils/index.js
index 42672debe..3b69243dc 100644
--- a/apps/web/__e2e__/utils/index.js
+++ b/apps/web/__e2e__/utils/index.js
@@ -35,11 +35,15 @@ async function editNote(title, content) {
force: true,
});
- await page.waitForTimeout(100);
+ if (content) {
+ await page.waitForTimeout(100);
- await page.focus(".mce-content-body");
+ await page.focus(".mce-content-body");
- await page.type(".mce-content-body", content);
+ await page.type(".mce-content-body", content);
+ }
+
+ await page.waitForTimeout(200);
}
async function downloadFile(downloadActionSelector, encoding) {
diff --git a/apps/web/src/components/editor/footer.js b/apps/web/src/components/editor/footer.js
index c4f5b51ea..7040e52f0 100644
--- a/apps/web/src/components/editor/footer.js
+++ b/apps/web/src/components/editor/footer.js
@@ -24,7 +24,9 @@ function EditorFooter() {
return (
<Flex alignItems="center">
<Text variant="subBody" color="bgSecondaryText">
- {totalWords + " words"}
+ <Text as="span" data-test-id="editor-word-count">
+ {totalWords + " words"}
+ </Text>
<TextSeperator />
{timeConverter(dateEdited || Date.now())}
<TextSeperator />
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.js
index 120025fae..4bb174bd6 100644
--- a/apps/web/src/components/editor/index.js
+++ b/apps/web/src/components/editor/index.js
@@ -92,6 +92,7 @@ function Editor({ noteId, nonce }) {
const editor = editorRef.current?.editor;
if (!editor || !editor.initialized) return;
editor.clearContent();
+ updateWordCount(editor);
}, []);
useEffect(