The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(ui): cover input class override behavior
Steven Enamakel87b707bc2d53
diff --git a/app/src/components/ui/Input.test.tsx b/app/src/components/ui/Input.test.tsxindex 4c7e1290b4..7cb3a13e4e 100644--- a/app/src/components/ui/Input.test.tsx+++ b/app/src/components/ui/Input.test.tsx@@ -1,37 +1,46 @@import { render, screen } from '@testing-library/react';-import { createRef } from 'react';import { describe, expect, it } from 'vitest';import Input from './Input';-describe('Input', () => {- it('forwards native input attributes and refs', () => {- const ref = createRef<HTMLInputElement>();- render(<Input ref={ref} aria-label="Name" placeholder="Ada" />);-- const input = screen.getByRole('textbox', { name: 'Name' });- expect(input).toHaveAttribute('placeholder', 'Ada');- expect(ref.current).toBe(input);+/**+ * These pin the ONE thing this component gets wrong when it is written the+ * obvious way: composing its class list by concatenation.+ *+ * Concatenation leaves the size defaults in the attribute beside the caller's+ * override and lets Tailwind's stylesheet order pick the winner, so an+ * override applies or not depending on where the two utilities happen to sit+ * in the generated CSS. `cn` (tailwind-merge) resolves the conflict last-wins,+ * which is what every caller assumes.+ */+describe('Input class composition', () => {+ it('lets a caller override the size preset padding', () => {+ render(<Input inputSize="sm" className="px-2" aria-label="field" />);+ const el = screen.getByLabelText('field');+ // `px-2.5` is `SIZES.sm`'s padding. Under concatenation both survived and+ // `px-2.5` won on stylesheet order, silently ignoring the caller.+ expect(el).toHaveClass('px-2');+ expect(el).not.toHaveClass('px-2.5');});- it('sets aria-invalid only for invalid inputs', () => {- const { rerender } = render(<Input aria-label="Amount" invalid />);- expect(screen.getByRole('textbox', { name: 'Amount' })).toHaveAttribute('aria-invalid', 'true');-- rerender(<Input aria-label="Amount" />);- expect(screen.getByRole('textbox', { name: 'Amount' })).not.toHaveAttribute('aria-invalid');+ it('lets a caller override the size preset font size and height', () => {+ render(<Input inputSize="sm" className="h-auto text-2xl" aria-label="heading" />);+ const el = screen.getByLabelText('heading');+ expect(el).toHaveClass('h-auto', 'text-2xl');+ expect(el).not.toHaveClass('h-8');+ expect(el).not.toHaveClass('text-sm');});- it('adds monospace presentation only when requested', () => {- const { rerender } = render(<Input aria-label="Token" monospace />);- expect(screen.getByRole('textbox', { name: 'Token' })).toHaveClass('font-mono');-- rerender(<Input aria-label="Token" />);- expect(screen.getByRole('textbox', { name: 'Token' })).not.toHaveClass('font-mono');+ it('keeps the defaults a caller does not override', () => {+ render(<Input inputSize="sm" className="px-2" aria-label="field" />);+ const el = screen.getByLabelText('field');+ expect(el).toHaveClass('h-8', 'text-sm', 'rounded-md', 'w-full', 'border');});- it('retains the configured input size', () => {- render(<Input aria-label="Large input" inputSize="lg" />);- expect(screen.getByRole('textbox', { name: 'Large input' })).toHaveClass('h-11');+ it('still applies the invalid ring and monospace flags', () => {+ render(<Input invalid monospace aria-label="bad" />);+ const el = screen.getByLabelText('bad');+ expect(el).toHaveClass('font-mono', 'border-coral-400');+ expect(el).toHaveAttribute('aria-invalid', 'true');});});