diff --git a/e2e-other.cjs b/e2e-other.cjs new file mode 100644 index 0000000..b2de76d --- /dev/null +++ b/e2e-other.cjs @@ -0,0 +1,66 @@ +// Verifies "Other" asset type gets a sensible suggestion (Hibah) instead of the +// previous bug: a nonsensical "EPF / Takaful nomination" suggestion pointing at a +// channel value ('nomination') that didn't even exist in the Nomination Registry. +const { chromium } = require('playwright'); +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 page.goto(BASE, { waitUntil: 'networkidle' }); + const clickTab = async label => { await page.locator('nav button.tab', { hasText: label }).click(); await page.waitForTimeout(200); }; + const selectByText = async (locator, text) => { + const val = await locator.evaluate((el, t) => Array.from(el.options).find(o => o.textContent.includes(t))?.value, text); + await locator.selectOption(val); + }; + + await clickTab('Assets'); + await page.locator('.field:has-text("Description") input').fill('Rare stamp collection'); + await page.locator('.field:has-text("Estimated value") input').fill('20000'); + await page.locator('.form-card select').first().selectOption('Other'); + await page.locator('button.btn-primary', { hasText: 'Add asset' }).click(); + await page.waitForTimeout(200); + + await clickTab('Coverage'); + const rowBefore = await page.locator('.asset-row', { hasText: 'stamp collection' }).textContent(); + record('Coverage: "Other" asset suggests Hibah, not the old nonsense EPF/Takaful suggestion', rowBefore.includes('Hibah') && !rowBefore.includes('EPF'), rowBefore.trim().slice(0, 200)); + + await clickTab('Nominate'); + await selectByText(page.locator('select').first(), 'stamp collection'); + await page.waitForTimeout(200); + const suggestionText = await page.locator('.suggestion').textContent(); + record('Nomination: suggestion for "Other" points to Hibah with sensible reasoning', suggestionText.includes('Hibah') && suggestionText.includes('safest general'), suggestionText.trim().slice(0, 200)); + + // Cover it via Hibah (the suggested path) + await clickTab('Hibah'); + await page.locator('.field:has-text("Recipient") input').fill('My Daughter'); + await page.locator('.field:has-text("Relation to you") input').fill('daughter'); + await page.locator('.field:has-text("Asset / gift description") input').fill('Stamp collection gift'); + await selectByText(page.locator('select').first(), 'stamp collection'); + await page.locator('button.btn-primary', { hasText: 'Log this hibah' }).click(); + await page.waitForTimeout(200); + await page.locator('.guard-buttons button.btn-secondary', { hasText: 'No' }).click(); + await page.waitForTimeout(200); + await page.locator('button.btn-primary', { hasText: 'Confirm and save' }).click(); + await page.waitForTimeout(300); + + await clickTab('Coverage'); + const pct = await page.locator('.big-percent').textContent(); + record('Coverage: "Other" asset covered after following the Hibah suggestion', pct.trim() === '100%', pct); + + record('No uncaught JS console errors', 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); }); diff --git a/src/lib/nonprobate.js b/src/lib/nonprobate.js index 758124f..a49c09b 100644 --- a/src/lib/nonprobate.js +++ b/src/lib/nonprobate.js @@ -67,5 +67,13 @@ export function suggestedChannel(assetType) { if (t.includes('digital')) return { channel: 'digital-custody', label: 'Digital custody plan (multi-sig / exchange beneficiary / key escrow)', note: 'Custodial exchange accounts often have a built-in beneficiary/inheritance feature — use it directly. Self-custody wallets need a multi-sig setup or a key-escrow arrangement with your executor; a single seed phrase known only to you is not a fast path, it is a total-loss risk.' }; if (t.includes('vehicle') || t.includes('jewelry') || t.includes('valuables')) return { channel: 'hibah', label: 'Hibah — lifetime gift now', note: 'Movable property like this transfers cleanly by Hibah — offer, acceptance, and possession, done today. No trust or nomination structure is needed for something this easy to hand over while you\'re alive.' }; if (t.includes('property')) return { channel: 'trust', label: 'Pre-funded trust / nominee holding, or Hibah/Waqf now', note: 'Land has no nomination-based bypass in most jurisdictions. Either complete a Hibah/Waqf now (ownership transfers immediately), or set up a trust/nominee holding structure — both require real-world legal steps this app can prepare paperwork for but cannot execute alone.' }; - return { channel: 'nomination', label: 'EPF / Takaful nomination', note: 'For retirement funds and insurance/takaful, use the scheme\'s own nomination form — these pay the nominee directly by law, bypassing probate.' }; + // Catch-all for "Other" and anything that doesn't match a specific type above. + // Hibah is the safest general default — it works for almost anything you can + // specifically identify and hand over, and needs no institution or legal + // structure to set up. If it's high-value, illiquid, or an ongoing income + // stream (a domain portfolio, IP royalties, an unusual collectible), a trust + // may fit better — the app can't know that from the type alone, so it points + // the simplest, most broadly applicable option first rather than guessing a + // specific institutional channel that likely doesn't apply. + return { channel: 'hibah', label: 'Hibah — lifetime gift now', note: 'For an asset type this app doesn\'t have a specific rule for, Hibah is the safest general starting point — a direct gift, no institution or legal structure required. If it\'s high-value or income-generating (e.g. a business-like asset, IP royalties), consider a trust setup in the Nomination Registry instead.' }; }