Files
psf-memo-client/test/unit/page-build-helpers.js
T
Chris Troutner 0159119921 Reduce DRY duplication in unit and property tests
Extract shared test helpers for the Memo post and Set Name behavior
slices: fake wallet/profiles, MemoAction tests, page-controller tests,
page build wiring, and shared property-test invariants. Behavior is
preserved; all unit, property, and acceptance tests pass.

By refactorer.
2026-08-25 20:30:24 -07:00

27 lines
1.1 KiB
JavaScript

'use strict'
const { fakeWallet } = require('../helpers/fake-wallet')
// Build a page controller wired to a working action and a navigation recorder.
// Both the New Post and Set Name pages extend PageController and take a single
// action dependency plus a navigate callback, so the wiring is identical; only
// the page-specific pieces differ. `cfg` supplies:
// Page - the page controller class (NewPostPage or SetNamePage)
// Action - the action class (MemoPost or MemoSetName)
// actionKey - the page's action dependency key ('memoPost' or 'memoSetName')
// storeKey - the action's store dependency key ('feed' or 'profiles')
// storeFactory - () => a fresh store
function buildPage ({ Page, Action, actionKey, storeKey, storeFactory }) {
const wallet = fakeWallet()
const store = storeFactory()
const action = new Action({ wallet, [storeKey]: store })
const navigations = []
const page = new Page({
[actionKey]: action,
navigate: (path) => navigations.push(path)
})
return { wallet, store, action, page, navigations }
}
module.exports = { buildPage }