File size: 1,483 Bytes
19c41e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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);
});