fix(transfer): hide transferred label on trash board posts

Posts moved to /trash/ should not show the transferred tag since the move is the intended outcome.
This commit is contained in:
Tommaso Casaburi
2026-07-28 14:28:37 +07:00
parent de47749c52
commit 56b22e7ea9
2 changed files with 22 additions and 0 deletions
@@ -2,6 +2,7 @@ import * as React from 'react';
import { createElement } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { TRASH_BOARD_ADDRESS } from '../../lib/special-boards';
import PostTransferredTag from '../post-transferred-tag';
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
@@ -36,6 +37,22 @@ describe('PostTransferredTag', () => {
expect(container.textContent).toBe('[Transferred] ');
});
it('does not render the transferred label for posts moved to trash', async () => {
await act(async () => {
root.render(
createElement(PostTransferredTag, {
comment: {
commentModeration: { flairs: [{ text: '5chan:transferred' }] },
communityAddress: TRASH_BOARD_ADDRESS,
title: 'Original title',
},
}),
);
});
expect(container.textContent).toBe('');
});
it('ignores user-authored transferred-looking flairs', async () => {
await act(async () => {
root.render(createElement(PostTransferredTag, { comment: { flairs: [{ text: '5chan:transferred' }] } }));
+5
View File
@@ -1,5 +1,7 @@
import { useTranslation } from 'react-i18next';
import { hasTransferredCommentMarker } from '../lib/comment-transfer';
import { getSpecialBoardByAddress, TRASH_BOARD_CODE } from '../lib/special-boards';
import { getCommentCommunityAddress } from '../lib/utils/comment-utils';
import styles from './post-transferred-tag.module.css';
interface PostTransferredTagProps {
@@ -10,6 +12,9 @@ const PostTransferredTag = ({ comment }: PostTransferredTagProps) => {
const { t } = useTranslation();
if (!hasTransferredCommentMarker(comment)) return null;
if (getSpecialBoardByAddress(getCommentCommunityAddress(comment))?.directoryCode === TRASH_BOARD_CODE) {
return null;
}
return (
<span className={styles.transferredTag} title={t('transferred')}>