Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

6.0 KB
Raw Blame
import { expect, test } from '@playwright/test';

test('creates a named company without inventing a domain', async ({
  page,
}, testInfo) => {
  await page.goto('/');
  await page.getByRole('button', { name: 'New company', exact: true }).click();
  await page
    .getByRole('textbox', { name: 'Company name' })
    .fill('Community group');
  await page.screenshot({ path: testInfo.outputPath('name-only-company.png') });
  await page.getByRole('button', { name: /^Create Company/ }).click();
  await expect(page.getByTestId('created')).toHaveText(
    '{"name":"Community group"}'
  );
});

for (const company of ['Acme', 'Community group']) {
  test(`creates a personal-email contact at ${company}`, async ({
    page,
  }, testInfo) => {
    await page.goto('/');
    await page
      .getByRole('button', { name: 'New contact', exact: true })
      .click();
    await page.getByRole('textbox', { name: 'Contact name' }).fill('Jane');
    await page
      .getByRole('textbox', { name: 'Email', exact: true })
      .fill('[email protected]');
    await page
      .getByRole('button', { name: 'Choose a company', exact: true })
      .click();
    await page.getByRole('option', { name: new RegExp(company) }).click();
    await page.screenshot({
      path: testInfo.outputPath('personal-email-contact.png'),
    });
    await page.getByRole('button', { name: /^Create Contact/ }).click();
    await expect(page.getByTestId('created')).toHaveText(
      JSON.stringify({
        companyId: company === 'Acme' ? 'acme' : 'name-only',
        name: 'Jane',
        email: '[email protected]',
      })
    );
  });
}

test('creates a contact by name alone, without a company or email', async ({
  page,
}, testInfo) => {
  await page.goto('/');
  await page.getByRole('button', { name: 'New contact', exact: true }).click();
  await page.getByRole('textbox', { name: 'Contact name' }).fill('Jane Doe');
  await page.screenshot({ path: testInfo.outputPath('name-only-contact.png') });
  await page.getByRole('button', { name: /^Create Contact/ }).click();
  await expect(page.getByTestId('created')).toHaveText('{"name":"Jane Doe"}');
});

test('uses the server character limit for Unicode contact names', async ({
  page,
}, testInfo) => {
  await page.goto('/');
  await page.getByRole('button', { name: 'New contact', exact: true }).click();
  const name = page.getByRole('textbox', { name: 'Contact name' });
  await name.fill('𐐀'.repeat(201));
  await page.getByRole('button', { name: /^Create Contact/ }).click();
  await expect(name).toHaveAttribute('aria-invalid', 'true');
  await expect(page.getByRole('alert')).toBeVisible();
  await expect(page.getByTestId('created')).toBeEmpty();
  await page.screenshot({
    path: testInfo.outputPath('unicode-name-limit.png'),
  });
  await name.fill('𐐀'.repeat(200));
  await page.getByRole('button', { name: /^Create Contact/ }).click();
  await expect(page.getByTestId('created')).toHaveText(
    JSON.stringify({ name: '𐐀'.repeat(200) })
  );
});

test('creates a name-only company while adding a deal', async ({ page }) => {
  await page.goto('/');
  await page.getByRole('button', { name: 'New deal', exact: true }).click();
  await page
    .getByRole('combobox', { name: 'Find or add a company' })
    .fill('New group');
  await page.getByRole('option', { name: 'Add company “New group”' }).click();
  await page.getByRole('button', { name: /^Add deal/ }).click();
  await expect(page.getByTestId('created')).toHaveText('{"name":"New group"}');
});

test('selects a different company for a pipeline contact', async ({ page }) => {
  await page.goto('/');
  await page
    .getByRole('button', { name: 'New pipeline contact', exact: true })
    .click();
  await page
    .getByRole('combobox', { name: 'Find or add a contact' })
    .fill('[email protected]');
  await page
    .getByRole('option', { name: 'Add contact “[email protected]”' })
    .click();
  await page.getByRole('textbox', { name: 'Contact name' }).fill('Jane');
  await page
    .getByRole('button', { name: 'Choose a company', exact: true })
    .click();
  await page.getByRole('option', { name: /Community group/ }).click();
  await page
    .getByRole('textbox', { name: 'Email', exact: true })
    .fill('[email protected]');
  await page.getByRole('button', { name: /^Add contact/ }).click();
  await expect(page.getByTestId('created')).toHaveText(
    '{"companyId":"name-only","name":"Jane","email":"[email protected]"}'
  );
});

test('requires accepting a suggested company before creating a pipeline contact', async ({
  page,
}, testInfo) => {
  const errors: string[] = [];
  page.on('pageerror', (error) => errors.push(error.message));
  await page.goto('/');
  await page
    .getByRole('button', { name: 'New pipeline contact', exact: true })
    .click();
  await page
    .getByRole('combobox', { name: 'Find or add a contact' })
    .fill('[email protected]');
  await page
    .getByRole('option', { name: 'Add contact “[email protected]”' })
    .click();
  await page.getByRole('textbox', { name: 'Contact name' }).fill('Jane');
  await page.getByRole('button', { name: /^Add contact/ }).click();
  await expect(page.getByRole('alert')).toHaveText(
    'Choose a company for this contact'
  );
  await expect(page.getByTestId('created')).toBeEmpty();
  const suggestion = page.getByRole('button', {
    name: 'Use suggested company: Acme',
    exact: true,
  });
  if (testInfo.project.name === 'desktop') {
    await suggestion.focus();
    await expect(page.locator('[role="tooltip"]')).toHaveText('Acme');
    await page.keyboard.press('Enter');
    await expect(page.locator('[role="tooltip"]')).toHaveCount(0);
    await expect(page.getByTestId('created')).toBeEmpty();
  } else {
    await suggestion.click();
  }
  await page
    .getByRole('textbox', { name: 'Email', exact: true })
    .fill('[email protected]');
  await page.getByRole('button', { name: /^Add contact/ }).click();
  await expect(page.getByTestId('created')).toHaveText(
    '{"companyId":"acme","name":"Jane","email":"[email protected]"}'
  );
  expect(errors).toEqual([]);
});