feat: close 3 more competitive gaps — recommendations engine, multi-madhab Faraid, draft will PDF
Closes 3 of the remaining 4 gaps from the competitive benchmark: - Coverage Dashboard now has a rule-based recommendations engine (recommendations.js) surfacing plain-language next steps from data already in the app — exposed assets, missing Wassiyah, unverified assets, unlinked liabilities, missing insurance/Zakat setup, insufficient attestors, no agent assigned, no Waqf configured. - Faraid Calculator gains a madhab selector (Shafi'i/Hanafi/Maliki/ Hanbali) encoding the one well-documented divergence this engine's existing rules touch: whether radd extends to a sole-heir spouse (Hanafi: yes; Shafi'i/Maliki/Hanbali: no, residue unallocated). Ja'fari (Shia) is honestly gated as unsupported rather than silently computed with Sunni rules, since it's a structurally different classification system, not a parameter tweak. faraid.test.js grows from 14 to 17 cases covering the divergence and the gating. - Wassiyah tab gains a 'Generate draft will document' button producing a formatted, statutory-style DRAFT will (declaration/revocation, executor appointment, bequest schedule, witness attestation blocks) via browser print-to-PDF — no new PDF dependency. Clearly watermarked 'DRAFT — NOT EXECUTED, requires physical signing and witnessing.' Not a claim of legal validity, a lawyer-reviewable starting point. The 4th gap (human-in-the-loop professional tier) remains open — out of scope for a self-serve prevention tool. COMPETITIVE_BENCHMARK.md updated to reflect closed/partially-closed status on each item. Covered by e2e-gaps-round2.cjs (14/14) plus 3 new faraid.test.js cases. Full regression: 226/226 across all suites.
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
// Verifies the second round of competitive-gap closures: the Coverage
|
||||
// Dashboard's rule-based recommendations engine, the Faraid Calculator's
|
||||
// madhab selector (including honest Ja'fari gating), and the Wassiyah tab's
|
||||
// draft will document generator.
|
||||
const { chromium } = require('playwright');
|
||||
const { signInFreshFamily } = require('./e2e-auth-helper.cjs');
|
||||
const BASE = 'https://moslem04.falahos.my/';
|
||||
const results = [];
|
||||
const consoleErrors = [];
|
||||
function record(name, pass, detail = '') { results.push({ name, pass, detail }); console.log(`${pass ? 'PASS' : 'FAIL'} ${name}${detail ? ' — ' + detail : ''}`); }
|
||||
|
||||
async function main() {
|
||||
const browser = await chromium.launch();
|
||||
const page = await browser.newPage({ viewport: { width: 390, height: 844 } });
|
||||
page.on('console', m => { if (m.type() === 'error') consoleErrors.push(m.text()); });
|
||||
page.on('pageerror', e => consoleErrors.push(e.message));
|
||||
|
||||
await signInFreshFamily(page, BASE, 'e2e-gaps2');
|
||||
|
||||
// ── Recommendations engine on Coverage Dashboard ──
|
||||
// Fresh family, no assets yet: no exposed-asset recommendation, but the
|
||||
// "no agent assigned" and "no insurance" rules should still fire since
|
||||
// they don't depend on estateTotal > 0.
|
||||
await page.waitForTimeout(600);
|
||||
const recSectionVisible = await page.locator('.recommendations').isVisible().catch(() => false);
|
||||
record('Coverage: recommendations section renders for a fresh family', recSectionVisible);
|
||||
const noAgentRec = await page.locator('.rec-row', { hasText: 'No estate agent' }).isVisible().catch(() => false);
|
||||
record('Coverage: flags missing estate agent/mutawalli', noAgentRec);
|
||||
|
||||
// Add an asset to trigger the exposed-asset recommendation
|
||||
await page.locator('nav button[aria-label="Assets"]').click();
|
||||
await page.waitForTimeout(500);
|
||||
await page.locator('.form-card .field:has-text("Description") input').fill('Savings account');
|
||||
await page.locator('.form-card .field:has-text("Estimated value") input').fill('50000');
|
||||
await page.locator('.form-card button.btn-primary', { hasText: 'Add asset' }).click();
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
await page.locator('nav button[aria-label="Coverage"]').click();
|
||||
await page.waitForTimeout(800);
|
||||
const exposedRec = await page.locator('.rec-row', { hasText: 'exposed to the slow' }).isVisible().catch(() => false);
|
||||
record('Coverage: flags exposed asset once one is logged', exposedRec);
|
||||
const wassiyahRec = await page.locator('.rec-row', { hasText: 'No Wassiyah bequests' }).isVisible().catch(() => false);
|
||||
record('Coverage: flags missing Wassiyah once estate has value', wassiyahRec);
|
||||
|
||||
// ── Faraid Calculator: madhab selector ──
|
||||
await page.locator('nav button[aria-label="Faraid"]').click();
|
||||
await page.waitForTimeout(500);
|
||||
const madhabSelectVisible = await page.locator('.field:has-text("Madhab") select').isVisible().catch(() => false);
|
||||
record('Faraid: madhab selector is present', madhabSelectVisible);
|
||||
|
||||
// Set up: wife only, no other heirs -> sole-heir radd divergence case
|
||||
await page.locator('.field:has-text("Number of surviving wives") input').fill('1');
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
await page.locator('.field:has-text("Madhab") select').selectOption('shafii');
|
||||
await page.waitForTimeout(500);
|
||||
const shafiiShare = await page.locator('.share-row', { hasText: 'Wife' }).locator('.share-frac').textContent();
|
||||
record("Faraid: Shafi'i excludes spouse from radd (wife keeps 1/4)", shafiiShare.trim() === '1/4', shafiiShare);
|
||||
const unallocatedNoteVisible = await page.locator('.note-box', { hasText: 'unallocated' }).isVisible().catch(() => false);
|
||||
record("Faraid: Shafi'i shows unallocated-residue note for sole-heir spouse", unallocatedNoteVisible);
|
||||
|
||||
await page.locator('.field:has-text("Madhab") select').selectOption('hanafi');
|
||||
await page.waitForTimeout(500);
|
||||
const hanafiShare = await page.locator('.share-row', { hasText: 'Wife' }).locator('.share-frac').textContent();
|
||||
record('Faraid: Hanafi extends radd to sole-heir spouse (takes whole estate)', hanafiShare.trim() === '1', hanafiShare);
|
||||
|
||||
await page.locator('.field:has-text("Madhab") select').selectOption('jaafari');
|
||||
await page.waitForTimeout(500);
|
||||
const jaafariGateVisible = await page.locator('.reframe-note', { hasText: "Ja'fari" }).isVisible().catch(() => false);
|
||||
const sharesHiddenForJaafari = await page.locator('.results').isVisible().catch(() => false);
|
||||
record("Faraid: Ja'fari is honestly gated as unsupported, not silently computed", jaafariGateVisible && !sharesHiddenForJaafari);
|
||||
|
||||
// ── Wassiyah: draft will document generator ──
|
||||
await page.locator('.field:has-text("Madhab") select').selectOption('shafii'); // reset, avoid cross-test pollution
|
||||
await page.locator('nav button[aria-label="Wassiyah"]').click();
|
||||
await page.waitForTimeout(500);
|
||||
await page.locator('.field:has-text("Full legal name") input').fill('Ahmad bin Ismail');
|
||||
await page.locator('.field:has-text("Recipient name") input').fill('Nur Charity Foundation');
|
||||
await page.locator('.field:has-text("Relation to you") input').fill('charity');
|
||||
await page.locator('.field:has-text("Description") input').fill('Cash bequest');
|
||||
await page.locator('.field:has-text("Value") input').first().fill('5000');
|
||||
await page.locator('button.btn-primary', { hasText: 'Add bequest' }).click();
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
const [docPage] = await Promise.all([
|
||||
page.waitForEvent('popup'),
|
||||
page.locator('button.btn-secondary', { hasText: 'Generate draft will document' }).click()
|
||||
]);
|
||||
await docPage.waitForLoadState();
|
||||
const docText = await docPage.locator('body').innerText();
|
||||
record('Will document: opens a new tab with the testator name', docText.includes('Ahmad bin Ismail'), docText.slice(0, 100));
|
||||
record('Will document: watermarked DRAFT / not executed', /draft.*not executed/i.test(docText));
|
||||
record('Will document: includes the bequest recipient', docText.includes('Nur Charity Foundation'));
|
||||
record('Will document: includes witness attestation section', /Witness Attestation/i.test(docText));
|
||||
await docPage.close();
|
||||
|
||||
record('No uncaught JS console errors during full session', consoleErrors.length === 0, consoleErrors.join(' || '));
|
||||
|
||||
await browser.close();
|
||||
const passCount = results.filter(r => r.pass).length;
|
||||
const failCount = results.length - passCount;
|
||||
console.log(`\n${passCount} passed, ${failCount} failed, ${results.length} total`);
|
||||
if (failCount > 0) results.filter(r => !r.pass).forEach(r => console.log(` - ${r.name}: ${r.detail}`));
|
||||
process.exit(failCount > 0 ? 1 : 0);
|
||||
}
|
||||
main().catch(e => { console.error('SCRIPT ERROR:', e); process.exit(2); });
|
||||
Reference in New Issue
Block a user