Skip to content

The open alternative to Salesforce, designed for AI.

1.8 KB
Raw Blame
import { expect, within } from 'storybook/test';

import { errorHandler } from '@/__stories__/shared/test-utils/createFrontComponentStoryMeta';
import { expectFrontComponentMounted } from '@/__stories__/shared/test-utils/matchers/expectFrontComponentMounted';
import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryPlayFunction';

export const phoneCountryPickerTriggerTest: TwentyUiGalleryPlayFunction =
  async ({ canvasElement }) => {
    const canvas = within(canvasElement);

    await expectFrontComponentMounted(canvas);

    const primary = canvas.getByRole('button', {
      name: 'Primary phone country',
    });
    const secondary = canvas.getByRole('button', {
      name: 'Secondary phone country',
    });
    const disabled = canvas.getByRole('button', {
      name: 'Disabled phone country',
    });

    expect(primary).toHaveAttribute('type', 'button');
    expect(primary).toHaveAttribute('data-phone-trigger', 'primary');
    expect(primary).toHaveTextContent('πŸ‡ΊπŸ‡Έ');
    expect(primary).toHaveAccessibleDescription('United States');
    expect(secondary).toHaveTextContent('πŸ‡«πŸ‡·');
    expect(secondary).toHaveAccessibleDescription('France');
    expect(disabled).toBeDisabled();
    expect(disabled).not.toHaveAccessibleDescription();
    expect(
      canvas.getByRole('status', { name: 'Primary phone country selection' }),
    ).toHaveTextContent('Country: US; Changes: 0; Event: none; Refs: unread');
    expect(
      canvas.getByRole('status', { name: 'Secondary phone country selection' }),
    ).toHaveTextContent('Country: FR; Changes: 0; Event: none');
    expect(
      canvas.getByRole('status', { name: 'Disabled phone country selection' }),
    ).toHaveTextContent('Country: none');
    expect(errorHandler).not.toHaveBeenCalled();
  };