Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.6 KB
Raw Blame
import { createElement } from 'react'
import { act, create, type ReactTestRenderer } from 'react-test-renderer'
import { afterEach, describe, expect, it } from 'vitest'
import { useMobileNativeChatDrafts } from './use-mobile-native-chat-drafts'
import {
  resetMobileNativeChatDraftStoreForTests,
  useMobileNativeChatDraft
} from './mobile-native-chat-draft-store'

describe('useMobileNativeChatDrafts with queued cards', () => {
  let renderer: ReactTestRenderer | null = null
  let state: (ReturnType<typeof useMobileNativeChatDrafts> & { composerText: string }) | null = null

  afterEach(() => {
    act(() => renderer?.unmount())
    resetMobileNativeChatDraftStoreForTests()
    renderer = null
    state = null
  })

  function Harness(): null {
    const drafts = useMobileNativeChatDrafts({
      hostId: 'host',
      worktreeId: 'worktree',
      tabId: 'a',
      sessionId: 'session-a',
      messages: [],
      launchDraft: null,
      transcriptLoading: false,
      transcriptSettled: true
    })
    state = { ...drafts, composerText: useMobileNativeChatDraft(drafts.draftKey) }
    return null
  }

  async function render(): Promise<void> {
    await act(async () => {
      renderer = create(createElement(Harness))
    })
  }

  it("reports whether a queued card's Edit copy landed, so Edit never deletes text it did not keep", async () => {
    await render()
    let copied: boolean | undefined
    act(() => {
      copied = state?.appendComposerText('')
    })
    expect(copied).toBe(false)
    act(() => {
      copied = state?.appendComposerText('edited text')
    })
    expect(copied).toBe(true)
    expect(state?.composerText).toBe('edited text')
  })
})