Skip to content

The open alternative to Salesforce, designed for AI.

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

export class DataModelSection {
  private readonly searchObjectInput: Locator;
  private readonly addObjectButton: Locator;
  private readonly objectSingularNameInput: Locator;
  private readonly objectPluralNameInput: Locator;
  private readonly objectDescription: Locator;
  private readonly synchronizeLabelApiToggle: Locator;
  private readonly objectApiSingularNameInput: Locator;
  private readonly objectApiPluralNameInput: Locator;
  private readonly objectMoreOptionsButton: Locator;
  private readonly editObjectButton: Locator;
  private readonly deleteObjectButton: Locator;
  private readonly activeSection: Locator;
  private readonly inactiveSection: Locator;
  private readonly searchFieldInput: Locator;
  private readonly addFieldButton: Locator;
  private readonly viewFieldDetailsMoreOptionsButton: Locator;
  private readonly nameFieldInput: Locator;
  private readonly descriptionFieldInput: Locator;
  private readonly deactivateMoreOptionsButton: Locator;
  private readonly activateMoreOptionsButton: Locator;
  private readonly deactivateButton: Locator; // TODO: add attribute to make it one button
  private readonly activateButton: Locator;
  private readonly cancelButton: Locator;
  private readonly saveButton: Locator;

  constructor(public readonly page: Page) {
    this.searchObjectInput = page.getByPlaceholder('Search an object...');
    this.addObjectButton = page.getByRole('button', { name: 'Add object' });
    this.objectSingularNameInput = page.getByPlaceholder('Listing', {
      exact: true,
    });
    this.objectPluralNameInput = page.getByPlaceholder('Listings', {
      exact: true,
    });
    this.objectDescription = page.getByPlaceholder('Write a description');
    this.synchronizeLabelApiToggle = page.getByRole('checkbox').nth(1);
    this.objectApiSingularNameInput = page.getByPlaceholder('listing', {
      exact: true,
    });
    this.objectApiPluralNameInput = page.getByPlaceholder('listings', {
      exact: true,
    });
    this.objectMoreOptionsButton = page.getByLabel('Object Options');
    this.editObjectButton = page.getByText('Edit', { exact: true });
    this.deactivateMoreOptionsButton = page.getByText('Deactivate', {
      exact: true,
    });
    this.activateMoreOptionsButton = page.getByText('Activate', {
      exact: true,
    });
    this.deleteObjectButton = page.getByText('Delete', { exact: true });
    this.activeSection = page.getByText('Active', { exact: true });
    this.inactiveSection = page.getByText('Inactive');
    this.searchFieldInput = page.getByPlaceholder('Search a field...');
    this.addFieldButton = page.getByRole('button', { name: 'Add field' });
    this.viewFieldDetailsMoreOptionsButton = page.getByText('View', {
      exact: true,
    });
    this.nameFieldInput = page.getByPlaceholder('Employees');
    this.descriptionFieldInput = page.getByPlaceholder('Write a description');
    this.deactivateButton = page.getByRole('button', { name: 'Deactivate' });
    this.activateButton = page.getByRole('button', { name: 'Activate' });
    this.cancelButton = page.getByRole('button', { name: 'Cancel' });
    this.saveButton = page.getByRole('button', { name: 'Save' });
  }

  async searchObject(name: string) {
    await this.searchObjectInput.fill(name);
  }

  async clickAddObjectButton() {
    await this.addObjectButton.click();
  }

  async typeObjectSingularName(name: string) {
    await this.objectSingularNameInput.fill(name);
  }

  async typeObjectPluralName(name: string) {
    await this.objectPluralNameInput.fill(name);
  }

  async typeObjectDescription(name: string) {
    await this.objectDescription.fill(name);
  }

  async toggleSynchronizeLabelApi() {
    await this.synchronizeLabelApiToggle.click();
  }

  async typeObjectSingularApiName(name: string) {
    await this.objectApiSingularNameInput.fill(name);
  }

  async typeObjectPluralApiName(name: string) {
    await this.objectApiPluralNameInput.fill(name);
  }

  async checkObjectDetails(name: string) {
    await this.page.getByRole('link').filter({ hasText: name }).click();
  }

  async activateInactiveObject(name: string) {
    await this.page
      .locator(`//div[@title="${name}"]/../../div[last()]`)
      .click();
    await this.activateButton.click();
  }

  // object can be deleted only if is custom and inactive
  async deleteInactiveObject(name: string) {
    await this.page
      .locator(`//div[@title="${name}"]/../../div[last()]`)
      .click();
    await this.deleteObjectButton.click();
  }

  async editObjectDetails() {
    await this.objectMoreOptionsButton.click();
    await this.editObjectButton.click();
  }

  async deactivateObjectWithMoreOptions() {
    await this.objectMoreOptionsButton.click();
    await this.deactivateButton.click();
  }

  async searchField(name: string) {
    await this.searchFieldInput.fill(name);
  }

  async checkFieldDetails(name: string) {
    await this.page.locator(`//div[@title="${name}"]`).click();
  }

  async checkFieldDetailsWithButton(name: string) {
    await this.page
      .locator(`//div[@title="${name}"]/../../div[last()]`)
      .click();
    await this.viewFieldDetailsMoreOptionsButton.click();
  }

  async deactivateFieldWithButton(name: string) {
    await this.page
      .locator(`//div[@title="${name}"]/../../div[last()]`)
      .click();
    await this.deactivateMoreOptionsButton.click();
  }

  async activateFieldWithButton(name: string) {
    await this.page
      .locator(`//div[@title="${name}"]/../../div[last()]`)
      .click();
    await this.activateMoreOptionsButton.click();
  }

  async clickAddFieldButton() {
    await this.addFieldButton.click();
  }

  async typeFieldName(name: string) {
    await this.nameFieldInput.clear();
    await this.nameFieldInput.fill(name);
  }

  async typeFieldDescription(description: string) {
    await this.descriptionFieldInput.clear();
    await this.descriptionFieldInput.fill(description);
  }

  async clickInactiveSection() {
    await this.inactiveSection.click();
  }

  async clickActiveSection() {
    await this.activeSection.click();
  }

  async clickCancelButton() {
    await this.cancelButton.click();
  }

  async clickSaveButton() {
    await this.saveButton.click();
  }
}