Files
vyndr/tests/unit/edgeBoard.test.js
T
builtbykev d755b43f05 P1-7: flat edge board — guard the broken edge placeholder (absent > fabricated)
Phone audit called the board 'mostly-empty'. Two causes, both now addressed:
1. Dead images (P0-2, already fixed) → the matchup/team chips render logos now.
2. Degraded edge data. Live snapshot edge_pct is on a broken scale (distinct
   values 20/60/100/140 — not a market %), with projection=0 and confidence
   35-55%. A real prop-market edge is single-digit, never past ~40%. Leading
   the board with '+140%' fabricates a signal (Data Semantics Rule).

Fix: an edge whose |value| > 40 is treated as ABSENT at BOTH layers — the
data layer (flattenToEdgeBoard nulls it, so it can't RANK a fake +140% above a
real +8.4%) and the display (EdgeCell shows '—'). Board falls through to the
grade-rank tiebreak when edges are unreliable. Real edges (≤40) are untouched.

The root cause — edge_pct/projection/confidence degradation — is a BACKEND
grading issue (same family as the P2-9 '45% B' flag), reported separately; this
is the honest frontend guard, not a fix for the data.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-17 01:34:01 -04:00

90 lines
4.3 KiB
JavaScript

'use strict';
// Rev 3 — flat EDGE BOARD (mobile screen 01). Design's mobile board is a flat,
// edge-ranked list across every game, not game-grouped cards. The flatten is a
// pure transform of the assembled GameCardData[]; lock its ranking + honesty.
const { flattenToEdgeBoard, edgeBoardBreadth, edgeGradeRank } = require('../../web/src/lib/slateAdapter');
const card = (over) => ({
sport: 'nba', live: false,
away: { abbr: 'DEN', name: 'Denver' }, home: { abbr: 'MIN', name: 'Minnesota' },
playerStrips: [], ...over,
});
const strip = (player, props, extra = {}) => ({ player, team: extra.team || '', props });
describe('flattenToEdgeBoard', () => {
const cards = [
card({ playerStrips: [
strip('Jokic', [{ stat: 'PTS', line: 27.5, side: 'O', grade: 'A+', edge: 8.4 }]),
strip('Gordon', [{ stat: 'REB', line: 7.5, side: 'O', grade: 'B', edge: 3.4 }]),
] }),
card({ live: true, away: { abbr: 'CHI', name: 'Chi' }, home: { abbr: 'MIL', name: 'Mil' }, playerStrips: [
strip('Edwards', [{ stat: 'AST', line: 5.5, side: 'O', grade: 'A', edge: 5.2 }]),
strip('LaVine', [{ stat: 'PTS', line: 22.5, side: 'O', grade: 'D', edge: -1.2 }]),
] }),
];
test('flattens every graded prop across games into ranked rows, edge desc', () => {
const rows = flattenToEdgeBoard(cards);
expect(rows.map((r) => r.player)).toEqual(['Jokic', 'Edwards', 'Gordon', 'LaVine']); // 8.4, 5.2, 3.4, -1.2
expect(rows[0].rank).toBe(1);
expect(rows[3].rank).toBe(4);
expect(rows[1].live).toBe(true); // Edwards' game is live → row carries it
expect(rows[0].away).toBe('DEN'); expect(rows[0].home).toBe('MIN');
});
test('a null edge sorts LAST, never 0-coerced to the top', () => {
const rows = flattenToEdgeBoard([card({ playerStrips: [
strip('NoEdge', [{ stat: 'PTS', line: 20, side: 'O', grade: 'A', edge: null }]),
strip('HasEdge', [{ stat: 'PTS', line: 20, side: 'O', grade: 'C', edge: 2.0 }]),
] })]);
expect(rows[0].player).toBe('HasEdge'); // +2.0 beats a null (not 0)
expect(rows[1].player).toBe('NoEdge');
});
test('awaiting / dead / ungraded rows are excluded from the board', () => {
const rows = flattenToEdgeBoard([card({ playerStrips: [
strip('Graded', [{ stat: 'PTS', line: 20, side: 'O', grade: 'A', edge: 5 }]),
strip('Awaiting', [{ stat: 'PTS', line: 20, side: 'O', grade: null, awaiting: true }]),
strip('Dead', [{ stat: 'PTS', line: 20, side: 'O', grade: 'B', edge: 4, dead: true }]),
] })]);
expect(rows.map((r) => r.player)).toEqual(['Graded']);
});
test('breadth counts A/B edges + games, never fabricates CLV', () => {
const rows = flattenToEdgeBoard(cards);
const b = edgeBoardBreadth(rows, cards);
expect(b.edges).toBe(3); // A+, B, A (not the D)
expect(b.games).toBe(2);
expect(b).not.toHaveProperty('clv'); // CLV comes from /api/accuracy, never invented here
});
test('edgeGradeRank orders tiers for the tiebreak', () => {
expect(edgeGradeRank('A+')).toBeLessThan(edgeGradeRank('A'));
expect(edgeGradeRank('A')).toBeLessThan(edgeGradeRank('B'));
expect(edgeGradeRank('F')).toBeLessThan(edgeGradeRank('ZZZ')); // unknown → last
});
test('empty / malformed input → empty board, no throw', () => {
expect(flattenToEdgeBoard(null)).toEqual([]);
expect(flattenToEdgeBoard([{}])).toEqual([]);
});
// P1-7 — an impossible edge (the pipeline's 60/100/140 placeholder) is not a
// market signal. It must be treated as absent so the board neither DISPLAYS
// nor RANKS on it — a fake +140% must never outrank a real +8.4%.
test('insane edge (>40%) is nulled so it neither displays nor ranks', () => {
const rows = flattenToEdgeBoard([card({ playerStrips: [
strip('RealEdge', [{ stat: 'PTS', line: 20, side: 'O', grade: 'B', edge: 8.4 }]),
strip('BrokenEdge', [{ stat: 'PTS', line: 20, side: 'O', grade: 'A', edge: 140 }]),
] })]);
const broken = rows.find((r) => r.player === 'BrokenEdge');
const real = rows.find((r) => r.player === 'RealEdge');
expect(broken.edge).toBeNull(); // not displayed as a fake %
expect(real.edge).toBe(8.4); // real edge preserved
// real edge outranks the nulled placeholder despite the placeholder's higher grade
expect(rows[0].player).toBe('RealEdge');
});
});