fix(conversations): 修复会话标识与解决后跳转
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user