fix: Chats doesn't sync for multi client users

This commit is contained in:
2026-06-11 00:04:49 +02:00
parent d0aff6319d
commit d174536272
16 changed files with 662 additions and 16 deletions

View File

@@ -114,10 +114,84 @@ export async function expectCrossDeviceMessage(
): Promise<void> {
await sender.sendMessage(message);
await expect.poll(async () => {
return await receiver.getMessageItemByText(message).isVisible()
.catch(() => false);
}, { timeout }).toBe(true);
await expectSyncedMessage(receiver, message, timeout);
}
/** Waits until a message sent elsewhere appears in the local chat history. */
export async function expectSyncedMessage(
receiver: ChatMessagesPage,
message: string,
timeout = 90_000
): Promise<void> {
await receiver.waitForReady();
await expect(receiver.getMessageItemByText(message)).toBeVisible({ timeout });
}
export async function expectSyncedMessageWithResync(
page: Page,
receiver: ChatMessagesPage,
message: string,
timeout = 60_000
): Promise<void> {
await receiver.waitForReady();
const alreadyVisible = await receiver.getMessageItemByText(message)
.isVisible()
.catch(() => false);
if (!alreadyVisible) {
await resyncChannelMessages(page);
}
await expect(receiver.getMessageItemByText(message)).toBeVisible({ timeout });
}
export async function resyncChannelMessages(page: Page, channelName = 'general'): Promise<void> {
const channel = page.locator(`button[data-channel-type="text"][data-channel-name="${channelName}"]`).first();
await expect(channel).toBeVisible({ timeout: 10_000 });
await channel.click({ button: 'right' });
await page.getByRole('button', { name: 'Resync Messages' }).click();
}
export async function closeClient(client: Client): Promise<void> {
await client.context.close();
}
export async function registerGuestAndJoinServer(
page: Page,
credentials: MultiDeviceCredentials,
serverName: string
): Promise<void> {
const registerPage = new RegisterPage(page);
await registerPage.goto();
await registerPage.register(credentials.username, credentials.displayName, credentials.password);
await expect(page).toHaveURL(/\/dashboard/, { timeout: 15_000 });
const search = new ServerSearchPage(page);
await search.joinServerFromSearch(serverName);
await expect(page).toHaveURL(/\/room\//, { timeout: 20_000 });
await expect(page.locator('app-rooms-side-panel').first()).toBeVisible({ timeout: 20_000 });
}
export async function reopenClientInServer(
createClient: () => Promise<Client>,
credentials: MultiDeviceCredentials,
serverName: string
): Promise<{ client: Client; messages: ChatMessagesPage }> {
const client = await createClient();
await warmClientPage(client.page);
await loginSecondDeviceIntoServer(client.page, credentials, serverName);
const messages = new ChatMessagesPage(client.page);
await messages.waitForReady();
return { client, messages };
}
async function warmClientPage(page: Page): Promise<void> {
@@ -181,6 +255,25 @@ export function membersSidePanel(page: Page) {
return page.locator('app-rooms-side-panel').last();
}
export function serverMemberRow(page: Page, displayName: string) {
return membersSidePanel(page)
.locator('[role="button"], button')
.filter({ has: page.getByText(displayName, { exact: true }) })
.first();
}
/**
* Gates cross-user assertions on real presence: the peer must show up in the
* members panel before chat delivery between the two users can be expected.
*/
export async function expectServerPeerVisible(
page: Page,
displayName: string,
timeout = 45_000
): Promise<void> {
await expect(serverMemberRow(page, displayName)).toBeVisible({ timeout });
}
export function passiveVoiceChannelJoinBadge(page: Page, channelName = MULTI_DEVICE_VOICE_CHANNEL) {
return page
.locator(`button[data-channel-type="voice"][data-channel-name="${channelName}"]`)