mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(pending-post): preserve sparse retry routes
This commit is contained in:
@@ -10,6 +10,7 @@ const act = (React as { act?: (cb: () => void | Promise<void>) => void | Promise
|
||||
type TestComment = {
|
||||
cid?: string;
|
||||
communityAddress?: string;
|
||||
index?: number;
|
||||
};
|
||||
|
||||
const testState = vi.hoisted(() => ({
|
||||
@@ -136,6 +137,29 @@ describe('PendingPost', () => {
|
||||
expect(testState.navigateMock).toHaveBeenCalledWith('/not-found', { replace: true });
|
||||
});
|
||||
|
||||
it('keeps sparse pending account comment indices addressable', async () => {
|
||||
testState.accountCommentIndex = '1';
|
||||
testState.accountComments = [{ index: 1 }];
|
||||
testState.post = {
|
||||
communityAddress: 'music-posting.eth',
|
||||
index: 1,
|
||||
};
|
||||
|
||||
await renderPendingPost();
|
||||
|
||||
expect(container.querySelector('[data-testid="post-view"]')?.textContent).toBe('no-post');
|
||||
expect(testState.navigateMock).not.toHaveBeenCalledWith('/not-found', { replace: true });
|
||||
});
|
||||
|
||||
it('redirects missing sparse pending account comment indices to not found', async () => {
|
||||
testState.accountCommentIndex = '0';
|
||||
testState.accountComments = [{ index: 1 }];
|
||||
|
||||
await renderPendingPost();
|
||||
|
||||
expect(testState.navigateMock).toHaveBeenCalledWith('/not-found', { replace: true });
|
||||
});
|
||||
|
||||
it('redirects resolved pending posts to the canonical thread route', async () => {
|
||||
testState.accountCommentIndex = '1';
|
||||
testState.accountComments = [{}, {}];
|
||||
|
||||
@@ -7,6 +7,30 @@ import { getCommentCommunityAddress } from '../../lib/utils/comment-utils';
|
||||
import { getBoardPath } from '../../lib/utils/route-utils';
|
||||
import { Post } from '../post';
|
||||
|
||||
type PendingAccountComment = {
|
||||
index?: number;
|
||||
};
|
||||
|
||||
const hasPendingAccountCommentIndex = (accountComments: PendingAccountComment[] | undefined, accountCommentIndex: number) => {
|
||||
if (!accountComments || accountComments.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let hasExplicitIndices = false;
|
||||
for (const accountComment of accountComments) {
|
||||
if (typeof accountComment?.index !== 'number') {
|
||||
continue;
|
||||
}
|
||||
|
||||
hasExplicitIndices = true;
|
||||
if (accountComment.index === accountCommentIndex) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return hasExplicitIndices ? false : accountCommentIndex < accountComments.length;
|
||||
};
|
||||
|
||||
const PendingPost = () => {
|
||||
const { accountComments } = useAccountComments();
|
||||
const { accountCommentIndex } = useParams<{ accountCommentIndex?: string }>();
|
||||
@@ -23,7 +47,7 @@ const PendingPost = () => {
|
||||
(hasNormalizedAccountCommentIndex &&
|
||||
normalizedAccountCommentIndex >= 0 &&
|
||||
Number.isInteger(normalizedAccountCommentIndex) &&
|
||||
(accountComments?.length === 0 || normalizedAccountCommentIndex < accountComments.length));
|
||||
hasPendingAccountCommentIndex(accountComments, normalizedAccountCommentIndex));
|
||||
|
||||
useEffect(() => {
|
||||
if (!isValidAccountCommentIndex) {
|
||||
|
||||
Reference in New Issue
Block a user