strategic-overview-layout.test.ts2.7 KBView on GitHub
/**
 * The Overview top row's shared layout rules. The AOP config editor and the
 * conversation Overview tab both read this module; when they each carried their
 * own copy, the editor labelled a cell "Next step quality" that the deal view
 * rendered as "Stage".
 */

import {
  CEDAR_CELL_LABELS,
  DEFAULT_TOP_ROW,
  TOP_ROW_SLOTS,
  normalizeLegacyLayout,
} from '@/modules/crm/utils/strategic-overview-layout';
import type { StrategicOverviewConfig } from '@/modules/crm/types';

function layout(topRow: StrategicOverviewConfig['topRow']): StrategicOverviewConfig {
  return { topRow, sections: [] };
}

describe('normalizeLegacyLayout', () => {
  it('renders the legacy next_step_quality cell as the native Stage cell', () => {
    const { topRow } = normalizeLegacyLayout(
      layout([
        { fieldId: 'nextStepDate', kind: 'cedar' },
        { fieldId: 'next_step_quality', kind: 'custom' },
      ]),
    );
    expect(topRow).toEqual([
      { fieldId: 'nextStepDate', kind: 'cedar' },
      { fieldId: 'status', kind: 'cedar' },
    ]);
    expect(CEDAR_CELL_LABELS.status).toBe('Stage');
  });

  it('drops the legacy cell rather than showing Stage twice', () => {
    const { topRow } = normalizeLegacyLayout(
      layout([
        { fieldId: 'status', kind: 'cedar' },
        { fieldId: 'next_step_quality', kind: 'custom' },
      ]),
    );
    expect(topRow).toEqual([{ fieldId: 'status', kind: 'cedar' }]);
  });

  it('removes the legacy field from sections', () => {
    const { sections } = normalizeLegacyLayout({
      topRow: [],
      sections: [{ id: 's', title: 'S', fieldIds: ['next_step_quality', 'risks'] }],
    });
    expect(sections[0].fieldIds).toEqual(['risks']);
  });

  it('re-tags a native field stored as custom, so it renders its native control', () => {
    const { topRow } = normalizeLegacyLayout(layout([{ fieldId: 'status', kind: 'custom' }]));
    expect(topRow).toEqual([{ fieldId: 'status', kind: 'cedar' }]);
  });

  it('caps the row at five cells', () => {
    const { topRow } = normalizeLegacyLayout(
      layout([
        { fieldId: 'nextStepDate', kind: 'cedar' },
        { fieldId: 'on_track', kind: 'custom' },
        { fieldId: 'status', kind: 'cedar' },
        { fieldId: 'risk', kind: 'cedar' },
        { fieldId: 'forecast', kind: 'custom' },
        { fieldId: 'dealValue', kind: 'cedar' },
      ]),
    );
    expect(topRow).toHaveLength(TOP_ROW_SLOTS);
  });

  it('leaves the default row untouched', () => {
    expect(normalizeLegacyLayout(layout([...DEFAULT_TOP_ROW])).topRow).toEqual(DEFAULT_TOP_ROW);
    expect(DEFAULT_TOP_ROW.map((c) => c.fieldId)).toEqual([
      'status',
      'nextStepDate',
      'lastContactedAt',
      'forecast',
      'dealValue',
    ]);
  });
});