spymaster-dev-b / browser /tests /handler.internal.test.ts
Danisz's picture
feat(browser): refactor handler API, add internal tests, update docs and types
19c41e0
Raw History Blame Contribute Delete
1.48 kB
import { CodenamesGameHandler } from '../handler';
import { Selectors } from '../selectors';
// Internal/implementation tests for Playwright selectors and UI logic
// Not part of the public API contract
describe('Codenames Handler Internals: Room Join and Leave Flow', () => {
let handler: CodenamesGameHandler;
afterEach(async () => {
if (handler) {
await handler._cleanupResources();
handler = undefined as any;
}
});
it('joins the room and leaves the room, verifying both states', async () => {
handler = await CodenamesGameHandler.create();
await handler.joinRoom();
await handler["page"].screenshot({ path: 'screenshots/after-join-room.png' });
// Assert user is in the room (URL contains room code)
const url = await handler["page"].url();
expect(url).toContain(process.env.CODENAMES_TEST_ROOM_CODE);
// Assert board is visible
const isBoardVisible = await handler["page"].locator(Selectors.teamBoardBlue).isVisible();
expect(isBoardVisible).toBe(true);
await handler["page"].screenshot({ path: 'screenshots/after-board-visible.png' });
// Leave the room using the handler
await handler.leaveRoom();
// Assert user is out of the room (URL does not contain room code)
const leftUrl = await handler["page"].url();
expect(leftUrl).not.toContain(process.env.CODENAMES_TEST_ROOM_CODE);
await handler["page"].screenshot({ path: 'screenshots/after-leave-room.png' });
}, 30000);
});