Files
psf-memo-client/test/unit/page-build-helpers.js
Chris Troutner b4508e8909 Reduce DRY duplication in reply-memo tests
Refactor the coder's new memo-reply and reply-thread-page tests to use
the shared test helpers (fake wallet, MemoAction tests, page-controller
tests, page submit tests, page build wiring). Extend the memo-action and
page-build helpers to support the reply slice's extra parent-txid
argument and byte-based multi-byte tests. Behavior is preserved; all
unit, property, and acceptance tests pass.

By refactorer.
2026-08-25 21:15:07 -07:00

29 lines
1.2 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
// pageDeps - extra dependencies passed to the page constructor
function buildPage ({ Page, Action, actionKey, storeKey, storeFactory, pageDeps = {} }) {
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),
...pageDeps
})
return { wallet, store, action, page, navigations }
}
module.exports = { buildPage }