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
web: add sorting tests for notes, notebooks, tags & topics (#1490)
Muhammad Ali00da012b3fbd
diff --git a/apps/web/__e2e__/models/base-view.model.ts b/apps/web/__e2e__/models/base-view.model.tsindex 5039b84d7..8a44e258f 100644--- a/apps/web/__e2e__/models/base-view.model.ts+++ b/apps/web/__e2e__/models/base-view.model.ts@@ -20,11 +20,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import { Locator, Page } from "@playwright/test";import { getTestId } from "../utils";import { iterateList } from "./utils";+import { ContextMenuModel } from "./context-menu.model";+import { SortOptions } from "./types";export class BaseViewModel {protected readonly page: Page;protected readonly list: Locator;private readonly listPlaceholder: Locator;+ private readonly sortByButton: Locator;constructor(page: Page, pageId: string) {this.page = page;@@ -32,6 +35,8 @@ export class BaseViewModel {this.listPlaceholder = page.locator(`#${pageId} >> ${getTestId("list-placeholder")}`);++ this.sortByButton = this.list.locator(getTestId("sort-icon-button"));}async findGroup(groupName: string) {@@ -94,4 +99,25 @@ export class BaseViewModel {await itemList.press(key);await this.page.waitForTimeout(300);}++ async sort(sort: SortOptions) {+ const contextMenu: ContextMenuModel = new ContextMenuModel(this.page);++ contextMenu.open(this.sortByButton, "left");+ await contextMenu.clickOnItem("groupBy");+ await contextMenu.clickOnItem(sort.groupBy);++ await contextMenu.open(this.sortByButton, "left");+ await contextMenu.clickOnItem("sortDirection");+ await contextMenu.clickOnItem(sort.orderBy);++ contextMenu.open(this.sortByButton, "left");+ await contextMenu.clickOnItem("sortBy");+ await contextMenu.clickOnItem(sort.sortBy);+ }++ async isEmpty() {+ const totalItems = await this.list.locator(getTestId("list-item")).count();+ return totalItems <= 0;+ }}diff --git a/apps/web/__e2e__/models/context-menu.model.ts b/apps/web/__e2e__/models/context-menu.model.tsindex b2a1e859c..9ff8bd85a 100644--- a/apps/web/__e2e__/models/context-menu.model.ts+++ b/apps/web/__e2e__/models/context-menu.model.ts@@ -30,8 +30,11 @@ export class ContextMenuModel {return await this.titleText.textContent();}- async open(locator: Locator) {- await locator.click({ button: "right" });+ async open(+ locator: Locator,+ button: "left" | "right" | "middle" | undefined = "right"+ ) {+ await locator.click({ button });await this.titleText.waitFor();}diff --git a/apps/web/__e2e__/models/types.ts b/apps/web/__e2e__/models/types.tsindex bed005cd2..613e80a3c 100644--- a/apps/web/__e2e__/models/types.ts+++ b/apps/web/__e2e__/models/types.ts@@ -28,3 +28,23 @@ export type Item = {};export type PriceItem = { label: string; value: string };++export type OrderByOptions = "asc" | "desc";+export type SortByOptions =+ | "dateCreated"+ | "dateEdited"+ | "dateModified"+ | "title";+export type GroupByOptions =+ | "abc"+ | "none"+ | "default"+ | "year"+ | "month"+ | "week";++export type SortOptions = {+ groupBy: GroupByOptions;+ sortBy: SortByOptions;+ orderBy: OrderByOptions;+};diff --git a/apps/web/__e2e__/notebooks.test.ts b/apps/web/__e2e__/notebooks.test.tsindex 826af403b..1318c2a71 100644--- a/apps/web/__e2e__/notebooks.test.ts+++ b/apps/web/__e2e__/notebooks.test.ts@@ -20,7 +20,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import { test, expect } from "@playwright/test";import { AppModel } from "./models/app.model";import { Item, Notebook } from "./models/types";-import { NOTE, NOTEBOOK } from "./utils";+import {+ groupByOptions,+ NOTE,+ NOTEBOOK,+ orderByOptions,+ sortByOptions+} from "./utils";test("create a notebook", async ({ page }) => {const app = new AppModel(page);@@ -223,3 +229,32 @@ test("remove shortcut of a topic", async ({ page }) => {const allShortcuts = await app.navigation.getShortcuts();expect(allShortcuts.includes(NOTEBOOK.topics[0])).toBeFalsy();});++test(`sort notebooks`, async ({ page }, info) => {+ info.setTimeout(60 * 1000);++ const app = new AppModel(page);+ await app.goto();+ const notebooks = await app.goToNotebooks();+ const titles = ["G ", "C ", "Gz", "2 ", "A "];+ for (const title of titles) {+ NOTEBOOK.title = title + NOTEBOOK.title;+ await notebooks.createNotebook(NOTEBOOK);+ }++ for (const groupBy of groupByOptions) {+ for (const sortBy of sortByOptions) {+ for (const orderBy of orderByOptions) {+ await test.step(`group by ${groupBy}, sort by ${sortBy}, order by ${orderBy}`, async () => {+ await notebooks?.sort({+ groupBy,+ orderBy,+ sortBy+ });++ expect(await notebooks.isEmpty()).toBeFalsy();+ });+ }+ }+ }+});diff --git a/apps/web/__e2e__/notes.test.ts b/apps/web/__e2e__/notes.test.tsindex c0a8ac0ed..8b4df541d 100644--- a/apps/web/__e2e__/notes.test.ts+++ b/apps/web/__e2e__/notes.test.ts@@ -19,7 +19,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import { test, expect } from "@playwright/test";import { AppModel } from "./models/app.model";-import { NOTE, PASSWORD } from "./utils";+import {+ groupByOptions,+ NOTE,+ orderByOptions,+ PASSWORD,+ sortByOptions+} from "./utils";test("create a note", async ({ page }) => {const app = new AppModel(page);@@ -273,3 +279,34 @@ test("change title of a locked note", async ({ page }) => {expect(await note?.getTitle()).toContain(title);expect(await notes.editor.getTitle()).toContain(title);});++test(`sort notes`, async ({ page }, info) => {+ info.setTimeout(60 * 1000);++ const app = new AppModel(page);+ await app.goto();+ const notes = await app.goToNotes();+ const titles = ["G ", "C ", "Gz", "2 ", "A "];+ for (const title of titles) {+ await notes.createNote({+ title: `${title} is Title`,+ content: "This is test".repeat(10)+ });+ }++ for (const groupBy of groupByOptions) {+ for (const sortBy of sortByOptions) {+ for (const orderBy of orderByOptions) {+ await test.step(`group by ${groupBy}, sort by ${sortBy}, order by ${orderBy}`, async () => {+ await notes?.sort({+ groupBy,+ orderBy,+ sortBy+ });++ expect(await notes.isEmpty()).toBeFalsy();+ });+ }+ }+ }+});diff --git a/apps/web/__e2e__/tags.test.ts b/apps/web/__e2e__/tags.test.tsindex e328a90a4..a08d4f500 100644--- a/apps/web/__e2e__/tags.test.ts+++ b/apps/web/__e2e__/tags.test.ts@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import { test, expect } from "@playwright/test";import { AppModel } from "./models/app.model";import { Item } from "./models/types";-import { NOTE } from "./utils";+import { groupByOptions, NOTE, orderByOptions, sortByOptions } from "./utils";const TAG: Item = { title: "hello-world" };const EDITED_TAG: Item = { title: "hello-world-2" };@@ -176,3 +176,32 @@ test("delete the last note of a tag that is also a shortcut", async ({expect(await app.getRouteHeader()).toBe("Notes");});++test(`sort tags`, async ({ page }, info) => {+ info.setTimeout(60 * 1000);++ const app = new AppModel(page);+ await app.goto();+ const tags = await app.goToTags();+ const titles = ["G", "C", "Gz", "2", "A"];+ for (const title of titles) {+ const tag = await tags.createItem({ title: `${title}` });+ if (!tag) continue;+ }++ for (const groupBy of groupByOptions) {+ for (const sortBy of sortByOptions) {+ for (const orderBy of orderByOptions) {+ await test.step(`group by ${groupBy}, sort by ${sortBy}, order by ${orderBy}`, async () => {+ await tags?.sort({+ groupBy,+ orderBy,+ sortBy+ });++ expect(await tags.isEmpty()).toBeFalsy();+ });+ }+ }+ }+});diff --git a/apps/web/__e2e__/topics.test.ts b/apps/web/__e2e__/topics.test.tsnew file mode 100644index 000000000..6a3bcd5ad--- /dev/null+++ b/apps/web/__e2e__/topics.test.ts@@ -0,0 +1,55 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2022 Streetwriters (Private) Limited++This program is free software: you can redistribute it and/or modify+it under the terms of the GNU General Public License as published by+the Free Software Foundation, either version 3 of the License, or+(at your option) any later version.++This program is distributed in the hope that it will be useful,+but WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+GNU General Public License for more details.++You should have received a copy of the GNU General Public License+along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++import { test, expect } from "@playwright/test";+import { AppModel } from "./models/app.model";+import {+ groupByOptions,+ NOTEBOOK,+ sortByOptions,+ orderByOptions+} from "./utils";++test(`sort topics`, async ({ page }, info) => {+ info.setTimeout(60 * 1000);++ const app = new AppModel(page);+ await app.goto();+ const notebooks = await app.goToNotebooks();+ const notebook = await notebooks.createNotebook({+ ...NOTEBOOK,+ topics: ["title1", "title2", "title3", "title4", "title5"]+ });+ const topics = await notebook?.openNotebook();++ for (const groupBy of groupByOptions) {+ for (const sortBy of sortByOptions) {+ for (const orderBy of orderByOptions) {+ await test.step(`group by ${groupBy}, sort by ${sortBy}, order by ${orderBy}`, async () => {+ await topics?.sort({+ groupBy,+ orderBy,+ sortBy+ });+ expect(await topics?.isEmpty()).toBeFalsy();+ });+ }+ }+ }+});diff --git a/apps/web/__e2e__/utils/index.ts b/apps/web/__e2e__/utils/index.tsindex 1ddd95f59..8c2bb8e7d 100644--- a/apps/web/__e2e__/utils/index.ts+++ b/apps/web/__e2e__/utils/index.ts@@ -21,6 +21,7 @@ import fs from "fs";import dotenv from "dotenv";import path from "path";import { Locator, Page } from "@playwright/test";+import { GroupByOptions, OrderByOptions, SortByOptions } from "../models/types";type Note = {title: string;@@ -108,6 +109,17 @@ function isTestAll() {return process.env.TEST_ALL === "true";}+const orderByOptions: OrderByOptions[] = ["asc", "desc"];+const sortByOptions: SortByOptions[] = ["dateCreated", "dateEdited"];+const groupByOptions: GroupByOptions[] = [+ "abc",+ "none",+ "default",+ "year",+ "month",+ "week"+];+export {USER,NOTE,@@ -118,5 +130,8 @@ export {createNote,editNote,downloadAndReadFile,- isTestAll+ isTestAll,+ orderByOptions,+ sortByOptions,+ groupByOptions};diff --git a/apps/web/src/components/group-header/index.js b/apps/web/src/components/group-header/index.jsindex ce54d04ac..d9118b3a5 100644--- a/apps/web/src/components/group-header/index.js+++ b/apps/web/src/components/group-header/index.js@@ -247,6 +247,7 @@ function GroupHeader(props) {{index === 0 && (<Flex mr={1}><IconButton+ testId="sort-icon-button"icon={groupOptions.sortDirection === "asc"? Icon.SortAsc@@ -288,7 +289,7 @@ function GroupHeader(props) {export default GroupHeader;function IconButton(props) {- const { text, title, onClick } = props;+ const { text, title, onClick, testId } = props;const isMobile = useMobile();return (<Button@@ -297,6 +298,7 @@ function IconButton(props) {title={title}p={"2px"}mr={[2, 0]}+ data-test-id={testId}sx={{ ":last-of-type": { mr: 0 }, alignItems: "center", display: "flex" }}onClick={(e) => {e.stopPropagation();