import type { Room } from '@ably/chat'; import { RoomLifecycle } from '@ably/chat'; import { beforeEach, describe, expect, it } from 'vitest'; import { newChatClient } from '../helper/chat'; import { getRandomRoom } from '../helper/room'; import { PublicChatClient } from '../unified-clients/RpcChat'; interface TestContext { chat: PublicChatClient; room: Room; } describe('Room', () => { beforeEach((context) => { context.chat = newChatClient(); context.room = getRandomRoom(context.chat); }); // test not supported in UTS yet it.skip('should be attachable', async ({ room }) => { await room.attach(); // We should be attached expect(room.status.current).toEqual(RoomLifecycle.Attached); // If we check the underlying channels, they should be attached too const messagesChannel = await room.messages.channel; expect(messagesChannel.state).toEqual('attached'); const reactionsChannel = await room.reactions.channel; expect(reactionsChannel.state).toEqual('attached'); const typingChannel = await room.typing.channel; expect(typingChannel.state).toEqual('attached'); const presenceChannel = await room.presence.channel; expect(presenceChannel.state).toEqual('attached'); const occupancyChannel = await room.occupancy.channel; expect(occupancyChannel.state).toEqual('attached'); }); // test not supported in UTS yet it.skip('should be detachable', async ({ room }) => { await room.attach(); await room.detach(); // We should be detached expect(room.status.current).toEqual(RoomLifecycle.Detached); // If we check the underlying channels, they should be detached too const messagesChannel = await room.messages.channel; expect(messagesChannel.state).toEqual('detached'); const reactionsChannel = await room.reactions.channel; expect(reactionsChannel.state).toEqual('detached'); const typingChannel = await room.typing.channel; expect(typingChannel.state).toEqual('detached'); const presenceChannel = await room.presence.channel; expect(presenceChannel.state).toEqual('detached'); const occupancyChannel = await room.occupancy.channel; expect(occupancyChannel.state).toEqual('detached'); }); // TODO: resolve using private API: DefaultRoom export and its .release() method // it('should be releasable', async ({ room }) => { // await room.attach(); // // We should be attached // expect(room.status.current).toEqual(RoomLifecycle.Attached); // // Release the room // await (room as DefaultRoom).release(); // // We should be released // expect(room.status.current).toEqual(RoomLifecycle.Released); // }); // TODO: resolve using private API: DefaultRoom export and its .release() method // it('releasing a room multiple times is idempotent', async ({ room }) => { // await room.attach(); // // We should be attached // expect(room.status.current).toEqual(RoomLifecycle.Attached); // // Release the room multiple times // await (room as DefaultRoom).release(); // await (room as DefaultRoom).release(); // await (room as DefaultRoom).release(); // // We should be released // expect(room.status.current).toEqual(RoomLifecycle.Released); // }); });