From fd44d1255fdd7ebef88e9388c04a04d359e91777 Mon Sep 17 00:00:00 2001 From: Nuwan Date: Tue, 27 Jan 2026 08:04:43 +0530 Subject: [PATCH] test(07-01): add failing tests for sessionChatSlice initial state RED phase of TDD: - Write tests for all 12 initial state fields - Validates messagesByChannel, activeChannel, channelType - Validates unread tracking: unreadCounts, lastReadAt - Validates fetch state: fetchStatus, fetchError - Validates send state: sendStatus, sendError - Validates pagination: nextCursors - Validates UI state: isWindowOpen, windowPosition Tests fail as expected - slice doesn't exist yet. Co-Authored-By: Claude Sonnet 4.5 --- .../__tests__/sessionChatSlice.test.js | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 jam-ui/src/store/features/__tests__/sessionChatSlice.test.js diff --git a/jam-ui/src/store/features/__tests__/sessionChatSlice.test.js b/jam-ui/src/store/features/__tests__/sessionChatSlice.test.js new file mode 100644 index 000000000..45116551e --- /dev/null +++ b/jam-ui/src/store/features/__tests__/sessionChatSlice.test.js @@ -0,0 +1,81 @@ +import sessionChatReducer from '../sessionChatSlice'; + +describe('sessionChatSlice initial state', () => { + test('has empty messagesByChannel object', () => { + const state = sessionChatReducer(undefined, { type: 'unknown' }); + expect(state.messagesByChannel).toEqual({}); + }); + + test('has null activeChannel', () => { + const state = sessionChatReducer(undefined, { type: 'unknown' }); + expect(state.activeChannel).toBeNull(); + }); + + test('has null channelType', () => { + const state = sessionChatReducer(undefined, { type: 'unknown' }); + expect(state.channelType).toBeNull(); + }); + + test('has empty unreadCounts object', () => { + const state = sessionChatReducer(undefined, { type: 'unknown' }); + expect(state.unreadCounts).toEqual({}); + }); + + test('has empty lastReadAt object', () => { + const state = sessionChatReducer(undefined, { type: 'unknown' }); + expect(state.lastReadAt).toEqual({}); + }); + + test('has empty fetchStatus object', () => { + const state = sessionChatReducer(undefined, { type: 'unknown' }); + expect(state.fetchStatus).toEqual({}); + }); + + test('has empty fetchError object', () => { + const state = sessionChatReducer(undefined, { type: 'unknown' }); + expect(state.fetchError).toEqual({}); + }); + + test('has idle sendStatus', () => { + const state = sessionChatReducer(undefined, { type: 'unknown' }); + expect(state.sendStatus).toBe('idle'); + }); + + test('has null sendError', () => { + const state = sessionChatReducer(undefined, { type: 'unknown' }); + expect(state.sendError).toBeNull(); + }); + + test('has empty nextCursors object', () => { + const state = sessionChatReducer(undefined, { type: 'unknown' }); + expect(state.nextCursors).toEqual({}); + }); + + test('has isWindowOpen set to false', () => { + const state = sessionChatReducer(undefined, { type: 'unknown' }); + expect(state.isWindowOpen).toBe(false); + }); + + test('has null windowPosition', () => { + const state = sessionChatReducer(undefined, { type: 'unknown' }); + expect(state.windowPosition).toBeNull(); + }); + + test('complete initial state structure matches design', () => { + const state = sessionChatReducer(undefined, { type: 'unknown' }); + expect(state).toEqual({ + messagesByChannel: {}, + activeChannel: null, + channelType: null, + unreadCounts: {}, + lastReadAt: {}, + fetchStatus: {}, + fetchError: {}, + sendStatus: 'idle', + sendError: null, + nextCursors: {}, + isWindowOpen: false, + windowPosition: null + }); + }); +});