Skip to content

The open alternative to Salesforce, designed for AI.

1.6 KB
Raw Blame
import { MOCKED_DATE } from '~/testing/constants/MockedDate';
import { type DraftPageLayout } from '@/page-layout/types/DraftPageLayout';
import { type PageLayoutTab } from '@/page-layout/types/PageLayoutTab';
import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';
import {
  PageLayoutTabLayoutMode,
  PageLayoutType,
  WidgetType,
} from '~/generated-metadata/graphql';

export const makeWidget = (
  id: string,
  index: number,
  tabId = 'tab-1',
): PageLayoutWidget =>
  ({
    id,
    pageLayoutTabId: tabId,
    title: id,
    isActive: true,
    type: WidgetType.FIELDS,
    configuration: { __typename: 'FieldsConfiguration' as const },
    position: {
      __typename: 'PageLayoutWidgetVerticalListPosition' as const,
      layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,
      index,
    },
    createdAt: MOCKED_DATE,
    updatedAt: MOCKED_DATE,
    deletedAt: null,
  }) as unknown as PageLayoutWidget;

export const makeTab = (
  id: string,
  widgets: PageLayoutWidget[],
  position = 0,
  layoutMode: PageLayoutTabLayoutMode = PageLayoutTabLayoutMode.VERTICAL_LIST,
  overrides?: Partial<PageLayoutTab>,
) => ({
  id,
  applicationId: '',
  universalIdentifier: id,
  isSystemSideEffect: false,
  title: id,
  isActive: true,
  position,
  layoutMode,
  pageLayoutId: '',
  widgets,
  createdAt: MOCKED_DATE,
  updatedAt: MOCKED_DATE,
  deletedAt: null,
  ...overrides,
});

export const makeDraft = (
  tabs: ReturnType<typeof makeTab>[],
): DraftPageLayout => ({
  id: 'test-layout',
  name: 'Test Layout',
  type: PageLayoutType.RECORD_PAGE,
  objectMetadataId: null,
  isFirstTabPinned: true,
  tabs,
});