pre-rep-review-fixture.test.ts1.5 KBView on GitHub /**
* Guards the authored Pre rep-review doc and the `conversationLink` table
* column it relies on: the doc's dashboard fence must be a valid spec, and a
* table column of type `conversationLink` must pass schema validation.
*/
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { parseDashboardSpec } from '@/modules/dashboards/types/dashboard';
const DOC_PATH = join(__dirname, '../../../docs/pre-rep-review.md');
const FENCE_RE = /```dashboard\s*\n([\s\S]*?)\n```/g;
function extractFences(md: string): string[] {
const fences: string[] = [];
let match: RegExpExecArray | null;
while ((match = FENCE_RE.exec(md)) !== null) fences.push(match[1]);
return fences;
}
describe('pre-rep-review.md', () => {
it('has one valid dashboard fence', () => {
const fences = extractFences(readFileSync(DOC_PATH, 'utf8'));
expect(fences.length).toBe(1);
expect(parseDashboardSpec(JSON.parse(fences[0]))).not.toBeNull();
});
});
describe('conversationLink table column', () => {
it('validates as a table column type', () => {
const spec = {
spec_version: '2.0',
id: 'cl',
dataSources: { d: { mock: [{ name: 'Acme', cid: 'abc-123' }] } },
layout: {
type: 'table',
source: 'd',
columns: [
{ key=[redacted], label: 'Deal', weight: 2 },
{ key: 'cid', label: 'Open', type: 'conversationLink', linkLabel: 'Open →' },
],
},
};
expect(parseDashboardSpec(spec)).not.toBeNull();
});
});