fix(quotes): keep same-thread board previews local

This commit is contained in:
Tommaso Casaburi
2026-04-16 15:33:12 +07:00
parent f6ce2ba018
commit e366dac25c
16 changed files with 293 additions and 64 deletions
@@ -41,7 +41,7 @@ let latestValue: ReturnType<typeof usePublishPost>;
let root: Root;
const HookHarness = () => {
latestValue = usePublishPost({ subplebbitAddress: 'music.eth' });
latestValue = usePublishPost({ communityAddress: 'music.eth' });
return null;
};
@@ -92,7 +92,6 @@ describe('usePublishPost', () => {
spoiler: true,
title: 'Hello world',
});
expect('subplebbitAddress' in latestValue.publishPostOptions).toBe(false);
expect(typeof latestValue.publishPostOptions.onChallengeVerification).toBe('function');
expect(typeof latestValue.publishPostOptions.onError).toBe('function');
});
@@ -41,6 +41,7 @@ vi.mock('@bitsocialnet/bitsocial-react-hooks', () => ({
vi.mock('../../hooks/use-directories', () => ({
useDirectories: () => testState.directories,
normalizeBoardAddress: (address?: string) => address?.replace(/(\.bso|\.eth)$/u, ''),
}));
vi.mock('../../lib/utils/external-quote-resolver', () => ({
@@ -60,7 +61,7 @@ let latestValue: ReturnType<typeof usePublishReply>;
let root: Root;
const HookHarness = () => {
latestValue = usePublishReply({ cid: 'parent-cid', subplebbitAddress: 'music.eth' });
latestValue = usePublishReply({ cid: 'parent-cid', communityAddress: 'music.eth' });
return null;
};
@@ -122,14 +123,13 @@ describe('usePublishReply', () => {
quotedCids: ['quoted-cid'],
spoiler: true,
});
expect('subplebbitAddress' in (testState.lastPublishOptions || {})).toBe(false);
});
it('resolves same-board external quote references before triggering publish', async () => {
testState.resolveExternalQuoteTargetMock.mockResolvedValue({
cid: 'external-cid',
route: '/music/thread/external-cid',
subplebbitAddress: 'music.eth',
communityAddress: 'music.eth',
});
await act(async () => {
@@ -72,4 +72,32 @@ describe('useQuotedByMap', () => {
expect(latestValue.get('op-cid')?.[0]?.number).toBe(42);
});
it('matches same-board quote numbers across .eth and .bso aliases', () => {
usePostNumberStore.setState({
cidToNumber: { 'op-cid': 1 },
numberToCid: { 'music.eth': { 1: 'op-cid' } },
});
testState.replies = [
{
cid: 'reply-cid',
content: 'replying to >>1',
number: 42,
state: 'succeeded',
subplebbitAddress: 'music.bso',
},
];
act(() => {
root.render(
createElement(() => {
latestValue = useQuotedByMap(testState.replies as never, 'music.bso');
return null;
}),
);
});
expect(latestValue.get('op-cid')?.[0]?.cid).toBe('reply-cid');
});
});