2020-09-28 14:31:45 +05:00
|
|
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
|
|
|
/* eslint-disable no-undef */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TODO: We are still not checking if toast appears on delete/restore or not.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-06-09 23:50:04 +05:00
|
|
|
const { test, expect } = require("@playwright/test");
|
2020-09-28 14:31:45 +05:00
|
|
|
const { getTestId, createNote, NOTE } = require("./utils");
|
|
|
|
|
const {
|
|
|
|
|
navigateTo,
|
|
|
|
|
clickMenuItem,
|
|
|
|
|
openContextMenu,
|
|
|
|
|
confirmDialog,
|
|
|
|
|
closeContextMenu,
|
|
|
|
|
useContextMenu,
|
|
|
|
|
} = require("./utils/actions");
|
|
|
|
|
const {
|
|
|
|
|
isToastPresent,
|
|
|
|
|
isPresent,
|
|
|
|
|
isAbsent,
|
|
|
|
|
checkNotePresence,
|
|
|
|
|
} = require("./utils/conditions");
|
|
|
|
|
const List = require("./utils/listitemidbuilder");
|
|
|
|
|
const Menu = require("./utils/menuitemidbuilder");
|
|
|
|
|
|
2021-06-09 23:50:04 +05:00
|
|
|
async function createNoteAndCheckPresence(note = NOTE) {
|
2020-12-01 12:55:50 +05:00
|
|
|
await createNote(note, "notes");
|
2020-09-28 14:31:45 +05:00
|
|
|
|
|
|
|
|
// make sure the note has saved.
|
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
|
|
|
|
|
|
let noteSelector = await checkNotePresence();
|
|
|
|
|
|
|
|
|
|
await page.click(noteSelector, { button: "left" });
|
|
|
|
|
|
|
|
|
|
return noteSelector;
|
2021-06-09 23:50:04 +05:00
|
|
|
}
|
2020-09-28 14:31:45 +05:00
|
|
|
|
|
|
|
|
async function deleteNoteAndCheckAbsence() {
|
|
|
|
|
const noteSelector = await createNoteAndCheckPresence();
|
|
|
|
|
|
|
|
|
|
await openContextMenu(noteSelector);
|
|
|
|
|
|
|
|
|
|
await clickMenuItem("movetotrash");
|
|
|
|
|
|
2021-05-31 00:59:49 +05:00
|
|
|
// await confirmDialog();
|
2020-09-28 14:31:45 +05:00
|
|
|
|
|
|
|
|
await expect(isToastPresent()).resolves.toBeTruthy();
|
|
|
|
|
|
|
|
|
|
await navigateTo("trash");
|
|
|
|
|
|
|
|
|
|
const trashItemSelector = List.new("trash").atIndex(0).title().build();
|
|
|
|
|
|
|
|
|
|
await expect(isPresent(trashItemSelector)).resolves.toBeTruthy();
|
|
|
|
|
|
|
|
|
|
await expect(page.innerText(trashItemSelector)).resolves.toBe(NOTE.title);
|
|
|
|
|
|
|
|
|
|
return trashItemSelector;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function lockUnlockNote(noteSelector, type) {
|
|
|
|
|
await openContextMenu(noteSelector);
|
|
|
|
|
|
|
|
|
|
await clickMenuItem(type);
|
|
|
|
|
|
2020-12-01 12:55:50 +05:00
|
|
|
await page.fill(getTestId("dialog-password"), "123abc123abc");
|
2020-09-28 14:31:45 +05:00
|
|
|
|
|
|
|
|
await confirmDialog();
|
|
|
|
|
|
|
|
|
|
await expect(isToastPresent()).resolves.toBeTruthy();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-31 00:59:49 +05:00
|
|
|
async function checkNotePinned(noteSelector, pause) {
|
2020-09-28 14:31:45 +05:00
|
|
|
await openContextMenu(noteSelector);
|
|
|
|
|
|
|
|
|
|
const unpinSelector = Menu.new("menuitem").item("unpin").build();
|
2021-05-31 00:59:49 +05:00
|
|
|
|
2020-09-28 14:31:45 +05:00
|
|
|
await expect(isPresent(unpinSelector)).resolves.toBeTruthy();
|
|
|
|
|
|
|
|
|
|
await closeContextMenu(noteSelector);
|
|
|
|
|
|
|
|
|
|
// wait for the menu to properly close
|
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function checkNoteLocked(noteSelector) {
|
|
|
|
|
await expect(
|
|
|
|
|
isPresent(List.new("note").grouped().atIndex(0).locked().build())
|
|
|
|
|
).resolves.toBeTruthy();
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
page.textContent(List.new("note").grouped().atIndex(0).body().build())
|
|
|
|
|
).resolves.toBe("");
|
|
|
|
|
|
|
|
|
|
await useContextMenu(noteSelector, () =>
|
|
|
|
|
expect(
|
|
|
|
|
isPresent(Menu.new("menuitem").item("unlock").build())
|
|
|
|
|
).resolves.toBeTruthy()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function checkNoteColored(noteSelector) {
|
|
|
|
|
await openContextMenu(noteSelector);
|
|
|
|
|
|
2021-06-10 00:53:24 +05:00
|
|
|
await page.waitForTimeout(500);
|
|
|
|
|
|
2020-09-28 14:31:45 +05:00
|
|
|
await expect(
|
|
|
|
|
isPresent(Menu.new("menuitem").colorCheck("red").build())
|
|
|
|
|
).resolves.toBeTruthy();
|
|
|
|
|
|
2020-12-01 12:55:50 +05:00
|
|
|
await closeContextMenu(noteSelector);
|
2020-09-28 14:31:45 +05:00
|
|
|
|
2020-12-01 12:55:50 +05:00
|
|
|
// wait for the menu to properly close
|
|
|
|
|
await page.waitForTimeout(500);
|
2020-09-28 14:31:45 +05:00
|
|
|
|
2020-12-01 12:55:50 +05:00
|
|
|
await navigateTo("red");
|
2020-09-28 14:31:45 +05:00
|
|
|
|
2020-12-03 14:24:25 +05:00
|
|
|
// wait for the page to render and notes to populate
|
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
|
|
2020-12-01 12:55:50 +05:00
|
|
|
const coloredNote = await page.$(List.new("note").atIndex(0).build());
|
2020-12-03 14:24:25 +05:00
|
|
|
if (!coloredNote) throw new Error("Colored note not present.");
|
2020-12-01 12:55:50 +05:00
|
|
|
}
|
2020-09-28 14:31:45 +05:00
|
|
|
|
2020-12-01 12:55:50 +05:00
|
|
|
async function addNoteToNotebook() {
|
|
|
|
|
await page.type(getTestId("mnd-new-notebook-title"), "Test Notebook");
|
2020-09-28 14:31:45 +05:00
|
|
|
|
2020-12-01 12:55:50 +05:00
|
|
|
await page.press(getTestId("mnd-new-notebook-title"), "Enter");
|
2020-09-28 14:31:45 +05:00
|
|
|
|
2020-12-01 12:55:50 +05:00
|
|
|
await page.click(List.new("notebook").atIndex(0).build());
|
2020-09-28 14:31:45 +05:00
|
|
|
|
2021-07-07 14:09:51 +05:00
|
|
|
await page.click(getTestId("mnd-new-topic"));
|
|
|
|
|
|
|
|
|
|
await page.type(getTestId("mnd-new-topic-title"), "Topic 1");
|
|
|
|
|
|
|
|
|
|
await page.press(getTestId("mnd-new-topic-title"), "Enter");
|
|
|
|
|
|
2020-12-01 12:55:50 +05:00
|
|
|
await page.click(List.new("notebook").atIndex(0).topic(0).build());
|
2020-09-28 14:31:45 +05:00
|
|
|
|
2021-07-07 14:09:51 +05:00
|
|
|
await page.click(getTestId("dialog-no"));
|
|
|
|
|
|
2020-09-28 14:31:45 +05:00
|
|
|
await expect(isToastPresent()).resolves.toBeTruthy();
|
|
|
|
|
|
|
|
|
|
await navigateTo("notebooks");
|
|
|
|
|
|
|
|
|
|
await page.click(List.new("notebook").atIndex(0).title().build());
|
|
|
|
|
|
|
|
|
|
await page.click(List.new("topic").atIndex(0).title().build());
|
|
|
|
|
|
|
|
|
|
await checkNotePresence(0, false);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-09 23:50:04 +05:00
|
|
|
test.describe("run tests independently", () => {
|
|
|
|
|
/**
|
|
|
|
|
* @type {Page}
|
|
|
|
|
*/
|
|
|
|
|
global.page = null;
|
|
|
|
|
test.beforeEach(async ({ page: _page }) => {
|
|
|
|
|
global.page = _page;
|
|
|
|
|
await page.goto("http://localhost:3000/");
|
2020-09-28 14:31:45 +05:00
|
|
|
});
|
|
|
|
|
|
2021-06-09 23:50:04 +05:00
|
|
|
test("create a note", async () => {
|
|
|
|
|
await createNoteAndCheckPresence();
|
2020-09-28 14:31:45 +05:00
|
|
|
});
|
|
|
|
|
|
2021-06-09 23:50:04 +05:00
|
|
|
test("delete a note", async () => {
|
|
|
|
|
await deleteNoteAndCheckAbsence();
|
|
|
|
|
});
|
2020-09-28 14:31:45 +05:00
|
|
|
|
|
|
|
|
test("restore a note", async () => {
|
2021-06-09 23:50:04 +05:00
|
|
|
const trashItemSelector = await deleteNoteAndCheckAbsence();
|
2020-09-28 14:31:45 +05:00
|
|
|
|
|
|
|
|
await openContextMenu(trashItemSelector);
|
|
|
|
|
|
|
|
|
|
await clickMenuItem("restore");
|
|
|
|
|
|
|
|
|
|
await expect(isToastPresent()).resolves.toBeTruthy();
|
|
|
|
|
|
2020-12-01 12:55:50 +05:00
|
|
|
await navigateTo("notes");
|
2020-09-28 14:31:45 +05:00
|
|
|
|
|
|
|
|
await checkNotePresence();
|
|
|
|
|
});
|
|
|
|
|
|
2021-07-07 14:09:51 +05:00
|
|
|
test("add a note to notebook", async () => {
|
|
|
|
|
const noteSelector = await createNoteAndCheckPresence();
|
2020-09-28 14:31:45 +05:00
|
|
|
|
2021-07-07 14:09:51 +05:00
|
|
|
await openContextMenu(noteSelector);
|
2020-09-28 14:31:45 +05:00
|
|
|
|
2021-07-07 14:09:51 +05:00
|
|
|
await clickMenuItem("addtonotebook(s)");
|
2020-09-28 14:31:45 +05:00
|
|
|
|
2021-07-07 14:09:51 +05:00
|
|
|
await addNoteToNotebook();
|
|
|
|
|
});
|
2020-09-28 14:31:45 +05:00
|
|
|
|
|
|
|
|
test("favorite a note", async () => {
|
|
|
|
|
const noteSelector = await createNoteAndCheckPresence();
|
|
|
|
|
|
|
|
|
|
await useContextMenu(noteSelector, async () => {
|
|
|
|
|
await clickMenuItem("favorite");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await useContextMenu(noteSelector, async () => {
|
|
|
|
|
await expect(
|
|
|
|
|
isPresent(Menu.new("menuitem").item("unfavorite").build())
|
|
|
|
|
).resolves.toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await navigateTo("favorites");
|
|
|
|
|
|
|
|
|
|
await checkNotePresence(0, false);
|
|
|
|
|
|
2020-12-01 12:55:50 +05:00
|
|
|
await navigateTo("notes");
|
2020-09-28 14:31:45 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("unfavorite a note", async () => {
|
|
|
|
|
const noteSelector = await createNoteAndCheckPresence();
|
|
|
|
|
|
2021-06-09 23:50:04 +05:00
|
|
|
await useContextMenu(noteSelector, async () => {
|
|
|
|
|
await clickMenuItem("favorite");
|
|
|
|
|
});
|
2020-09-28 14:31:45 +05:00
|
|
|
|
2020-09-29 15:44:07 +05:00
|
|
|
await page.waitForTimeout(500);
|
|
|
|
|
|
2020-09-28 14:31:45 +05:00
|
|
|
await useContextMenu(noteSelector, async () => {
|
|
|
|
|
await clickMenuItem("unfavorite");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await useContextMenu(noteSelector, async () => {
|
|
|
|
|
await expect(
|
|
|
|
|
isPresent(Menu.new("menuitem").item("favorite").build())
|
|
|
|
|
).resolves.toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("favorite a note from properties", async () => {
|
|
|
|
|
let noteSelector = await createNoteAndCheckPresence();
|
|
|
|
|
|
|
|
|
|
await page.click(getTestId("properties"));
|
|
|
|
|
|
|
|
|
|
await page.click(getTestId("properties-favorite"));
|
|
|
|
|
|
|
|
|
|
await page.click(getTestId("properties-close"));
|
|
|
|
|
|
|
|
|
|
await navigateTo("favorites");
|
|
|
|
|
|
|
|
|
|
noteSelector = await checkNotePresence(0, false);
|
|
|
|
|
|
|
|
|
|
await useContextMenu(noteSelector, async () => {
|
|
|
|
|
await expect(
|
|
|
|
|
isPresent(Menu.new("menuitem").item("unfavorite").build())
|
|
|
|
|
).resolves.toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
|
2020-12-01 12:55:50 +05:00
|
|
|
await navigateTo("notes");
|
2020-09-28 14:31:45 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("assign a color to a note", async () => {
|
|
|
|
|
const noteSelector = await createNoteAndCheckPresence();
|
|
|
|
|
|
|
|
|
|
await openContextMenu(noteSelector);
|
|
|
|
|
|
|
|
|
|
await page.click(Menu.new("menuitem").color("red").build());
|
|
|
|
|
|
|
|
|
|
await page.click(getTestId("properties"));
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
isPresent(getTestId("properties-red-check"))
|
|
|
|
|
).resolves.toBeTruthy();
|
|
|
|
|
|
2021-05-31 00:59:49 +05:00
|
|
|
await page.click(getTestId("properties-close"));
|
|
|
|
|
|
2020-09-28 14:31:45 +05:00
|
|
|
await checkNoteColored(noteSelector);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("pin a note", async () => {
|
|
|
|
|
const noteSelector = await createNoteAndCheckPresence();
|
|
|
|
|
|
|
|
|
|
await useContextMenu(noteSelector, () => clickMenuItem("pin"));
|
|
|
|
|
|
|
|
|
|
await checkNotePinned(noteSelector);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("unpin a note", async () => {
|
|
|
|
|
const noteSelector = await createNoteAndCheckPresence();
|
|
|
|
|
|
2021-06-09 23:50:04 +05:00
|
|
|
await useContextMenu(noteSelector, () => clickMenuItem("pin"));
|
2020-09-28 14:31:45 +05:00
|
|
|
|
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
|
|
|
|
|
|
await useContextMenu(noteSelector, () => clickMenuItem("unpin"));
|
|
|
|
|
|
|
|
|
|
await useContextMenu(noteSelector, () =>
|
|
|
|
|
expect(
|
|
|
|
|
isPresent(Menu.new("menuitem").item("pin").build())
|
|
|
|
|
).resolves.toBeTruthy()
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("pin a note from properties", async () => {
|
|
|
|
|
const noteSelector = await createNoteAndCheckPresence();
|
|
|
|
|
|
|
|
|
|
await page.click(getTestId("properties"));
|
|
|
|
|
|
|
|
|
|
await page.click(getTestId("properties-pinned"));
|
|
|
|
|
|
|
|
|
|
await page.click(getTestId("properties-close"));
|
|
|
|
|
|
2021-05-31 00:59:49 +05:00
|
|
|
await checkNotePinned(noteSelector, true);
|
2020-09-28 14:31:45 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("permanently delete a note", async () => {
|
|
|
|
|
//editor-title //quill
|
|
|
|
|
const trashItemSelector = await deleteNoteAndCheckAbsence();
|
|
|
|
|
|
|
|
|
|
await openContextMenu(trashItemSelector);
|
|
|
|
|
|
|
|
|
|
await clickMenuItem("delete");
|
|
|
|
|
|
|
|
|
|
await confirmDialog();
|
|
|
|
|
|
|
|
|
|
await expect(isToastPresent()).resolves.toBeTruthy();
|
|
|
|
|
|
|
|
|
|
await expect(page.$(trashItemSelector)).resolves.toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
|
2021-05-31 00:59:49 +05:00
|
|
|
test("lock a note", async () => {
|
2020-09-28 14:31:45 +05:00
|
|
|
const noteSelector = await createNoteAndCheckPresence();
|
|
|
|
|
|
|
|
|
|
await lockUnlockNote(noteSelector, "lock");
|
|
|
|
|
|
|
|
|
|
await checkNoteLocked(noteSelector);
|
|
|
|
|
});
|
|
|
|
|
|
2021-05-31 00:59:49 +05:00
|
|
|
test("unlock a note permanently", async () => {
|
2020-09-28 14:31:45 +05:00
|
|
|
const noteSelector = await createNoteAndCheckPresence();
|
|
|
|
|
|
|
|
|
|
await lockUnlockNote(noteSelector, "lock");
|
|
|
|
|
|
2021-06-09 23:50:04 +05:00
|
|
|
await page.waitForTimeout(1000);
|
2020-12-01 12:55:50 +05:00
|
|
|
|
2020-09-28 14:31:45 +05:00
|
|
|
await lockUnlockNote(noteSelector, "unlock");
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
isAbsent(List.new("note").grouped().atIndex(0).locked().build())
|
|
|
|
|
).resolves.toBeTruthy();
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
page.textContent(List.new("note").grouped().atIndex(0).body().build())
|
|
|
|
|
).resolves.toContain(NOTE.content);
|
|
|
|
|
|
|
|
|
|
await openContextMenu(noteSelector);
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
isPresent(Menu.new("menuitem").item("lock").build())
|
|
|
|
|
).resolves.toBeTruthy();
|
|
|
|
|
|
|
|
|
|
await closeContextMenu(noteSelector);
|
|
|
|
|
});
|
|
|
|
|
|
2021-05-31 00:59:49 +05:00
|
|
|
test("lock a note from properties", async () => {
|
2020-09-28 14:31:45 +05:00
|
|
|
const noteSelector = await createNoteAndCheckPresence();
|
|
|
|
|
|
|
|
|
|
await page.click(getTestId("properties"));
|
|
|
|
|
|
|
|
|
|
await page.click(getTestId("properties-locked"));
|
|
|
|
|
|
2020-12-01 12:55:50 +05:00
|
|
|
await page.fill(getTestId("dialog-password"), "123abc123abc");
|
2020-09-28 14:31:45 +05:00
|
|
|
|
|
|
|
|
await confirmDialog();
|
|
|
|
|
|
|
|
|
|
// TODO fix this: no toast is shown when locking note from properties.
|
|
|
|
|
//await expect(isToastPresent()).resolves.toBeTruthy();
|
|
|
|
|
|
|
|
|
|
await checkNoteLocked(noteSelector);
|
|
|
|
|
});
|
|
|
|
|
|
2021-07-07 14:09:51 +05:00
|
|
|
test("add a note to notebook from properties", async () => {
|
|
|
|
|
await createNoteAndCheckPresence();
|
2020-09-28 14:31:45 +05:00
|
|
|
|
2021-07-07 14:09:51 +05:00
|
|
|
await page.click(getTestId("properties"));
|
2020-09-28 14:31:45 +05:00
|
|
|
|
2021-07-07 14:09:51 +05:00
|
|
|
await page.click(getTestId("properties-add-to-nb"));
|
2020-09-28 14:31:45 +05:00
|
|
|
|
2021-07-07 14:09:51 +05:00
|
|
|
await addNoteToNotebook();
|
|
|
|
|
});
|
2020-09-28 14:31:45 +05:00
|
|
|
|
|
|
|
|
test("assign a color to note from properties", async () => {
|
|
|
|
|
const noteSelector = await createNoteAndCheckPresence();
|
|
|
|
|
|
|
|
|
|
await page.click(getTestId("properties"));
|
|
|
|
|
|
|
|
|
|
await page.click(getTestId("properties-red"));
|
|
|
|
|
|
|
|
|
|
await checkNoteColored(noteSelector);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("tag with words from properties", async () => {
|
|
|
|
|
await createNoteAndCheckPresence();
|
|
|
|
|
|
|
|
|
|
await page.click(getTestId("properties"));
|
|
|
|
|
|
|
|
|
|
await page.fill(getTestId("properties-tag"), "testtag");
|
|
|
|
|
|
|
|
|
|
await page.press(getTestId("properties-tag"), "Enter");
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
isPresent(getTestId("properties-tag-testtag"))
|
|
|
|
|
).resolves.toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
});
|