2022-09-20 18:33:55 +05:00
|
|
|
/*
|
|
|
|
|
This file is part of the Notesnook project (https://notesnook.com/)
|
|
|
|
|
|
2023-01-16 13:44:52 +05:00
|
|
|
Copyright (C) 2023 Streetwriters (Private) Limited
|
2022-09-20 18:33:55 +05:00
|
|
|
|
|
|
|
|
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, Browser, expect } from "@playwright/test";
|
|
|
|
|
import { AppModel } from "./models/app.model";
|
|
|
|
|
import { USER } from "./utils";
|
|
|
|
|
|
2025-01-29 15:04:24 +05:00
|
|
|
// run this test file sequentially
|
|
|
|
|
test.describe.configure({ mode: "serial" });
|
|
|
|
|
|
2022-09-20 18:33:55 +05:00
|
|
|
async function createDevice(browser: Browser) {
|
|
|
|
|
// Create two isolated browser contexts
|
|
|
|
|
const context = await browser.newContext();
|
|
|
|
|
const page = await context.newPage();
|
|
|
|
|
|
|
|
|
|
const app = new AppModel(page);
|
|
|
|
|
await app.auth.goto();
|
|
|
|
|
await app.auth.login(USER.CURRENT);
|
2024-03-26 11:45:03 +05:00
|
|
|
await app.waitForSync("synced");
|
2022-09-20 18:33:55 +05:00
|
|
|
|
|
|
|
|
return app;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function actAndSync<T>(
|
|
|
|
|
devices: AppModel[],
|
|
|
|
|
...actions: (Promise<T> | undefined)[]
|
|
|
|
|
) {
|
|
|
|
|
const results = await Promise.all([
|
|
|
|
|
...actions.filter((a) => !!a),
|
2024-05-10 11:58:56 +05:00
|
|
|
...devices.map((d) =>
|
|
|
|
|
d.waitForSync("syncing").then(() => d.waitForSync("synced"))
|
|
|
|
|
)
|
2022-09-20 18:33:55 +05:00
|
|
|
]);
|
2022-11-23 16:21:56 +05:00
|
|
|
|
|
|
|
|
await Promise.all(devices.map((d) => d.page.waitForTimeout(2000)));
|
2022-09-20 18:33:55 +05:00
|
|
|
return results.slice(0, actions.length) as T[];
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-29 15:04:24 +05:00
|
|
|
test(`content edits in a note opened on 2 devices in multiple tabs should sync in real-time`, async ({
|
2022-09-20 18:33:55 +05:00
|
|
|
browser
|
|
|
|
|
}, info) => {
|
2025-01-29 15:04:24 +05:00
|
|
|
const NOTE = {
|
|
|
|
|
title: `Note ${makeid(20)}`
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-05 16:27:42 +05:00
|
|
|
info.setTimeout(70 * 1000);
|
2022-09-20 18:33:55 +05:00
|
|
|
const newContent = makeid(24).repeat(2);
|
|
|
|
|
|
|
|
|
|
const [deviceA, deviceB] = await Promise.all([
|
|
|
|
|
createDevice(browser),
|
|
|
|
|
createDevice(browser)
|
|
|
|
|
]);
|
2024-05-10 11:58:56 +05:00
|
|
|
|
2022-09-20 18:33:55 +05:00
|
|
|
const [notesA, notesB] = await Promise.all(
|
|
|
|
|
[deviceA, deviceB].map((d) => d.goToNotes())
|
|
|
|
|
);
|
2024-11-13 18:13:16 +05:00
|
|
|
const noteB = (
|
|
|
|
|
await actAndSync([deviceA, deviceB], notesB.createNote(NOTE))
|
|
|
|
|
)[0];
|
2022-09-20 18:33:55 +05:00
|
|
|
const noteA = await notesA.findNote(NOTE);
|
|
|
|
|
await Promise.all([noteA, noteB].map((note) => note?.openNote()));
|
2025-01-29 15:04:24 +05:00
|
|
|
await noteA?.openNote(true);
|
2022-09-20 18:33:55 +05:00
|
|
|
|
2023-12-26 11:49:29 +05:00
|
|
|
if ((await notesB.editor.getContent("text")) !== "")
|
|
|
|
|
await actAndSync([deviceA, deviceB], notesB.editor.clear());
|
2024-05-10 11:58:56 +05:00
|
|
|
await expect(notesA.editor.content).toBeEmpty();
|
|
|
|
|
await expect(notesB.editor.content).toBeEmpty();
|
2022-09-20 18:33:55 +05:00
|
|
|
await actAndSync([deviceA, deviceB], notesB.editor.setContent(newContent));
|
2022-09-21 14:01:32 +05:00
|
|
|
|
2022-09-20 18:33:55 +05:00
|
|
|
expect(noteA).toBeDefined();
|
|
|
|
|
expect(noteB).toBeDefined();
|
2024-03-26 11:45:03 +05:00
|
|
|
await expect(notesA.editor.content).toHaveText(newContent);
|
|
|
|
|
await expect(notesB.editor.content).toHaveText(newContent);
|
2025-01-29 15:04:24 +05:00
|
|
|
const tabsA = await notesA.editor.getTabs();
|
|
|
|
|
await tabsA[0].click();
|
|
|
|
|
await expect(notesA.editor.content).toHaveText(newContent);
|
|
|
|
|
|
|
|
|
|
await (await deviceA.goToSettings())?.logout();
|
|
|
|
|
await (await deviceB.goToSettings())?.logout();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test(`title edits in a note opened on 2 devices in multiple tabs should sync in real-time`, async ({
|
|
|
|
|
browser
|
|
|
|
|
}, info) => {
|
|
|
|
|
const NOTE = {
|
|
|
|
|
title: `Note ${makeid(20)}`
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
info.setTimeout(70 * 1000);
|
|
|
|
|
const newContent = makeid(24).repeat(2);
|
|
|
|
|
|
|
|
|
|
const [deviceA, deviceB] = await Promise.all([
|
|
|
|
|
createDevice(browser),
|
|
|
|
|
createDevice(browser)
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const [notesA, notesB] = await Promise.all(
|
|
|
|
|
[deviceA, deviceB].map((d) => d.goToNotes())
|
|
|
|
|
);
|
|
|
|
|
const noteB = (
|
|
|
|
|
await actAndSync([deviceA, deviceB], notesB.createNote(NOTE))
|
|
|
|
|
)[0];
|
|
|
|
|
const noteA = await notesA.findNote(NOTE);
|
|
|
|
|
await Promise.all([noteA, noteB].map((note) => note?.openNote()));
|
|
|
|
|
await noteA?.openNote(true);
|
|
|
|
|
|
|
|
|
|
if ((await notesB.editor.getContent("text")) !== "")
|
|
|
|
|
await actAndSync([deviceA, deviceB], notesB.editor.clear());
|
|
|
|
|
await expect(notesA.editor.content).toBeEmpty();
|
|
|
|
|
await expect(notesB.editor.content).toBeEmpty();
|
|
|
|
|
await actAndSync([deviceA, deviceB], notesB.editor.setTitle(newContent));
|
|
|
|
|
|
|
|
|
|
expect(noteA).toBeDefined();
|
|
|
|
|
expect(noteB).toBeDefined();
|
|
|
|
|
expect(await notesA.editor.getTitle()).toBe(newContent);
|
|
|
|
|
expect(await notesB.editor.getTitle()).toBe(newContent);
|
|
|
|
|
const tabsA = await notesA.editor.getTabs();
|
|
|
|
|
await tabsA[0].click();
|
|
|
|
|
expect(await notesA.editor.getTitle()).toBe(newContent);
|
2024-05-10 11:58:56 +05:00
|
|
|
|
|
|
|
|
await (await deviceA.goToSettings())?.logout();
|
|
|
|
|
await (await deviceB.goToSettings())?.logout();
|
2022-09-20 18:33:55 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function makeid(length: number) {
|
|
|
|
|
let result = "";
|
|
|
|
|
const characters =
|
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
|
|
|
const charactersLength = characters.length;
|
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|