mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-08-07 01:03:34 +02:00
extract conversation navigation state
This commit is contained in:
@@ -34,14 +34,15 @@ describe('useAppShell', () => {
|
||||
expect(result.current.showSettings).toBe(false);
|
||||
});
|
||||
|
||||
it('supports React-style target message updates', () => {
|
||||
it('toggles the cracker shell without affecting sidebar state', () => {
|
||||
const { result } = renderHook(() => useAppShell());
|
||||
|
||||
act(() => {
|
||||
result.current.setTargetMessageId(10);
|
||||
result.current.setTargetMessageId((prev) => (prev ?? 0) + 5);
|
||||
result.current.setSidebarOpen(true);
|
||||
result.current.handleToggleCracker();
|
||||
});
|
||||
|
||||
expect(result.current.targetMessageId).toBe(15);
|
||||
expect(result.current.showCracker).toBe(true);
|
||||
expect(result.current.sidebarOpen).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -65,14 +65,11 @@ function createArgs(overrides: Partial<Parameters<typeof useConversationActions>
|
||||
return {
|
||||
activeConversation,
|
||||
activeConversationRef: { current: activeConversation },
|
||||
setTargetMessageId: vi.fn(),
|
||||
channels: [publicChannel],
|
||||
setChannels: vi.fn(),
|
||||
addMessageIfNew: vi.fn(() => true),
|
||||
jumpToBottom: vi.fn(),
|
||||
handleToggleBlockedKey: vi.fn(async () => {}),
|
||||
handleToggleBlockedName: vi.fn(async () => {}),
|
||||
handleSelectConversation: vi.fn(),
|
||||
messageInputRef: { current: { appendText: vi.fn() } },
|
||||
...overrides,
|
||||
};
|
||||
@@ -123,47 +120,6 @@ describe('useConversationActions', () => {
|
||||
expect(args.addMessageIfNew).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('resets the jump target when switching to a normal conversation', () => {
|
||||
const args = createArgs();
|
||||
const { result } = renderHook(() => useConversationActions(args));
|
||||
|
||||
act(() => {
|
||||
result.current.handleSelectConversationWithTargetReset({
|
||||
type: 'contact',
|
||||
id: 'bb'.repeat(32),
|
||||
name: 'Bob',
|
||||
});
|
||||
});
|
||||
|
||||
expect(args.setTargetMessageId).toHaveBeenCalledWith(null);
|
||||
expect(args.handleSelectConversation).toHaveBeenCalledWith({
|
||||
type: 'contact',
|
||||
id: 'bb'.repeat(32),
|
||||
name: 'Bob',
|
||||
});
|
||||
});
|
||||
|
||||
it('navigates search results into the target conversation and preserves the jump target', () => {
|
||||
const args = createArgs();
|
||||
const { result } = renderHook(() => useConversationActions(args));
|
||||
|
||||
act(() => {
|
||||
result.current.handleNavigateToMessage({
|
||||
id: 321,
|
||||
type: 'CHAN',
|
||||
conversation_key: publicChannel.key,
|
||||
conversation_name: publicChannel.name,
|
||||
});
|
||||
});
|
||||
|
||||
expect(args.setTargetMessageId).toHaveBeenCalledWith(321);
|
||||
expect(args.handleSelectConversation).toHaveBeenCalledWith({
|
||||
type: 'channel',
|
||||
id: publicChannel.key,
|
||||
name: publicChannel.name,
|
||||
});
|
||||
});
|
||||
|
||||
it('clears cached messages and jumps to the latest page after blocking a key', async () => {
|
||||
const args = createArgs();
|
||||
const { result } = renderHook(() => useConversationActions(args));
|
||||
@@ -176,4 +132,15 @@ describe('useConversationActions', () => {
|
||||
expect(mocks.messageCache.clear).toHaveBeenCalledTimes(1);
|
||||
expect(args.jumpToBottom).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('appends sender mentions into the message input', () => {
|
||||
const args = createArgs();
|
||||
const { result } = renderHook(() => useConversationActions(args));
|
||||
|
||||
act(() => {
|
||||
result.current.handleSenderClick('Alice');
|
||||
});
|
||||
|
||||
expect(args.messageInputRef.current?.appendText).toHaveBeenCalledWith('@[Alice] ');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { useConversationNavigation } from '../hooks/useConversationNavigation';
|
||||
import type { Channel } from '../types';
|
||||
|
||||
const publicChannel: Channel = {
|
||||
key: '8B3387E9C5CDEA6AC9E5EDBAA115CD72',
|
||||
name: 'Public',
|
||||
is_hashtag: false,
|
||||
on_radio: false,
|
||||
last_read_at: null,
|
||||
};
|
||||
|
||||
function createArgs(overrides: Partial<Parameters<typeof useConversationNavigation>[0]> = {}) {
|
||||
return {
|
||||
channels: [publicChannel],
|
||||
handleSelectConversation: vi.fn(),
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe('useConversationNavigation', () => {
|
||||
it('resets the jump target when switching to a non-search conversation', () => {
|
||||
const args = createArgs();
|
||||
const { result } = renderHook(() => useConversationNavigation(args));
|
||||
|
||||
act(() => {
|
||||
result.current.setTargetMessageId(10);
|
||||
result.current.handleSelectConversationWithTargetReset({
|
||||
type: 'contact',
|
||||
id: 'aa'.repeat(32),
|
||||
name: 'Alice',
|
||||
});
|
||||
});
|
||||
|
||||
expect(result.current.targetMessageId).toBeNull();
|
||||
expect(args.handleSelectConversation).toHaveBeenCalledWith({
|
||||
type: 'contact',
|
||||
id: 'aa'.repeat(32),
|
||||
name: 'Alice',
|
||||
});
|
||||
});
|
||||
|
||||
it('preserves the jump target when navigating from search results', () => {
|
||||
const args = createArgs();
|
||||
const { result } = renderHook(() => useConversationNavigation(args));
|
||||
|
||||
act(() => {
|
||||
result.current.handleNavigateToMessage({
|
||||
id: 321,
|
||||
type: 'CHAN',
|
||||
conversation_key: publicChannel.key,
|
||||
conversation_name: publicChannel.name,
|
||||
});
|
||||
});
|
||||
|
||||
expect(result.current.targetMessageId).toBe(321);
|
||||
expect(args.handleSelectConversation).toHaveBeenCalledWith({
|
||||
type: 'channel',
|
||||
id: publicChannel.key,
|
||||
name: publicChannel.name,
|
||||
});
|
||||
});
|
||||
|
||||
it('closes the contact info pane when navigating to a channel', () => {
|
||||
const args = createArgs();
|
||||
const { result } = renderHook(() => useConversationNavigation(args));
|
||||
|
||||
act(() => {
|
||||
result.current.handleOpenContactInfo('bb'.repeat(32), true);
|
||||
result.current.handleNavigateToChannel(publicChannel.key);
|
||||
});
|
||||
|
||||
expect(result.current.infoPaneContactKey).toBeNull();
|
||||
expect(args.handleSelectConversation).toHaveBeenCalledWith({
|
||||
type: 'channel',
|
||||
id: publicChannel.key,
|
||||
name: publicChannel.name,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user