fix(conversations): 修复会话标识与解决后跳转

This commit is contained in:
Rogee
2026-08-06 11:19:39 +08:00
parent b78f963472
commit 8d002d1dbe
8 changed files with 173 additions and 12 deletions
@@ -0,0 +1,10 @@
export const getAdjacentConversationId = (conversationIds, currentId) => {
const currentIndex = conversationIds.indexOf(currentId);
if (currentIndex === -1) return null;
return (
conversationIds[currentIndex + 1] ??
conversationIds[currentIndex - 1] ??
null
);
};
@@ -0,0 +1,21 @@
import { getAdjacentConversationId } from '../conversationNavigation';
describe('getAdjacentConversationId', () => {
const conversationIds = [15, 19, 25];
it('selects the immediate next conversation', () => {
expect(getAdjacentConversationId(conversationIds, 15)).toBe(19);
});
it('selects the previous conversation for the last item', () => {
expect(getAdjacentConversationId(conversationIds, 25)).toBe(19);
});
it('returns null for a single-item list', () => {
expect(getAdjacentConversationId([15], 15)).toBeNull();
});
it('returns null when the current conversation is absent', () => {
expect(getAdjacentConversationId(conversationIds, 99)).toBeNull();
});
});