|
| 1 | +import { WizardMultiSelect, WizardSelect } from '../WizardSelect.js'; |
| 2 | +import { render } from 'ink-testing-library'; |
| 3 | +import React from 'react'; |
| 4 | +import { describe, expect, it } from 'vitest'; |
| 5 | + |
| 6 | +describe('WizardSelect', () => { |
| 7 | + const items = [ |
| 8 | + { id: 'strands', title: 'Strands', description: 'AWS Strands SDK' }, |
| 9 | + { id: 'langchain', title: 'LangChain' }, |
| 10 | + ]; |
| 11 | + |
| 12 | + it('renders title and items', () => { |
| 13 | + const { lastFrame } = render(<WizardSelect title="Select SDK" items={items} selectedIndex={0} />); |
| 14 | + |
| 15 | + expect(lastFrame()).toContain('Select SDK'); |
| 16 | + expect(lastFrame()).toContain('Strands'); |
| 17 | + expect(lastFrame()).toContain('LangChain'); |
| 18 | + }); |
| 19 | + |
| 20 | + it('renders description when provided', () => { |
| 21 | + const { lastFrame } = render( |
| 22 | + <WizardSelect title="Pick one" description="Choose your framework" items={items} selectedIndex={0} /> |
| 23 | + ); |
| 24 | + |
| 25 | + expect(lastFrame()).toContain('Choose your framework'); |
| 26 | + }); |
| 27 | + |
| 28 | + it('does not render description when not provided', () => { |
| 29 | + const { lastFrame } = render(<WizardSelect title="Pick one" items={items} selectedIndex={0} />); |
| 30 | + |
| 31 | + expect(lastFrame()).toContain('Pick one'); |
| 32 | + expect(lastFrame()).toContain('Strands'); |
| 33 | + }); |
| 34 | + |
| 35 | + it('passes empty message to SelectList', () => { |
| 36 | + const { lastFrame } = render(<WizardSelect title="Pick one" items={[]} selectedIndex={0} emptyMessage="No SDKs" />); |
| 37 | + |
| 38 | + expect(lastFrame()).toContain('No SDKs'); |
| 39 | + }); |
| 40 | +}); |
| 41 | + |
| 42 | +describe('WizardMultiSelect', () => { |
| 43 | + const items = [ |
| 44 | + { id: 'agent-1', title: 'Agent A' }, |
| 45 | + { id: 'agent-2', title: 'Agent B' }, |
| 46 | + ]; |
| 47 | + |
| 48 | + it('renders title and items', () => { |
| 49 | + const { lastFrame } = render( |
| 50 | + <WizardMultiSelect title="Select agents" items={items} cursorIndex={0} selectedIds={new Set()} /> |
| 51 | + ); |
| 52 | + |
| 53 | + expect(lastFrame()).toContain('Select agents'); |
| 54 | + expect(lastFrame()).toContain('Agent A'); |
| 55 | + expect(lastFrame()).toContain('Agent B'); |
| 56 | + }); |
| 57 | + |
| 58 | + it('renders description when provided', () => { |
| 59 | + const { lastFrame } = render( |
| 60 | + <WizardMultiSelect |
| 61 | + title="Agents" |
| 62 | + description="Select which agents" |
| 63 | + items={items} |
| 64 | + cursorIndex={0} |
| 65 | + selectedIds={new Set()} |
| 66 | + /> |
| 67 | + ); |
| 68 | + |
| 69 | + expect(lastFrame()).toContain('Select which agents'); |
| 70 | + }); |
| 71 | + |
| 72 | + it('shows checked items', () => { |
| 73 | + const { lastFrame } = render( |
| 74 | + <WizardMultiSelect title="Agents" items={items} cursorIndex={0} selectedIds={new Set(['agent-1'])} /> |
| 75 | + ); |
| 76 | + |
| 77 | + expect(lastFrame()).toContain('[✓]'); |
| 78 | + }); |
| 79 | + |
| 80 | + it('passes empty message', () => { |
| 81 | + const { lastFrame } = render( |
| 82 | + <WizardMultiSelect title="Agents" items={[]} cursorIndex={0} selectedIds={new Set()} emptyMessage="No agents" /> |
| 83 | + ); |
| 84 | + |
| 85 | + expect(lastFrame()).toContain('No agents'); |
| 86 | + }); |
| 87 | +}); |
0 commit comments