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.

2.4 KB
Raw Blame
import { createElement } from 'react'
import { act, create, type ReactTestRenderer } from 'react-test-renderer'
import { describe, expect, it, vi } from 'vitest'
import { CodexResetCreditAction } from './CodexResetCreditAction'
import { findAllByHostType, findByHostType } from '../test-support/react-test-renderer-host-nodes'

vi.mock('react-native', () => ({
  ActivityIndicator: 'ActivityIndicator',
  Pressable: 'Pressable',
  StyleSheet: { create: (styles: unknown) => styles, hairlineWidth: 1 },
  Text: 'Text',
  View: 'View'
}))

vi.mock('lucide-react-native', () => ({ RotateCcw: 'RotateCcw' }))

const summary = {
  availableCount: 1,
  availabilityLabel: '1 reset available',
  expiryLabel: 'Expires in 5d'
}

function renderAction(busy: boolean, disabled: boolean): ReactTestRenderer {
  let renderer: ReactTestRenderer | null = null
  act(() => {
    renderer = create(
      createElement(CodexResetCreditAction, {
        summary,
        scopeLabel: '[email protected] on the host',
        busy,
        disabled,
        onPress: vi.fn()
      })
    )
  })
  if (!renderer) {
    throw new Error('Reset action did not render')
  }
  return renderer
}

describe('CodexResetCreditAction', () => {
  it('exposes a 44pt touch target and enabled accessibility state', () => {
    const renderer = renderAction(false, false)
    const button = findByHostType(renderer.root, 'Pressable')

    expect(button.props.accessibilityLabel).toBe('Use Codex rate-limit reset')
    expect(button.props.accessibilityState).toEqual({ busy: false, disabled: false })
    expect(button.props.accessibilityHint).toContain('[email protected] on the host')
    expect(button.props.hitSlop).toBe(8)
    expect(button.props.style({ pressed: false })[0]).toMatchObject({ minHeight: 44 })
    act(() => renderer.unmount())
  })

  it('announces progress and visually dims a busy disabled action', () => {
    const renderer = renderAction(true, true)
    const button = findByHostType(renderer.root, 'Pressable')
    const text = findAllByHostType(renderer.root, 'Text').map((node) =>
      node.children.filter((child) => typeof child === 'string').join('')
    )

    expect(button.props.accessibilityLabel).toBe('Resetting Codex rate limits')
    expect(button.props.accessibilityState).toEqual({ busy: true, disabled: true })
    expect(button.props.style({ pressed: false })[1]).toMatchObject({ opacity: 0.5 })
    expect(text).toContain('Resetting…')
    act(() => renderer.unmount())
  })
})