mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(post): move failed publish notice into comment body (#1066)
Align the failed notice and delete action with the existing post card and footer controls.
This commit is contained in:
@@ -169,6 +169,12 @@ const renderContent = async (comment: TestComment) => {
|
||||
});
|
||||
};
|
||||
|
||||
const renderContentWithProps = async (props: { comment: TestComment; prependContent?: React.ReactNode }) => {
|
||||
await act(async () => {
|
||||
root.render(createElement(CommentContent, props as any));
|
||||
});
|
||||
};
|
||||
|
||||
const queryMarkdownText = () => Array.from(container.querySelectorAll('[data-testid="markdown"]')).map((node) => node.textContent ?? '');
|
||||
|
||||
describe('CommentContent', () => {
|
||||
@@ -217,6 +223,35 @@ describe('CommentContent', () => {
|
||||
expect(previews[0]?.textContent).toBe('quoted-2');
|
||||
});
|
||||
|
||||
it('renders prepended content before reply quote previews and markdown', async () => {
|
||||
testState.commentsByCid = {
|
||||
'quoted-1': { cid: 'quoted-1', number: 11 },
|
||||
};
|
||||
testState.postNumbers = {
|
||||
'quoted-1': 11,
|
||||
};
|
||||
|
||||
await renderContentWithProps({
|
||||
comment: {
|
||||
cid: 'reply-1',
|
||||
content: 'body',
|
||||
parentCid: 'quoted-1',
|
||||
postCid: 'post-1',
|
||||
},
|
||||
prependContent: createElement('span', { 'data-testid': 'prepend' }, 'failed notice'),
|
||||
});
|
||||
|
||||
const blockquote = container.querySelector('blockquote');
|
||||
const prepend = container.querySelector('[data-testid="prepend"]');
|
||||
const preview = container.querySelector('[data-testid="reply-quote-preview"]');
|
||||
const markdown = container.querySelector('[data-testid="markdown"]');
|
||||
|
||||
expect(blockquote?.firstChild).toBe(prepend);
|
||||
expect(preview?.textContent).toBe('quoted-1');
|
||||
expect(markdown?.textContent).toBe('body');
|
||||
expect(blockquote?.querySelectorAll('br')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('truncates long comments outside the post view and expands them on demand', async () => {
|
||||
const longComment = 'x'.repeat(1105);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Fragment, useMemo, useState } from 'react';
|
||||
import { Fragment, type ReactNode, useMemo, useState } from 'react';
|
||||
import { useLocation, useParams } from 'react-router-dom';
|
||||
import { Trans, useTranslation } from 'react-i18next';
|
||||
import { Comment, useComment } from '@bitsocialnet/bitsocial-react-hooks';
|
||||
@@ -62,7 +62,7 @@ const useScopedCidToNumber = (cids: string[]) => {
|
||||
return cidToNumber;
|
||||
};
|
||||
|
||||
const CommentContent = ({ comment: post }: { comment: Comment }) => {
|
||||
const CommentContent = ({ comment: post, prependContent }: { comment: Comment; prependContent?: ReactNode }) => {
|
||||
const { t } = useTranslation();
|
||||
const params = useParams();
|
||||
const location = useLocation();
|
||||
@@ -126,6 +126,12 @@ const CommentContent = ({ comment: post }: { comment: Comment }) => {
|
||||
|
||||
return (
|
||||
<blockquote className={`${styles.postMessage} ${!isReply && isMobile && styles.clampLines}`}>
|
||||
{prependContent && (
|
||||
<>
|
||||
{prependContent}
|
||||
<br />
|
||||
</>
|
||||
)}
|
||||
{isReply &&
|
||||
!hasFailedState &&
|
||||
!(deleted || removed || purged) &&
|
||||
|
||||
Reference in New Issue
Block a user