Skip to content

Commit

Permalink
test room join and listen to event
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanak-michal committed Apr 12, 2024
1 parent 7b15153 commit 7a2ea9d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions e2e/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import EventType from "../src/EventType";

test('perform ThingsDB test', async ({ page }) => {
await page.goto('http://localhost:9000/');
Expand All @@ -17,4 +18,17 @@ test('perform ThingsDB test', async ({ page }) => {

const hello = await page.evaluate(() => window["thingsdb"].query('@thingsdb', '"Hello World!"'));
expect(hello).toBe('Hello World!');

const roomId = await page.evaluate(() => window["thingsdb"].query('@:stuff', `if (.has("test_room")) .del("test_room");
.test_room = room();
.test_room.id();`));
expect(roomId).toBeGreaterThan(0);

const watchDog = page.waitForFunction(() => window["joined"], null, {timeout: 5});
await page.evaluate((r) => {
window["joined"] = false;
window["thingsdb"].addEventListener((type: number, message: any): boolean => { window["joined"] = type === EventType.ON_JOIN; });
return window["thingsdb"].join('@:stuff', r);
}, roomId);
await watchDog;
});

0 comments on commit 7a2ea9d

Please sign in to comment.