mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-16 19:57:52 +01:00
* test: intialize testing environment * test: add an example test for reference * test: add simple navigation test * some initial tests * some changes * name and other small changes * permanently delete a note * permanenlt delete a note * test: improve test readability I have added different id builders for building test ids. They make the tests more readable and fluent. * test lock a note * test add a note to notebook * test favorite a note * test pin a note * test: further improve test readability basically I refactored some frequently performed actions into helper functions * test: check for presence of toast * test: properly test pinned note * test: increase tests reliability * test: fix all tests * perf: load 2co script & fonts when needed * ci: initialize e2e gh test runner * ci: do not run npm ci * test: fix lock note test for all browsers * ci: fix playwright tests * ci: fix yaml syntax error * ci: no need to use custom ssh-agent action for eslint * test: improve lock a note test * ci: add GH_DEPLOY_KEY env in eslint.yml * test: check for state: "visible" in isPresent * test: do not check for toast in lock a note test * test: log crypto error to console * test: skip "lock a note" test for now until further investigation * ci: only run tests on firefox & chromium * fix: fix useMediaQuery for WebKit browsers * ci: try webkit once again * properties tests * test tag a color /properties * test: run some tests sequentially and independently * test: reenable all tests * fix: user only able to type on character in title box * test: skip lock/unlock tests in CI * test edit a notebook * test: fix all tests * test: fix and add more notebook tests * test: do not only run edit topics test * test: make sure all notes tests pass * test: skip add note to notebook tests for now * test: make sure all tests pass Co-authored-by: alihamuh <alihamuh@gmail.com>
146 lines
3.9 KiB
JavaScript
146 lines
3.9 KiB
JavaScript
/* eslint-disable no-undef */
|
|
const { getTestId, createNote, NOTE, NOTEBOOK } = require("./utils");
|
|
const {
|
|
navigateTo,
|
|
openContextMenu,
|
|
useContextMenu,
|
|
clickMenuItem,
|
|
} = require("./utils/actions");
|
|
const List = require("./utils/listitemidbuilder");
|
|
const Menu = require("./utils/menuitemidbuilder");
|
|
const { checkNotePresence } = require("./utils/conditions");
|
|
|
|
beforeEach(async () => {
|
|
page = await browser.newPage();
|
|
await page.goto("http://localhost:3000/");
|
|
}, 600000);
|
|
|
|
afterEach(async () => page.close());
|
|
|
|
async function fillNotebookDialog(notebook) {
|
|
await page.fill(getTestId("dialog-nb-name"), notebook.title);
|
|
|
|
await page.fill(getTestId("dialog-nb-description"), notebook.description);
|
|
|
|
for (let i = 0; i < notebook.topics.length; ++i) {
|
|
let topic = notebook.topics[i];
|
|
|
|
await page.fill(getTestId(`dialog-topic-name-${i}`), topic);
|
|
|
|
if (!(await page.$(getTestId(`dialog-topic-name-${i + 1}`))))
|
|
await page.click(getTestId("dialog-add-topic"));
|
|
}
|
|
|
|
await page.click(getTestId("dialog-yes"));
|
|
}
|
|
|
|
async function createNotebook(notebook) {
|
|
await page.click(getTestId("notebooks-action-button"));
|
|
|
|
await fillNotebookDialog(notebook);
|
|
}
|
|
|
|
async function createNoteAndCheckPresence(note = NOTE) {
|
|
await createNote(note, "notes");
|
|
|
|
// make sure the note has saved.
|
|
await page.waitForTimeout(1000);
|
|
|
|
return await checkNotePresence(0, false, note);
|
|
}
|
|
|
|
async function checkNotebookPresence(notebook) {
|
|
const notebookIdBuilder = List.new("notebook").atIndex(0);
|
|
|
|
await expect(
|
|
page.textContent(notebookIdBuilder.title().build())
|
|
).resolves.toBe(notebook.title);
|
|
|
|
await expect(
|
|
page.textContent(notebookIdBuilder.body().build())
|
|
).resolves.toBe(notebook.description);
|
|
|
|
await page.click(List.new("notebook").atIndex(0).title().build());
|
|
|
|
await expect(
|
|
page.textContent(List.new("topic").atIndex(0).title().build())
|
|
).resolves.toBe("General");
|
|
|
|
for (let i = 0; i < notebook.topics.length; ++i) {
|
|
let topic = notebook.topics[i];
|
|
await expect(
|
|
page.textContent(
|
|
List.new("topic")
|
|
.atIndex(i + 1)
|
|
.title()
|
|
.build()
|
|
)
|
|
).resolves.toBe(topic);
|
|
}
|
|
|
|
await page.click(getTestId("go-back"));
|
|
|
|
return notebookIdBuilder.build();
|
|
}
|
|
|
|
async function createNotebookAndCheckPresence(notebook = NOTEBOOK) {
|
|
await navigateTo("notebooks");
|
|
|
|
await createNotebook(notebook);
|
|
|
|
return await checkNotebookPresence(notebook);
|
|
}
|
|
|
|
test("create a notebook", createNotebookAndCheckPresence);
|
|
|
|
test("create a note inside a notebook", async () => {
|
|
const notebookSelector = await createNotebookAndCheckPresence();
|
|
|
|
await page.click(notebookSelector);
|
|
|
|
await page.click(List.new("topic").atIndex(1).build());
|
|
|
|
await createNoteAndCheckPresence();
|
|
});
|
|
|
|
test("edit a notebook", async () => {
|
|
const notebookSelector = await createNotebookAndCheckPresence();
|
|
|
|
await useContextMenu(notebookSelector, () => clickMenuItem("edit"));
|
|
|
|
const editedNotebook = {
|
|
title: "An Edited Notebook",
|
|
description: "A new edited description",
|
|
topics: ["Topic 1", "Topic 2", "Topic 3", "Topic 4", "Topic 5"],
|
|
};
|
|
|
|
await fillNotebookDialog(editedNotebook);
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
await checkNotebookPresence(editedNotebook);
|
|
});
|
|
|
|
test("edit topics individually", async () => {
|
|
const notebookSelector = await createNotebookAndCheckPresence();
|
|
|
|
await page.click(notebookSelector);
|
|
|
|
for (let index = 1; index < 4; index++) {
|
|
await openContextMenu(List.new("topic").atIndex(index).build());
|
|
|
|
await page.click(Menu.new("menuitem").item("edit").build());
|
|
|
|
const editedTopicTitle = "Topic " + index + " edit 1";
|
|
await page.fill(getTestId("edit-topic-dialog"), editedTopicTitle);
|
|
|
|
await page.click(getTestId("dialog-yes"));
|
|
|
|
await page.waitForTimeout(500);
|
|
|
|
await expect(
|
|
page.textContent(List.new("topic").atIndex(index).title().build())
|
|
).resolves.toBe(editedTopicTitle);
|
|
}
|
|
});
|