Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

2.3 KB
Raw Blame
import type { Locator, Page } from '@playwright/test';

export class OrderPage {
  constructor(private readonly page: Page) {}

  async goto(eventId: number): Promise<void> {
    await this.page.goto(`/manage/event/${eventId}/orders`);
    await this.page.waitForLoadState('networkidle');
  }

  rowByEmail(email: string): Locator {
    return this.page.getByRole('row').filter({ hasText: email });
  }

  async chooseRowAction(email: string, action: string): Promise<void> {
    const row = this.rowByEmail(email);
    await row.getByTestId('order-actions-trigger').click();
    await this.page.getByRole('menuitem', { name: action }).click();
  }

  detailsDrawer(): Locator {
    return this.page.getByRole('dialog');
  }

  async chooseDrawerAction(action: string): Promise<void> {
    const drawer = this.detailsDrawer();
    const button = drawer.getByRole('button', { name: action, exact: true });
    if (await button.isVisible()) {
      await button.click();
      return;
    }
    await drawer.getByRole('button', { name: 'More actions' }).click();
    await this.page.getByRole('menuitem', { name: action }).click();
  }

  async sendMessageToBuyer(subject: string, body: string): Promise<void> {
    await this.page.getByRole('heading', { name: 'Send a message' }).waitFor();
    await this.page.getByLabel(/^Subject/).fill(subject);

    const editor = this.page.locator('.ProseMirror').first();
    await editor.click();
    await editor.fill(body);

    await this.page.getByRole('checkbox', { name: /I confirm this is a transactional message/ }).check();
    await this.page.getByTestId('message-send-button').click();
  }

  async confirmCancelOrder(): Promise<void> {
    await this.page.getByRole('heading', { name: /^Cancel Order/ }).waitFor();
    await this.page.getByRole('button', { name: 'Cancel Order' }).click();
  }

  async filterByProduct(productTitle: string): Promise<void> {
    await this.page.getByRole('button', { name: /Filters/ }).click();
    const dialog = this.page.getByRole('dialog');
    await dialog.getByRole('combobox', { name: 'Product' }).click();
    await this.page.getByRole('option', { name: productTitle }).click();
    await dialog.getByRole('button', { name: 'Apply' }).click();
    await dialog.waitFor({ state: 'hidden' });
  }

  exportButton(): Locator {
    return this.page.getByRole('button', { name: 'Export' });
  }
}