web: fix real time sync test

This commit is contained in:
Abdullah Atta
2024-05-10 11:58:56 +05:00
parent fde45fb6de
commit 3c8b8a7bc9
3 changed files with 11 additions and 10 deletions

View File

@@ -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" });

View File

@@ -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) {

View File

@@ -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
};