A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
test: add tests for note export
thecodrr8be672e6203f
diff --git a/apps/web/__e2e__/notes.test.js b/apps/web/__e2e__/notes.test.jsindex d5acbac9d..424905f18 100644--- a/apps/web/__e2e__/notes.test.js+++ b/apps/web/__e2e__/notes.test.js@@ -3,10 +3,8 @@/*** TODO: We are still not checking if toast appears on delete/restore or not.- */--const { test, expect } = require("@playwright/test");-const { getTestId, createNote, NOTE } = require("./utils");+ */ const { test, expect } = require("@playwright/test");+const { getTestId, createNote, NOTE, downloadFile } = require("./utils");const {navigateTo,clickMenuItem,@@ -153,6 +151,27 @@ async function addNoteToNotebook() {await checkNotePresence(0, false);}+async function exportNote(format) {+ const noteSelector = await createNoteAndCheckPresence();++ await openContextMenu(noteSelector);++ await page.click(Menu.new("menuitem").item("export").build());++ // we need to override date time so+ // date created & date edited remain fixed.+ await page.evaluate(() => {+ // eslint-disable-next-line no-extend-native+ Date.prototype.toLocaleDateString = () => "xxx";+ });++ const output = await downloadFile(+ getTestId(`export-dialog-${format}`),+ "utf-8"+ );+ expect(output).toMatchSnapshot(`export-${format}.txt`);+}+test.describe("run tests independently", () => {/*** @type {Page}@@ -410,4 +429,8 @@ test.describe("run tests independently", () => {isPresent(getTestId("properties-tag-testtag"))).resolves.toBeTruthy();});++ test(`export note as txt`, async () => await exportNote("txt"));+ test(`export note as md`, async () => await exportNote("md"));+ test(`export note as html`, async () => await exportNote("html"));});diff --git a/apps/web/__e2e__/notes.test.js-snapshots/export-html-Chromium-linux.txt b/apps/web/__e2e__/notes.test.js-snapshots/export-html-Chromium-linux.txtnew file mode 100644index 000000000..1b8c68481--- /dev/null+++ b/apps/web/__e2e__/notes.test.js-snapshots/export-html-Chromium-linux.txt@@ -0,0 +1,19 @@+<!DOCTYPE html>+<html lang="en-US">+ <head>+ <meta charset="utf-8" />+ <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />+ <meta+ name="description"+ content="This is Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1"+ />+ <title>Test 1 - Notesnook</title>+ </head>+ <body>+ <h1>Test 1</h1>+ <p>This is Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1</p>+ <br/>+ Created on: <b>xxx</b><br/>+ Edited on: <b>xxx</b>+ </body>+</html>diff --git a/apps/web/__e2e__/notes.test.js-snapshots/export-html-Firefox-linux.txt b/apps/web/__e2e__/notes.test.js-snapshots/export-html-Firefox-linux.txtnew file mode 100644index 000000000..1b8c68481--- /dev/null+++ b/apps/web/__e2e__/notes.test.js-snapshots/export-html-Firefox-linux.txt@@ -0,0 +1,19 @@+<!DOCTYPE html>+<html lang="en-US">+ <head>+ <meta charset="utf-8" />+ <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />+ <meta+ name="description"+ content="This is Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1"+ />+ <title>Test 1 - Notesnook</title>+ </head>+ <body>+ <h1>Test 1</h1>+ <p>This is Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1</p>+ <br/>+ Created on: <b>xxx</b><br/>+ Edited on: <b>xxx</b>+ </body>+</html>diff --git a/apps/web/__e2e__/notes.test.js-snapshots/export-html-WebKit-linux.txt b/apps/web/__e2e__/notes.test.js-snapshots/export-html-WebKit-linux.txtnew file mode 100644index 000000000..1b8c68481--- /dev/null+++ b/apps/web/__e2e__/notes.test.js-snapshots/export-html-WebKit-linux.txt@@ -0,0 +1,19 @@+<!DOCTYPE html>+<html lang="en-US">+ <head>+ <meta charset="utf-8" />+ <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />+ <meta+ name="description"+ content="This is Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1"+ />+ <title>Test 1 - Notesnook</title>+ </head>+ <body>+ <h1>Test 1</h1>+ <p>This is Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1</p>+ <br/>+ Created on: <b>xxx</b><br/>+ Edited on: <b>xxx</b>+ </body>+</html>diff --git a/apps/web/__e2e__/notes.test.js-snapshots/export-md-Chromium-linux.txt b/apps/web/__e2e__/notes.test.js-snapshots/export-md-Chromium-linux.txtnew file mode 100644index 000000000..e479a1902--- /dev/null+++ b/apps/web/__e2e__/notes.test.js-snapshots/export-md-Chromium-linux.txt@@ -0,0 +1,10 @@+# Test 1++This is Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1+++---++_Created on: xxx_++_Edited on: xxx_\ No newline at end of filediff --git a/apps/web/__e2e__/notes.test.js-snapshots/export-md-Firefox-linux.txt b/apps/web/__e2e__/notes.test.js-snapshots/export-md-Firefox-linux.txtnew file mode 100644index 000000000..e479a1902--- /dev/null+++ b/apps/web/__e2e__/notes.test.js-snapshots/export-md-Firefox-linux.txt@@ -0,0 +1,10 @@+# Test 1++This is Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1+++---++_Created on: xxx_++_Edited on: xxx_\ No newline at end of filediff --git a/apps/web/__e2e__/notes.test.js-snapshots/export-md-WebKit-linux.txt b/apps/web/__e2e__/notes.test.js-snapshots/export-md-WebKit-linux.txtnew file mode 100644index 000000000..e479a1902--- /dev/null+++ b/apps/web/__e2e__/notes.test.js-snapshots/export-md-WebKit-linux.txt@@ -0,0 +1,10 @@+# Test 1++This is Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1+++---++_Created on: xxx_++_Edited on: xxx_\ No newline at end of filediff --git a/apps/web/__e2e__/notes.test.js-snapshots/export-txt-Chromium-linux.txt b/apps/web/__e2e__/notes.test.js-snapshots/export-txt-Chromium-linux.txtnew file mode 100644index 000000000..6c39fd390--- /dev/null+++ b/apps/web/__e2e__/notes.test.js-snapshots/export-txt-Chromium-linux.txt@@ -0,0 +1,8 @@+Test 1+----------++This is Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1++----------+Created on: xxx+Edited on: xxx\ No newline at end of filediff --git a/apps/web/__e2e__/notes.test.js-snapshots/export-txt-Firefox-linux.txt b/apps/web/__e2e__/notes.test.js-snapshots/export-txt-Firefox-linux.txtnew file mode 100644index 000000000..6c39fd390--- /dev/null+++ b/apps/web/__e2e__/notes.test.js-snapshots/export-txt-Firefox-linux.txt@@ -0,0 +1,8 @@+Test 1+----------++This is Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1++----------+Created on: xxx+Edited on: xxx\ No newline at end of filediff --git a/apps/web/__e2e__/notes.test.js-snapshots/export-txt-WebKit-linux.txt b/apps/web/__e2e__/notes.test.js-snapshots/export-txt-WebKit-linux.txtnew file mode 100644index 000000000..6c39fd390--- /dev/null+++ b/apps/web/__e2e__/notes.test.js-snapshots/export-txt-WebKit-linux.txt@@ -0,0 +1,8 @@+Test 1+----------++This is Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1Test 1++----------+Created on: xxx+Edited on: xxx\ No newline at end of filediff --git a/apps/web/__e2e__/utils/index.js b/apps/web/__e2e__/utils/index.jsindex 209a82f38..0e9085816 100644--- a/apps/web/__e2e__/utils/index.js+++ b/apps/web/__e2e__/utils/index.js@@ -1,4 +1,5 @@/* eslint-disable no-undef */+const fs = require("fs");const NOTEBOOK = {title: "Test notebook 1",@@ -29,9 +30,22 @@ async function createNote(note, actionButtonId) {await page.type(".mce-content-body", note.content);}+async function downloadFile(downloadActionSelector, encoding) {+ return new Promise(async (resolve) => {+ page.on("download", async (download) => {+ const path = await download.path();+ resolve(fs.readFileSync(path, { encoding }).toString());+ });+ await page.waitForSelector(downloadActionSelector);++ await page.click(downloadActionSelector);+ });+}+module.exports = {NOTE,NOTEBOOK,getTestId,createNote,+ downloadFile,};diff --git a/apps/web/playwright.config.js b/apps/web/playwright.config.jsindex 4f0442899..67b25b7e5 100644--- a/apps/web/playwright.config.js+++ b/apps/web/playwright.config.js@@ -9,9 +9,10 @@ module.exports = {timeout: 30000,workers: IS_CI ? 3 : 4,reporter: "list",- retries: 3,+ retries: IS_CI ? 3 : 0,use: {headless: true,+ acceptDownloads: true,// Artifactstrace: IS_CI ? "off" : "retain-on-failure",diff --git a/apps/web/src/components/dialogs/exportdialog.js b/apps/web/src/components/dialogs/exportdialog.jsindex 55b70e743..0a661a0c9 100644--- a/apps/web/src/components/dialogs/exportdialog.js+++ b/apps/web/src/components/dialogs/exportdialog.js@@ -47,6 +47,7 @@ function ExportDialog(props) {<Flex flexDirection="column">{formats.map((format) => (<Button+ data-test-id={`export-dialog-${format.type}`}variant="tertiary"sx={{ display: "flex" }}mb={1}