|
| 1 | +/** |
| 2 | + * Tests for the ThreadIndicator visibility condition in the compose strip. |
| 3 | + * |
| 4 | + * The indicator renders when a user is replying to a thread message from the |
| 5 | + * main timeline (no threadRootId). It must NOT appear when composing inside |
| 6 | + * the ThreadDrawer (threadRootId is set), because the drawer already makes the |
| 7 | + * thread context obvious. |
| 8 | + * |
| 9 | + * Mirrors the exact render guard in RoomInput.tsx: |
| 10 | + * {replyDraft.relation?.rel_type === RelationType.Thread && !threadRootId && ( |
| 11 | + * <ThreadIndicator /> |
| 12 | + * )} |
| 13 | + */ |
| 14 | +import { describe, it, expect } from 'vitest'; |
| 15 | +import { render, screen } from '@testing-library/react'; |
| 16 | +import { RelationType } from '$types/matrix-sdk'; |
| 17 | +import { ThreadIndicator } from './Reply'; |
| 18 | + |
| 19 | +function Subject({ relType, threadRootId }: { relType?: string; threadRootId?: string }) { |
| 20 | + return <>{relType === RelationType.Thread && !threadRootId && <ThreadIndicator />}</>; |
| 21 | +} |
| 22 | + |
| 23 | +describe('ThreadIndicator visibility in compose strip', () => { |
| 24 | + it('renders in the main timeline compose box when a thread relation is active', () => { |
| 25 | + render(<Subject relType={RelationType.Thread} />); |
| 26 | + expect(screen.getByText('Thread')).toBeInTheDocument(); |
| 27 | + }); |
| 28 | + |
| 29 | + it('is hidden inside the ThreadDrawer when threadRootId is set', () => { |
| 30 | + render(<Subject relType={RelationType.Thread} threadRootId="$root:example.com" />); |
| 31 | + expect(screen.queryByText('Thread')).not.toBeInTheDocument(); |
| 32 | + }); |
| 33 | + |
| 34 | + it('is hidden when the draft has no relation', () => { |
| 35 | + render(<Subject relType={undefined} />); |
| 36 | + expect(screen.queryByText('Thread')).not.toBeInTheDocument(); |
| 37 | + }); |
| 38 | + |
| 39 | + it('is hidden for a non-thread relation type', () => { |
| 40 | + render(<Subject relType="m.in_reply_to" />); |
| 41 | + expect(screen.queryByText('Thread')).not.toBeInTheDocument(); |
| 42 | + }); |
| 43 | +}); |
0 commit comments