Skip to content

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

test: add importer test

thecodrr1edfcbe6f518
diff --git a/apps/web/__e2e__/data/importer-data.zip b/apps/web/__e2e__/data/importer-data.zip
new file mode 100644
index 000000000..c3a786f14
Binary files /dev/null and b/apps/web/__e2e__/data/importer-data.zip differ
diff --git a/apps/web/__e2e__/user.test.js b/apps/web/__e2e__/user.test.js
index 8a224d68a..3848a8e4e 100644
--- a/apps/web/__e2e__/user.test.js
+++ b/apps/web/__e2e__/user.test.js
@@ -56,3 +56,31 @@ test("logout user", async () => {
expect(await isAbsent(getTestId("navitem-sync"))).toBe(true);
});
+
+test("login user & import notes", async () => {
+ await loginUser();
+
+ await page.click(getTestId("navitem-settings"));
+
+ await page.click(getTestId("settings-importer"));
+
+ await page.click(getTestId("settings-importer-import"));
+
+ const [fileChooser] = await Promise.all([
+ page.waitForEvent("filechooser"),
+ page.click(getTestId("import-dialog-select-files")),
+ ]);
+
+ await fileChooser.setFiles(path.join(__dirname, "data", "importer-data.zip"));
+
+ await page.click(getTestId("importer-dialog-notes"));
+
+ let titles = [];
+ for (let i = 0; i < 6; ++i) {
+ const noteId = getTestId(`note-${i}`);
+ const text = await page.innerText(noteId);
+ titles.push(text);
+ }
+
+ expect(titles.join("\n")).toMatchSnapshot("importer-notes-titles.txt");
+});
diff --git a/apps/web/__e2e__/user.test.js-snapshots/importer-notes-titles-Chromium-linux.txt b/apps/web/__e2e__/user.test.js-snapshots/importer-notes-titles-Chromium-linux.txt
new file mode 100644
index 000000000..94de26d75
--- /dev/null
+++ b/apps/web/__e2e__/user.test.js-snapshots/importer-notes-titles-Chromium-linux.txt
@@ -0,0 +1,6 @@
+2021-05-21T22_31_28.334+05_00
+2021-11-29T10_12_57.757+05_00
+2021-11-29T10_11_39.427+05_00
+2021-11-29T10_08_04.344+05_00
+2021-11-29T10_12_25.187+05_00
+Some really amazing note
\ No newline at end of file
diff --git a/apps/web/__e2e__/user.test.js-snapshots/importer-notes-titles-Firefox-linux.txt b/apps/web/__e2e__/user.test.js-snapshots/importer-notes-titles-Firefox-linux.txt
new file mode 100644
index 000000000..94de26d75
--- /dev/null
+++ b/apps/web/__e2e__/user.test.js-snapshots/importer-notes-titles-Firefox-linux.txt
@@ -0,0 +1,6 @@
+2021-05-21T22_31_28.334+05_00
+2021-11-29T10_12_57.757+05_00
+2021-11-29T10_11_39.427+05_00
+2021-11-29T10_08_04.344+05_00
+2021-11-29T10_12_25.187+05_00
+Some really amazing note
\ No newline at end of file
diff --git a/apps/web/__e2e__/user.test.js-snapshots/importer-notes-titles-WebKit-linux.txt b/apps/web/__e2e__/user.test.js-snapshots/importer-notes-titles-WebKit-linux.txt
new file mode 100644
index 000000000..6788adb78
--- /dev/null
+++ b/apps/web/__e2e__/user.test.js-snapshots/importer-notes-titles-WebKit-linux.txt
@@ -0,0 +1,11 @@
+2021-05-21T22_31_28.334+05_00
+
+2021-11-29T10_12_57.757+05_00
+
+2021-11-29T10_11_39.427+05_00
+
+2021-11-29T10_08_04.344+05_00
+
+2021-11-29T10_12_25.187+05_00
+
+Some really amazing note
diff --git a/apps/web/src/components/accordion/index.js b/apps/web/src/components/accordion/index.js
index f91ac5e9b..521f58371 100644
--- a/apps/web/src/components/accordion/index.js
+++ b/apps/web/src/components/accordion/index.js
@@ -8,6 +8,7 @@ export default function Accordion({
sx,
color,
isClosed = true,
+ testId,
...restProps
}) {
const [isContentHidden, setIsContentHidden] = useState();
@@ -30,6 +31,7 @@ export default function Accordion({
onClick={() => {
setIsContentHidden((state) => !state);
}}
+ data-test-id={testId}
>
<Text variant="subtitle" sx={{ color }}>
{title}
diff --git a/apps/web/src/components/dialogs/import-dialog.js b/apps/web/src/components/dialogs/import-dialog.js
index 47bc9df26..464a3658d 100644
--- a/apps/web/src/components/dialogs/import-dialog.js
+++ b/apps/web/src/components/dialogs/import-dialog.js
@@ -127,6 +127,7 @@ function ImportDialog(props) {
<Flex
{...getRootProps()}
flexDirection="column"
+ data-test-id="import-dialog-select-files"
sx={{
justifyContent: "center",
alignItems: "center",
@@ -173,10 +174,15 @@ function ImportDialog(props) {
</Accordion>
{files.length > 0 && (
- <Accordion title={`${notes.length} notes found`} sx={{ mt: 1 }}>
+ <Accordion
+ title={`${notes.length} notes found`}
+ sx={{ mt: 1 }}
+ testId={"importer-dialog-notes"}
+ >
<Flex flexDirection="column" mt={1}>
{notes.map((note, i) => (
<Flex
+ data-test-id={`note-${i}`}
p={1}
sx={{
":hover": { bg: "hover" },
diff --git a/apps/web/src/views/settings.js b/apps/web/src/views/settings.js
index 3ea0c0110..dbbf418a3 100644
--- a/apps/web/src/views/settings.js
+++ b/apps/web/src/views/settings.js
@@ -475,6 +475,7 @@ function Settings(props) {
<Header
title="Notesnook Importer"
isOpen={groups.importer}
+ testId="settings-importer"
onClick={() => {
setGroups((g) => ({ ...g, importer: !g.importer }));
}}
@@ -483,6 +484,7 @@ function Settings(props) {
<>
<Button
key={"importer"}
+ data-test-id="settings-importer-import"
variant="list"
onClick={() => showImportDialog()}
>
@@ -906,9 +908,10 @@ function AccountStatusContainer(props) {
}
function Header(props) {
- const { title, isOpen, onClick } = props;
+ const { title, isOpen, testId, onClick } = props;
return (
<Flex
+ data-test-id={testId}
sx={{ borderBottom: "1px solid var(--border)", cursor: "pointer" }}
// mt={2}
py={2}