all repos — caroster @ add-playwright

[Octree] Group carpool to your event https://caroster.io

frontend/tests/page-objects/event-page.ts (view raw)

 1import type {Page} from '@playwright/test';
 2
 3const API_URL = 'http://localhost:1337';
 4
 5export class EventPage {
 6  public uuid: string;
 7  public name: string;
 8
 9  constructor(public readonly page: Page) {}
10
11  async createEvent(name: string) {
12    const response = await fetch(`${API_URL}/api/events`, {
13      method: 'POST',
14      headers: {
15        'Content-Type': 'application/json',
16      },
17      body: JSON.stringify({
18        name,
19        email: 'test@example.org',
20        date: '2030-01-30',
21      }),
22    });
23    const payload = await response.json();
24    this.uuid = payload.uuid;
25    this.name = name;
26  }
27
28  async goto() {
29    await this.page.goto(`/e/${this.uuid}`);
30  }
31
32  async addTravel(carName = 'Test car') {
33    await this.page.getByLabel('add-car').click();
34    await this.page.getByLabel('Name of the car').click();
35    await this.page.getByLabel('Name of the car').fill(carName);
36    await this.page.getByLabel('Telephone number').click();
37    await this.page.getByLabel('Telephone number').fill('0044 444 44 44');
38    await this.page.getByLabel('Choose date').click();
39    await this.page.getByLabel('Next month').click();
40    await this.page.waitForTimeout(1000);
41    await this.page.getByRole('gridcell', {name: '28'}).click();
42    if (await this.page.getByRole('button', {name: 'OK'}).isVisible())
43      this.page.getByRole('button', {name: 'OK'}).click();
44    await this.page.getByLabel('Meeting place').click();
45    await this.page.getByLabel('Meeting place').fill('Au coin de la rue');
46    await this.page.getByLabel('Additional information').click();
47    await this.page
48      .getByLabel('Additional information')
49      .fill("J'aime le vent dans mes cheveux");
50    await this.page.getByRole('button', {name: 'Add'}).click();
51  }
52
53  async addPassenger(name: string) {
54    // Select first travel (fail if it does not exist)
55    await this.page
56      .getByRole('button', {name: 'Add to passenger'})
57      .first()
58      .click();
59    await this.page.getByPlaceholder('Name').click();
60    await this.page.getByPlaceholder('Name').fill(name);
61    await this.page.getByRole('button', {name: 'Add to car'}).click();
62  }
63}