Files
wmj 33a821e61d refactor: restructure navigation into 5 grouped hubs, off the 22-item flat strip
Implements the researched IA fix: mobile nav UX consensus caps primary
destinations at 4-5 (uxpin.com, fintech/banking 2026 UX research), and
this app had grown to 22 tabs in one horizontally-scrolling row —
exactly the anti-pattern that research flags for choice paralysis and
slower task completion.

New structure — 5 bottom-nav hubs, grouped by what the user is actually
trying to do, not build order:
- Home: Coverage (unchanged, still the landing screen)
- Estate: Assets, Faraid, Insurance, Wassiyah, Hibah, Family Waqf,
  Nominate, Claims (H2)
- Giving: Zakat, Sadaqah, Khairat
- Family: Tree, Trigger, Mutawalli, Manage (was 'Family', renamed to
  avoid colliding with the hub's own label), Neighbourhood
- Daily: Prayer Times, Qibla, Quran, Locate

Each hub reveals its own sub-nav one tap in, instead of every tab
competing for space in a single row. Settings moved out of the tab
strip entirely into a header gear icon, matching the banking-app pattern
of keeping settings out of primary thumb-reach real estate. The bottom
nav is now fixed (thumb-zone), sub-nav keeps the old sticky-top position.

Cross-component navigation (nav.js requestedTab, used by the Family
Tree's 'give sadaqah in memory' link) now resolves a tab label to its
owning (hub, sub-tab) pair instead of a flat index — verified live.

This touches every E2E suite: a single click on a tab's old selector no
longer reaches it (hub, then sub-tab). Added a shared gotoTab(page, label)
helper to e2e-auth-helper.cjs encapsulating the two-step navigation, and
migrated all ~22 affected test files off direct nav-button selectors —
mechanical substitution followed by manual fixes for local clickTab
wrappers, template-literal selectors, and active-state assertions that
needed to target the new .hub-tab/.subnav structure specifically.

Full regression after migration: every suite passes (one isolated
Family Tree flake confirmed clean on rerun, unrelated to navigation).
2026-08-14 14:55:09 +08:00

107 lines
6.4 KiB
JavaScript

// 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, gotoTab } = 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 gotoTab(page, 'Assets');
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 gotoTab(page, 'Coverage');
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 gotoTab(page, 'Faraid');
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 gotoTab(page, 'Wassiyah');
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); });