// Book Comparison wired to the prop card (display-only). Source-assertion style, // matching vyndrCoreScreens.test.js. const fs = require('fs'); const path = require('path'); const read = (p) => fs.readFileSync(path.join(__dirname, '../../web/src', p), 'utf8'); describe('BookComparison — honest states', () => { const src = read('components/BookComparison.tsx'); it('renders EACH book’s own line (books frequently differ in line)', () => { // per-row line, not one shared header line. expect(src).toMatch(/sideChar\}\$\{b\.line\}/); expect(src).toMatch(/gridTemplateColumns: '1fr auto auto auto'/); // book · line · price · best }); it('single-book renders an intentional state, never a fake second row', () => { expect(src).toMatch(/const single = books\.length === 1/); expect(src).toContain('One book posting this prop.'); }); it('crown/BEST only shows on isBest (gated off → never shows)', () => { expect(src).toContain('b.isBest ?'); // savings copy is guarded behind savings > 0 (0 when crown off) expect(src).toMatch(/savings != null && savings > 0/); }); it('empty book list → renders nothing (honest-absent)', () => { expect(src).toMatch(/if \(!books \|\| books\.length === 0\) return null/); }); }); describe('BookComparisonPanel — the wire to /api/books', () => { const src = read('components/vyndr/BookComparisonPanel.tsx'); it('fetches the live /api/books per-prop endpoint', () => { expect(src).toMatch(/\/api\/books\/\$\{encodeURIComponent\(sport\)\}/); expect(src).toContain('BookComparison'); }); it('honest-absent: renders NULL until real book rows exist', () => { expect(src).toMatch(/data\.books\.length === 0\) return null/); }); it('does not enable the crown or pass a fabricated best', () => { expect(src).not.toMatch(/isBest:\s*true/); expect(src).not.toContain('BOOK_CROWN_ENABLED'); }); }); describe('GradeResultCard — wired + existing elements survive', () => { const src = read('components/vyndr/GradeResultCard.tsx'); it('renders the live BookComparisonPanel (BookComparison is no longer dead)', () => { expect(src).toContain('import BookComparisonPanel'); expect(src).toContain(''); }); it('the existing grade / projection / line / price elements are untouched', () => { expect(src).toContain('PriceTriplet'); // the price layer expect(src).toMatch(/PROJECTION|d\.projection/); // projection row expect(src).toContain('GradeBadge'); // the grade expect(src).toContain("l: 'LINE'"); // the PropLine line cell }); });