File size: 1,811 Bytes
2b86c60 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import type { Report } from '../src/analyze';
import { renderReport, renderUnsupported } from '../src/render';
const ATTACK = '<img src=x onerror="window.pwned=1">';
const report: Report = {
store: 'zepto',
findings: [{ rule: 'preselected_paid_addon', severity: 'warn', amountMinor: 9900, evidence: [ATTACK], message: '₹99.00 add-on was selected by default' }],
matches: [{ line: ATTACK, matches: [{ score: 0.7, confirmed: false, seen: { store: 'blinkit', name: ATTACK, brand: null, sizeValue: 1, sizeUnit: 'count',
priceMinor: 100, available: true, locationKey: 'a'.repeat(64), seenAt: '2026-10-23T09:00:00Z' } }] }],
split: { status: 'optimal', assignment: { 'line-0': 'blinkit' }, storeTotalsMinor: { blinkit: 28500 }, totalMinor: 28500,
bestSingleStore: { store: 'blinkit', totalMinor: 28500 }, savingsMinor: 0, unpurchasable: [] },
assumptions: ['Assumption text'],
};
it('renders page text as text, never as markup', () => {
const root = document.createElement('main');
renderReport(root, report);
expect(root.querySelector('img')).toBeNull();
expect(root.textContent).toContain(ATTACK);
expect((window as unknown as { pwned?: number }).pwned).toBeUndefined();
});
it('asks the user to confirm low-confidence matches', () => {
const root = document.createElement('main');
const confirmed: [number, string][] = [];
renderReport(root, report, (i, s) => confirmed.push([i, s]));
root.querySelector('button')!.click();
expect(confirmed).toEqual([[0, 'blinkit']]);
});
it('says when a page layout is unsupported instead of showing numbers', () => {
const root = document.createElement('main');
renderUnsupported(root, 'blinkit', 'cart container missing');
expect(root.textContent).toContain('not supported');
expect(root.textContent).not.toMatch(/₹/);
});
|