|
1 | 1 | import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test' |
2 | 2 |
|
| 3 | +import { useChatStore } from '../../state/chat-store' |
| 4 | + |
3 | 5 | import type { RouterParams } from '../command-registry' |
4 | | -import * as analytics from '../../utils/analytics' |
5 | 6 |
|
6 | | -const setInputMode = mock(() => {}) |
7 | | -const setMessages = mock(() => {}) |
8 | 7 | const saveToHistory = mock(() => {}) |
9 | 8 | const setInputValue = mock(() => {}) |
| 9 | +const setMessages = mock(() => {}) |
10 | 10 | const handleChatGptAuthCode = mock(async () => ({ |
11 | 11 | success: true, |
12 | 12 | message: 'ok', |
13 | 13 | })) |
14 | 14 |
|
15 | | -mock.module('../../state/chat-store', () => ({ |
16 | | - useChatStore: { |
17 | | - getState: () => ({ |
18 | | - inputMode: 'connect:chatgpt', |
19 | | - setInputMode, |
20 | | - pendingAttachments: [], |
21 | | - }), |
22 | | - }, |
23 | | -})) |
24 | | - |
25 | 15 | mock.module('../../components/chatgpt-connect-banner', () => ({ |
26 | 16 | handleChatGptAuthCode, |
27 | 17 | })) |
28 | 18 |
|
29 | | -mock.module('../../utils/analytics', () => ({ |
30 | | - ...analytics, |
31 | | - trackEvent: () => {}, |
32 | | -})) |
33 | | - |
34 | 19 | mock.module('@codebuff/common/constants/chatgpt-oauth', () => ({ |
35 | 20 | CHATGPT_OAUTH_ENABLED: true, |
36 | 21 | })) |
37 | 22 |
|
38 | 23 | describe('routeUserPrompt connect:chatgpt mode', () => { |
39 | 24 | beforeEach(() => { |
40 | | - setInputMode.mockClear() |
41 | | - setMessages.mockClear() |
| 25 | + useChatStore.getState().reset() |
| 26 | + useChatStore.getState().setInputMode('connect:chatgpt') |
42 | 27 | saveToHistory.mockClear() |
43 | 28 | setInputValue.mockClear() |
| 29 | + setMessages.mockClear() |
44 | 30 | handleChatGptAuthCode.mockClear() |
45 | 31 | }) |
46 | 32 |
|
47 | 33 | afterEach(() => { |
48 | | - setInputMode.mockClear() |
49 | | - setMessages.mockClear() |
50 | | - saveToHistory.mockClear() |
51 | | - setInputValue.mockClear() |
52 | | - handleChatGptAuthCode.mockClear() |
| 34 | + useChatStore.getState().reset() |
53 | 35 | }) |
54 | 36 |
|
55 | 37 | test('when in connect:chatgpt mode, it exchanges the auth code and updates messages', async () => { |
@@ -82,6 +64,6 @@ describe('routeUserPrompt connect:chatgpt mode', () => { |
82 | 64 |
|
83 | 65 | expect(handleChatGptAuthCode).toHaveBeenCalledWith('auth-code-123') |
84 | 66 | expect(setMessages).toHaveBeenCalled() |
85 | | - expect(setInputMode).toHaveBeenCalledWith('default') |
| 67 | + expect(useChatStore.getState().inputMode).toBe('default') |
86 | 68 | }) |
87 | 69 | }) |
0 commit comments