Skip to content

Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬

1.3 KB
Raw Blame
import { Page } from '@playwright/test';

export class AddAgentModal {
  private page: Page;

  constructor(page: Page) {
    this.page = page;
  }

  getModalTitle() {
    return this.page.locator('[data-test-id="modal-header-title"]');
  }

  getAgentNameInput() {
    return this.page.getByRole('textbox', { name: 'Agent Name' });
  }

  getEmailInput() {
    return this.page.getByRole('textbox', { name: 'Email Address' });
  }

  getRoleCombobox() {
    return this.page.getByRole('combobox', { name: 'Role' });
  }

  getSubmitButton() {
    return this.page.locator('form').getByRole('button', { name: 'Add Agent' });
  }

  getCancelButton() {
    return this.page.getByRole('button', { name: 'Cancel' });
  }

  getSuccessMessage() {
    return this.page.getByText('Agent added successfully');
  }

  async fillAgentName(name: string) {
    await this.getAgentNameInput().fill(name);
    await this.page.waitForTimeout(1000);
  }

  async fillEmail(email: string) {
    await this.getEmailInput().fill(email);
    await this.page.waitForTimeout(1000);
  }

  async submitForm() {
    await this.getSubmitButton().click();
  }

  async cancelForm() {
    await this.getCancelButton().click();
  }

  async createAgent(name: string, email: string) {
    await this.fillAgentName(name);
    await this.fillEmail(email);
    await this.submitForm();
  }
}