|
1 | | -import { describe, test, expect, mock } from 'bun:test' |
| 1 | +import { afterEach, describe, test, expect, mock } from 'bun:test' |
2 | 2 |
|
3 | 3 | import { useFeedbackStore } from '../../state/feedback-store' |
| 4 | +import { useChatStore } from '../../state/chat-store' |
4 | 5 | import { |
5 | 6 | registerActiveRun, |
6 | 7 | stopActiveRun, |
@@ -178,6 +179,7 @@ describe('command factory pattern', () => { |
178 | 179 | // mode:* commands also accept args now |
179 | 180 | const expectedWithArgs = [ |
180 | 181 | 'feedback', |
| 182 | + 'btw', |
181 | 183 | 'bash', |
182 | 184 | 'image', |
183 | 185 | 'publish', |
@@ -346,4 +348,85 @@ describe('command factory pattern', () => { |
346 | 348 | expect(result).toEqual({ openFeedbackMode: true }) |
347 | 349 | }) |
348 | 350 | }) |
| 351 | + |
| 352 | + describe('/btw command', () => { |
| 353 | + afterEach(() => { |
| 354 | + useChatStore.getState().clearPendingAttachments() |
| 355 | + }) |
| 356 | + |
| 357 | + test('queues the note and pending attachments while a turn is active', () => { |
| 358 | + const btwCmd = COMMAND_REGISTRY.find((c) => c.name === 'btw') |
| 359 | + expect(btwCmd).toBeDefined() |
| 360 | + |
| 361 | + const attachment = { |
| 362 | + kind: 'text' as const, |
| 363 | + id: 'note.txt', |
| 364 | + content: 'remember the edge case', |
| 365 | + preview: 'remember the edge case', |
| 366 | + charCount: 22, |
| 367 | + } |
| 368 | + useChatStore.getState().clearPendingAttachments() |
| 369 | + useChatStore.getState().addPendingAttachment(attachment) |
| 370 | + |
| 371 | + const addToQueue = mock(() => {}) |
| 372 | + const sendMessage = mock(async () => {}) |
| 373 | + const setInputFocused = mock(() => {}) |
| 374 | + const params = createMockParams({ |
| 375 | + inputValue: '/btw remember the edge case', |
| 376 | + isStreaming: true, |
| 377 | + addToQueue, |
| 378 | + sendMessage, |
| 379 | + setInputFocused, |
| 380 | + }) |
| 381 | + |
| 382 | + btwCmd!.handler(params, 'remember the edge case') |
| 383 | + |
| 384 | + expect(addToQueue).toHaveBeenCalledWith( |
| 385 | + expect.stringContaining('remember the edge case'), |
| 386 | + [attachment], |
| 387 | + ) |
| 388 | + expect(sendMessage).not.toHaveBeenCalled() |
| 389 | + expect(setInputFocused).toHaveBeenCalledWith(true) |
| 390 | + expect(useChatStore.getState().pendingAttachments).toEqual([]) |
| 391 | + }) |
| 392 | + |
| 393 | + test('sends the note immediately when the CLI is idle', () => { |
| 394 | + const btwCmd = COMMAND_REGISTRY.find((c) => c.name === 'btw') |
| 395 | + expect(btwCmd).toBeDefined() |
| 396 | + |
| 397 | + const addToQueue = mock(() => {}) |
| 398 | + const sendMessage = mock(async () => {}) |
| 399 | + const params = createMockParams({ |
| 400 | + inputValue: '/btw check the parser', |
| 401 | + addToQueue, |
| 402 | + sendMessage, |
| 403 | + }) |
| 404 | + |
| 405 | + btwCmd!.handler(params, 'check the parser') |
| 406 | + |
| 407 | + expect(sendMessage).toHaveBeenCalledWith({ |
| 408 | + content: expect.stringContaining('check the parser'), |
| 409 | + agentMode: 'DEFAULT', |
| 410 | + }) |
| 411 | + expect(addToQueue).not.toHaveBeenCalled() |
| 412 | + }) |
| 413 | + |
| 414 | + test('shows usage instead of sending an empty note', () => { |
| 415 | + const btwCmd = COMMAND_REGISTRY.find((c) => c.name === 'btw') |
| 416 | + expect(btwCmd).toBeDefined() |
| 417 | + |
| 418 | + const setMessages = mock(() => {}) |
| 419 | + const sendMessage = mock(async () => {}) |
| 420 | + const params = createMockParams({ |
| 421 | + inputValue: '/btw', |
| 422 | + setMessages, |
| 423 | + sendMessage, |
| 424 | + }) |
| 425 | + |
| 426 | + btwCmd!.handler(params, '') |
| 427 | + |
| 428 | + expect(setMessages).toHaveBeenCalled() |
| 429 | + expect(sendMessage).not.toHaveBeenCalled() |
| 430 | + }) |
| 431 | + }) |
349 | 432 | }) |
0 commit comments