Skip to content

Commit ab7df7c

Browse files
committed
test(cli): update tests for input mode refactoring
Replace isUsageVisible references with inputMode checks. Update test assertions to use setInputMode instead of setIsUsageVisible.
1 parent 9912876 commit ab7df7c

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

cli/src/__tests__/integration/usage-refresh-on-completion.test.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import * as authModule from '../../utils/auth'
99
* Integration test for usage refresh on SDK run completion
1010
*
1111
* This test verifies the complete lifecycle:
12-
* 1. User opens usage banner (isUsageVisible = true)
12+
* 1. User opens usage banner (inputMode = 'usage')
1313
* 2. SDK run completes successfully
1414
* 3. Query is invalidated to trigger refresh
1515
* 4. Banner shows updated credit balance (when query refetches)
1616
*
1717
* Also tests:
18-
* - No invalidation when banner is closed (isUsageVisible = false)
18+
* - No invalidation when banner is closed (inputMode = 'default')
1919
* - Multiple sequential runs with banner open
2020
*/
2121
describe('Usage Refresh on SDK Completion', () => {
@@ -65,16 +65,16 @@ describe('Usage Refresh on SDK Completion', () => {
6565
describe('banner visible scenarios', () => {
6666
test('should invalidate query when banner is visible and run completes', () => {
6767
// Setup: Open usage banner
68-
useChatStore.getState().setIsUsageVisible(true)
69-
expect(useChatStore.getState().isUsageVisible).toBe(true)
68+
useChatStore.getState().setInputMode('usage')
69+
expect(useChatStore.getState().inputMode).toBe('usage')
7070

7171
// Spy on invalidateQueries
7272
const invalidateSpy = mock(queryClient.invalidateQueries.bind(queryClient))
7373
queryClient.invalidateQueries = invalidateSpy as any
7474

7575
// Simulate SDK run completion triggering invalidation
76-
const isUsageVisible = useChatStore.getState().isUsageVisible
77-
if (isUsageVisible) {
76+
const isUsageMode = useChatStore.getState().inputMode === 'usage'
77+
if (isUsageMode) {
7878
queryClient.invalidateQueries({ queryKey: usageQueryKeys.current() })
7979
}
8080

@@ -86,14 +86,14 @@ describe('Usage Refresh on SDK Completion', () => {
8686
})
8787

8888
test('should invalidate multiple times for sequential runs', () => {
89-
useChatStore.getState().setIsUsageVisible(true)
89+
useChatStore.getState().setInputMode('usage')
9090

9191
const invalidateSpy = mock(queryClient.invalidateQueries.bind(queryClient))
9292
queryClient.invalidateQueries = invalidateSpy as any
9393

9494
// Simulate three sequential SDK runs
9595
for (let i = 0; i < 3; i++) {
96-
if (useChatStore.getState().isUsageVisible) {
96+
if (useChatStore.getState().inputMode === 'usage') {
9797
queryClient.invalidateQueries({ queryKey: usageQueryKeys.current() })
9898
}
9999
}
@@ -104,16 +104,16 @@ describe('Usage Refresh on SDK Completion', () => {
104104

105105
describe('banner not visible scenarios', () => {
106106
test('should NOT invalidate when banner is not visible', () => {
107-
// Setup: Banner is closed
108-
useChatStore.getState().setIsUsageVisible(false)
109-
expect(useChatStore.getState().isUsageVisible).toBe(false)
107+
// Setup: Banner is closed (default mode)
108+
useChatStore.getState().setInputMode('default')
109+
expect(useChatStore.getState().inputMode).toBe('default')
110110

111111
const invalidateSpy = mock(queryClient.invalidateQueries.bind(queryClient))
112112
queryClient.invalidateQueries = invalidateSpy as any
113113

114114
// Simulate SDK run completion check
115-
const isUsageVisible = useChatStore.getState().isUsageVisible
116-
if (isUsageVisible) {
115+
const isUsageMode = useChatStore.getState().inputMode === 'usage'
116+
if (isUsageMode) {
117117
queryClient.invalidateQueries({ queryKey: usageQueryKeys.current() })
118118
}
119119

@@ -123,17 +123,17 @@ describe('Usage Refresh on SDK Completion', () => {
123123

124124
test('should not invalidate if banner was closed before run completed', () => {
125125
// Setup: Start with banner open
126-
useChatStore.getState().setIsUsageVisible(true)
126+
useChatStore.getState().setInputMode('usage')
127127

128128
// User closes banner before run completes
129-
useChatStore.getState().setIsUsageVisible(false)
129+
useChatStore.getState().setInputMode('default')
130130

131131
const invalidateSpy = mock(queryClient.invalidateQueries.bind(queryClient))
132132
queryClient.invalidateQueries = invalidateSpy as any
133133

134134
// Simulate run completion
135-
const isUsageVisible = useChatStore.getState().isUsageVisible
136-
if (isUsageVisible) {
135+
const isUsageMode = useChatStore.getState().inputMode === 'usage'
136+
if (isUsageMode) {
137137
queryClient.invalidateQueries({ queryKey: usageQueryKeys.current() })
138138
}
139139

@@ -144,7 +144,7 @@ describe('Usage Refresh on SDK Completion', () => {
144144
describe('query behavior', () => {
145145
test('should not fetch when enabled is false', () => {
146146
// Even if banner is visible in store, query won't run if enabled=false
147-
useChatStore.getState().setIsUsageVisible(true)
147+
useChatStore.getState().setInputMode('usage')
148148

149149
const fetchMock = mock(globalThis.fetch)
150150
globalThis.fetch = fetchMock as any
@@ -159,7 +159,7 @@ describe('Usage Refresh on SDK Completion', () => {
159159
describe('unauthenticated scenarios', () => {
160160
test('should not fetch when no auth token', () => {
161161
getAuthTokenSpy.mockReturnValue(undefined)
162-
useChatStore.getState().setIsUsageVisible(true)
162+
useChatStore.getState().setInputMode('usage')
163163

164164
const fetchMock = mock(globalThis.fetch)
165165
globalThis.fetch = fetchMock as any

cli/src/utils/__tests__/fetch-usage.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { FetchAndUpdateUsageParams } from '../fetch-usage'
66
import type { Logger } from '@codebuff/common/types/contracts/logger'
77

88
describe('fetchAndUpdateUsage (deprecated)', () => {
9-
let setIsUsageVisibleMock: ReturnType<typeof mock>
9+
let setInputModeMock: ReturnType<typeof mock>
1010
let getAuthTokenMock: ReturnType<typeof mock>
1111
let loggerMock: Logger
1212
let fetchMock: ReturnType<typeof mock>
@@ -24,15 +24,15 @@ describe('fetchAndUpdateUsage (deprecated)', () => {
2424
getAuthToken: getAuthTokenMock,
2525
getChatStore: () => ({
2626
sessionCreditsUsed: 150,
27-
setIsUsageVisible: setIsUsageVisibleMock,
27+
setInputMode: setInputModeMock,
2828
}),
2929
logger: loggerMock,
3030
fetch: fetchMock as any,
3131
...overrides,
3232
})
3333

3434
beforeEach(() => {
35-
setIsUsageVisibleMock = mock(() => {})
35+
setInputModeMock = mock(() => {})
3636
getAuthTokenMock = mock(() => 'test-auth-token')
3737
loggerMock = {
3838
info: mock(() => {}),
@@ -56,7 +56,7 @@ describe('fetchAndUpdateUsage (deprecated)', () => {
5656

5757
expect(result).toBe(true)
5858
// Note: setUsageData no longer called - data managed by TanStack Query
59-
expect(setIsUsageVisibleMock).not.toHaveBeenCalled()
59+
expect(setInputModeMock).not.toHaveBeenCalled()
6060
})
6161

6262
test('should show banner when showBanner parameter is true', async () => {
@@ -66,8 +66,8 @@ describe('fetchAndUpdateUsage (deprecated)', () => {
6666

6767
expect(result).toBe(true)
6868
// Note: setUsageData no longer called - data managed by TanStack Query
69-
expect(setIsUsageVisibleMock).toHaveBeenCalledTimes(1)
70-
expect(setIsUsageVisibleMock.mock.calls[0][0]).toBe(true)
69+
expect(setInputModeMock).toHaveBeenCalledTimes(1)
70+
expect(setInputModeMock.mock.calls[0][0]).toBe('usage')
7171
})
7272

7373
test('should handle null remainingBalance correctly', async () => {
@@ -111,7 +111,7 @@ describe('fetchAndUpdateUsage (deprecated)', () => {
111111
const result = await fetchAndUpdateUsage(createDefaultParams())
112112

113113
expect(result).toBe(false)
114-
expect(setIsUsageVisibleMock).not.toHaveBeenCalled()
114+
expect(setInputModeMock).not.toHaveBeenCalled()
115115
expect(loggerMock.debug).toHaveBeenCalled()
116116
})
117117

@@ -190,7 +190,7 @@ describe('fetchAndUpdateUsage (deprecated)', () => {
190190
createDefaultParams({
191191
getChatStore: () => ({
192192
sessionCreditsUsed: 250,
193-
setIsUsageVisible: setIsUsageVisibleMock,
193+
setInputMode: setInputModeMock,
194194
}),
195195
}),
196196
)
@@ -204,7 +204,7 @@ describe('fetchAndUpdateUsage (deprecated)', () => {
204204
createDefaultParams({
205205
getChatStore: () => ({
206206
sessionCreditsUsed: 0,
207-
setIsUsageVisible: setIsUsageVisibleMock,
207+
setInputMode: setInputModeMock,
208208
}),
209209
}),
210210
)
@@ -262,7 +262,7 @@ describe('fetchAndUpdateUsage (deprecated)', () => {
262262

263263
expect(results).toEqual([true, true, true])
264264
// Note: setUsageData no longer called - data managed by TanStack Query
265-
expect(setIsUsageVisibleMock).toHaveBeenCalledTimes(1)
265+
expect(setInputModeMock).toHaveBeenCalledTimes(1)
266266
})
267267
})
268268
})

0 commit comments

Comments
 (0)