mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 04:00:59 +01:00
web: fix real time sync test
This commit is contained in:
@@ -123,7 +123,7 @@ export class AppModel {
|
||||
);
|
||||
}
|
||||
|
||||
async waitForSync(state: "completed" | "synced" = "completed") {
|
||||
async waitForSync(state: "completed" | "synced" | "syncing" = "completed") {
|
||||
await this.page
|
||||
.locator(getTestId(`sync-status-${state}`))
|
||||
.waitFor({ state: "visible" });
|
||||
|
||||
@@ -19,7 +19,6 @@ 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";
|
||||
import exp from "constants";
|
||||
|
||||
async function createDevice(browser: Browser) {
|
||||
// Create two isolated browser contexts
|
||||
@@ -40,7 +39,9 @@ async function actAndSync<T>(
|
||||
) {
|
||||
const results = await Promise.all([
|
||||
...actions.filter((a) => !!a),
|
||||
...devices.map((d) => d.waitForSync("synced"))
|
||||
...devices.map((d) =>
|
||||
d.waitForSync("syncing").then(() => d.waitForSync("synced"))
|
||||
)
|
||||
]);
|
||||
|
||||
await Promise.all(devices.map((d) => d.page.waitForTimeout(2000)));
|
||||
@@ -61,6 +62,7 @@ test(`edits in a note opened on 2 devices should sync in real-time`, async ({
|
||||
createDevice(browser),
|
||||
createDevice(browser)
|
||||
]);
|
||||
|
||||
const [notesA, notesB] = await Promise.all(
|
||||
[deviceA, deviceB].map((d) => d.goToNotes())
|
||||
);
|
||||
@@ -72,14 +74,17 @@ test(`edits in a note opened on 2 devices should sync in real-time`, async ({
|
||||
|
||||
if ((await notesB.editor.getContent("text")) !== "")
|
||||
await actAndSync([deviceA, deviceB], notesB.editor.clear());
|
||||
await expect(notesA.editor.content).toHaveText("");
|
||||
await expect(notesB.editor.content).toHaveText("");
|
||||
await expect(notesA.editor.content).toBeEmpty();
|
||||
await expect(notesB.editor.content).toBeEmpty();
|
||||
await actAndSync([deviceA, deviceB], notesB.editor.setContent(newContent));
|
||||
|
||||
expect(noteA).toBeDefined();
|
||||
expect(noteB).toBeDefined();
|
||||
await expect(notesA.editor.content).toHaveText(newContent);
|
||||
await expect(notesB.editor.content).toHaveText(newContent);
|
||||
|
||||
await (await deviceA.goToSettings())?.logout();
|
||||
await (await deviceB.goToSettings())?.logout();
|
||||
});
|
||||
|
||||
function makeid(length: number) {
|
||||
|
||||
@@ -70,11 +70,7 @@ class AppStore extends BaseStore<AppStore> {
|
||||
isSyncEnabled = Config.get("syncEnabled", true);
|
||||
isRealtimeSyncEnabled = Config.get("isRealtimeSyncEnabled", true);
|
||||
syncStatus: SyncStatus = {
|
||||
key: navigator.onLine
|
||||
? Config.get("syncEnabled", true)
|
||||
? "synced"
|
||||
: "disabled"
|
||||
: "offline",
|
||||
key: navigator.onLine ? "disabled" : "offline",
|
||||
progress: null,
|
||||
type: undefined
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user