mirror of
https://github.com/Permissionless-Software-Foundation/psf-memo.git
synced 2026-09-21 16:52:01 -07:00
Use the reactive bchWalletState.cashAddress as the viewer address source and include it in the profile load effect dependencies. Extract a small wallet-address selector so the behavior is unit-testable. By coder.
61 lines
1.7 KiB
JavaScript
61 lines
1.7 KiB
JavaScript
/*
|
|
Unit tests for the profile wallet address selector.
|
|
|
|
The profile page must show follow/mute controls only when the viewer's
|
|
wallet address is known. The React app tracks the loaded address both in the
|
|
wallet object and in `bchWalletState`; the selector prefers the reactive
|
|
state so the profile reloads when the address becomes available.
|
|
*/
|
|
|
|
'use strict'
|
|
|
|
const test = require('node:test')
|
|
const assert = require('node:assert/strict')
|
|
const { getViewerAddress } = require('../../src/services/profile-wallet')
|
|
|
|
function makeAppData ({ bchCashAddress, walletCashAddress } = {}) {
|
|
return {
|
|
bchWalletState: {
|
|
cashAddress: bchCashAddress
|
|
},
|
|
wallet: walletCashAddress
|
|
? { walletInfo: { cashAddress: walletCashAddress } }
|
|
: null,
|
|
profiles: {}
|
|
}
|
|
}
|
|
|
|
test('getViewerAddress prefers bchWalletState.cashAddress', () => {
|
|
const appData = makeAppData({
|
|
bchCashAddress: 'bitcoincash:state-address',
|
|
walletCashAddress: 'bitcoincash:wallet-address'
|
|
})
|
|
|
|
assert.equal(getViewerAddress(appData), 'bitcoincash:state-address')
|
|
})
|
|
|
|
test('getViewerAddress falls back to wallet.walletInfo.cashAddress', () => {
|
|
const appData = makeAppData({
|
|
bchCashAddress: undefined,
|
|
walletCashAddress: 'bitcoincash:wallet-address'
|
|
})
|
|
|
|
assert.equal(getViewerAddress(appData), 'bitcoincash:wallet-address')
|
|
})
|
|
|
|
test('getViewerAddress returns null when no wallet is loaded', () => {
|
|
const appData = makeAppData({})
|
|
|
|
assert.equal(getViewerAddress(appData), null)
|
|
})
|
|
|
|
test('getViewerAddress returns null when wallet lacks an address', () => {
|
|
const appData = {
|
|
bchWalletState: {},
|
|
wallet: { walletInfo: {} },
|
|
profiles: {}
|
|
}
|
|
|
|
assert.equal(getViewerAddress(appData), null)
|
|
})
|