mirror of https://github.com/vector-im/riot-web
Stabilise sliding sync playwright test (#28879)
* Stabilise sliding sync playwright test There's no guarantee that the unsubscription & subscription occur in the same request given the add/remove APIs are async Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Stabilise more sliding sync tests Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>pull/28673/merge
parent
6846679d34
commit
5caad70191
|
@ -371,37 +371,42 @@ test.describe("Sliding Sync", () => {
|
||||||
roomIds.push(id);
|
roomIds.push(id);
|
||||||
await expect(page.getByRole("treeitem", { name: fruit })).toBeVisible();
|
await expect(page.getByRole("treeitem", { name: fruit })).toBeVisible();
|
||||||
}
|
}
|
||||||
const [roomAId, roomPId] = roomIds;
|
const [roomAId, roomPId, roomOId] = roomIds;
|
||||||
|
|
||||||
const assertUnsubExists = (request: Request, subRoomId: string, unsubRoomId: string) => {
|
const matchRoomSubRequest = (subRoomId: string) => (request: Request) => {
|
||||||
|
if (!request.url().includes("/sync")) return false;
|
||||||
const body = request.postDataJSON();
|
const body = request.postDataJSON();
|
||||||
// There may be a request without a txn_id, ignore it, as there won't be any subscription changes
|
return body.txn_id && body.room_subscriptions?.[subRoomId];
|
||||||
if (body.txn_id === undefined) {
|
};
|
||||||
return;
|
const matchRoomUnsubRequest = (unsubRoomId: string) => (request: Request) => {
|
||||||
}
|
if (!request.url().includes("/sync")) return false;
|
||||||
expect(body.unsubscribe_rooms).toEqual([unsubRoomId]);
|
const body = request.postDataJSON();
|
||||||
expect(body.room_subscriptions).not.toHaveProperty(unsubRoomId);
|
return (
|
||||||
expect(body.room_subscriptions).toHaveProperty(subRoomId);
|
body.txn_id && body.unsubscribe_rooms?.includes(unsubRoomId) && !body.room_subscriptions?.[unsubRoomId]
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
let promise = page.waitForRequest(/sync/);
|
// Select the Test Room and wait for playwright to get the request
|
||||||
|
const [request] = await Promise.all([
|
||||||
// Select the Test Room
|
page.waitForRequest(matchRoomSubRequest(roomAId)),
|
||||||
await page.getByRole("treeitem", { name: "Apple", exact: true }).click();
|
page.getByRole("treeitem", { name: "Apple", exact: true }).click(),
|
||||||
|
]);
|
||||||
// and wait for playwright to get the request
|
const roomSubscriptions = request.postDataJSON().room_subscriptions;
|
||||||
const roomSubscriptions = (await promise).postDataJSON().room_subscriptions;
|
|
||||||
expect(roomSubscriptions, "room_subscriptions is object").toBeDefined();
|
expect(roomSubscriptions, "room_subscriptions is object").toBeDefined();
|
||||||
|
|
||||||
// Switch to another room
|
// Switch to another room and wait for playwright to get the request
|
||||||
promise = page.waitForRequest(/sync/);
|
await Promise.all([
|
||||||
await page.getByRole("treeitem", { name: "Pineapple", exact: true }).click();
|
page.waitForRequest(matchRoomSubRequest(roomPId)),
|
||||||
assertUnsubExists(await promise, roomPId, roomAId);
|
page.waitForRequest(matchRoomUnsubRequest(roomAId)),
|
||||||
|
page.getByRole("treeitem", { name: "Pineapple", exact: true }).click(),
|
||||||
|
]);
|
||||||
|
|
||||||
// And switch to even another room
|
// And switch to even another room and wait for playwright to get the request
|
||||||
promise = page.waitForRequest(/sync/);
|
await Promise.all([
|
||||||
await page.getByRole("treeitem", { name: "Apple", exact: true }).click();
|
page.waitForRequest(matchRoomSubRequest(roomOId)),
|
||||||
assertUnsubExists(await promise, roomPId, roomAId);
|
page.waitForRequest(matchRoomUnsubRequest(roomPId)),
|
||||||
|
page.getByRole("treeitem", { name: "Orange", exact: true }).click(),
|
||||||
|
]);
|
||||||
|
|
||||||
// TODO: Add tests for encrypted rooms
|
// TODO: Add tests for encrypted rooms
|
||||||
});
|
});
|
||||||
|
|
|
@ -167,6 +167,7 @@ export const test = base.extend<Fixtures>({
|
||||||
window.localStorage.setItem(
|
window.localStorage.setItem(
|
||||||
"mx_local_settings",
|
"mx_local_settings",
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
// Retain any other settings which may have already been set
|
||||||
...JSON.parse(window.localStorage.getItem("mx_local_settings") || "{}"),
|
...JSON.parse(window.localStorage.getItem("mx_local_settings") || "{}"),
|
||||||
// Ensure the language is set to a consistent value
|
// Ensure the language is set to a consistent value
|
||||||
language: "en",
|
language: "en",
|
||||||
|
|
Loading…
Reference in New Issue