diff --git a/packages/jsx/src/components/option.ts b/packages/jsx/src/components/option.ts index 70a56aa..a49b839 100644 --- a/packages/jsx/src/components/option.ts +++ b/packages/jsx/src/components/option.ts @@ -1,31 +1,32 @@ -import { type Option, isCancel } from '@clack/prompts'; +import { type Option as PromptOption, isCancel } from '@clack/prompts'; import type { JSX } from '../types.js'; import { resolveChildren } from '../utils.js'; -export interface OptionProps { - value: unknown; +export interface OptionProps { + value: T; + hint?: string; children?: JSX.Element | JSX.Element[] | string; } -export async function Option(props: OptionProps): Promise> { - let label = ''; - if (props.children) { - const children = await resolveChildren(props.children); +export async function Option(props: OptionProps): Promise> { + const { children, ...opts } = props; + + if (children) { + const resolvedChildren = await resolveChildren(children); const childStrings: string[] = []; - for (const child of children) { + for (const child of resolvedChildren) { if (isCancel(child)) { continue; } childStrings.push(String(child)); } - label = childStrings.join('\n'); - } else { - label = String(props.value); + return { + ...opts, + label: childStrings.join('\n'), + } as PromptOption; } - return { - value: props.value, - label, - }; + + return opts as PromptOption; } diff --git a/packages/jsx/src/components/select.ts b/packages/jsx/src/components/select.ts index 573f158..08c2c10 100644 --- a/packages/jsx/src/components/select.ts +++ b/packages/jsx/src/components/select.ts @@ -4,17 +4,11 @@ import type { JSX } from '../types.js'; import { resolveChildren } from '../utils.js'; export interface SelectProps extends Omit, 'options'> { - children: JSX.Element[] | JSX.Element; + children: JSX.Element[] | JSX.Element | string; } const isOptionLike = (obj: unknown): obj is Option => { - return ( - obj !== null && - typeof obj === 'object' && - Object.hasOwnProperty.call(obj, 'label') && - Object.hasOwnProperty.call(obj, 'value') && - typeof (obj as { label: string }).label === 'string' - ); + return obj !== null && typeof obj === 'object' && Object.hasOwnProperty.call(obj, 'value'); }; export async function Select(props: SelectProps): ReturnType { diff --git a/packages/jsx/src/types.ts b/packages/jsx/src/types.ts index 039efb0..70519da 100644 --- a/packages/jsx/src/types.ts +++ b/packages/jsx/src/types.ts @@ -1,5 +1,5 @@ namespace JSX { - export type IntrinsicElements = {}; + export type IntrinsicElements = never; export type Element = Promise; } diff --git a/packages/jsx/test/__snapshots__/jsx.test.tsx.snap b/packages/jsx/test/__snapshots__/jsx.test.tsx.snap deleted file mode 100644 index ca3ee16..0000000 --- a/packages/jsx/test/__snapshots__/jsx.test.tsx.snap +++ /dev/null @@ -1,302 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`jsx > Confirm > can set active text 1`] = ` -[ - "", - "โ”‚ -โ—† foo? -โ”‚ โ— DO IT / โ—‹ No -โ”” -", - "", - "", - "", - "โ—‡ foo? -โ”‚ DO IT", - " -", - "", -] -`; - -exports[`jsx > Confirm > can set inactive text 1`] = ` -[ - "", - "โ”‚ -โ—† foo? -โ”‚ โ— Yes / โ—‹ DONT DO IT -โ”” -", - "", - "", - "", - "โ—‡ foo? -โ”‚ Yes", - " -", - "", -] -`; - -exports[`jsx > Confirm > can set message 1`] = ` -[ - "", - "โ”‚ -โ—† foo? -โ”‚ โ— Yes / โ—‹ No -โ”” -", - "", - "", - "", - "โ—‡ foo? -โ”‚ Yes", - " -", - "", -] -`; - -exports[`jsx > Note > can render children as message 1`] = ` -[ - "โ”‚ -โ—‡  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ -โ”‚ โ”‚ -โ”‚ a message โ”‚ -โ”‚ โ”‚ -โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ -", -] -`; - -exports[`jsx > Note > can render complex results as message 1`] = ` -[ - "", - "โ”‚ -โ—† say yes -โ”‚ โ— Yes / โ—‹ No -โ”” -", - "", - "", - "", - "โ—‡ say yes -โ”‚ Yes", - " -", - "", - "โ”‚ -โ—‡  โ”€โ”€โ”€โ”€โ”€โ•ฎ -โ”‚ โ”‚ -โ”‚ true โ”‚ -โ”‚ โ”‚ -โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ -", -] -`; - -exports[`jsx > Note > can render multiple children as message 1`] = ` -[ - "", - "โ”‚ -โ—† say yes -โ”‚ โ— Yes / โ—‹ No -โ”” -", - "", - "โ”‚ -โ—† say yes again -โ”‚ โ— Yes / โ—‹ No -โ”” -", - "", - "", - "", - "โ—‡ say yes -โ”‚ Yes", - " -", - "", - "", - "", - "", - "โ—‡ say yes again -โ”‚ Yes", - " -", - "", - "โ”‚ -โ—‡  โ”€โ”€โ”€โ”€โ”€โ•ฎ -โ”‚ โ”‚ -โ”‚ true โ”‚ -โ”‚ true โ”‚ -โ”‚ โ”‚ -โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ -", -] -`; - -exports[`jsx > Note > can render string message 1`] = ` -[ - "โ”‚ -โ—‡  โ”€โ”€โ”€โ”€โ•ฎ -โ”‚ โ”‚ -โ”‚ foo โ”‚ -โ”‚ โ”‚ -โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ -", -] -`; - -exports[`jsx > Password > can set custom mask 1`] = ` -[ - "", - "โ”‚ -โ—† foo -โ”‚ _ -โ”” -", - "", - "", - "", - "โ”‚ !_", - "", - "", - "", - "", - "โ”‚ !!_", - "", - "", - "", - "", - "โ—‡ foo -โ”‚ !!", - " -", - "", -] -`; - -exports[`jsx > Password > renders password input 1`] = ` -[ - "", - "โ”‚ -โ—† foo -โ”‚ _ -โ”” -", - "", - "", - "", - "โ—‡ foo -โ”‚", - " -", - "", -] -`; - -exports[`jsx > Password > renders user input 1`] = ` -[ - "", - "โ”‚ -โ—† foo -โ”‚ _ -โ”” -", - "", - "", - "", - "โ”‚ โ–ช_", - "", - "", - "", - "", - "โ”‚ โ–ชโ–ช_", - "", - "", - "", - "", - "โ—‡ foo -โ”‚ โ–ชโ–ช", - " -", - "", -] -`; - -exports[`jsx > Text > can set default value 1`] = ` -[ - "", - "โ”‚ -โ—† foo -โ”‚ _ -โ”” -", - "", - "", - "", - "โ—‡ foo -โ”‚ bar", - " -", - "", -] -`; - -exports[`jsx > Text > can set initial value 1`] = ` -[ - "", - "โ”‚ -โ—† foo -โ”‚ barโ–ˆ -โ”” -", - "", - "", - "", - "โ—‡ foo -โ”‚ bar", - " -", - "", -] -`; - -exports[`jsx > Text > can set placeholder 1`] = ` -[ - "", - "โ”‚ -โ—† foo -โ”‚ bar -โ”” -", - "", - "", - "", - "โ—‡ foo -โ”‚", - " -", - "", -] -`; - -exports[`jsx > Text > renders text input 1`] = ` -[ - "", - "โ”‚ -โ—† foo -โ”‚ _ -โ”” -", - "", - "", - "", - "โ—‡ foo -โ”‚", - " -", - "", -] -`; diff --git a/packages/jsx/test/components/__snapshots__/confirm.test.tsx.snap b/packages/jsx/test/components/__snapshots__/confirm.test.tsx.snap new file mode 100644 index 0000000..896f4a7 --- /dev/null +++ b/packages/jsx/test/components/__snapshots__/confirm.test.tsx.snap @@ -0,0 +1,58 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`Confirm > can set active text 1`] = ` +[ + "", + "โ”‚ +โ—† foo? +โ”‚ โ— DO IT / โ—‹ No +โ”” +", + "", + "", + "", + "โ—‡ foo? +โ”‚ DO IT", + " +", + "", +] +`; + +exports[`Confirm > can set inactive text 1`] = ` +[ + "", + "โ”‚ +โ—† foo? +โ”‚ โ— Yes / โ—‹ DONT DO IT +โ”” +", + "", + "", + "", + "โ—‡ foo? +โ”‚ Yes", + " +", + "", +] +`; + +exports[`Confirm > can set message 1`] = ` +[ + "", + "โ”‚ +โ—† foo? +โ”‚ โ— Yes / โ—‹ No +โ”” +", + "", + "", + "", + "โ—‡ foo? +โ”‚ Yes", + " +", + "", +] +`; diff --git a/packages/jsx/test/components/__snapshots__/note.test.tsx.snap b/packages/jsx/test/components/__snapshots__/note.test.tsx.snap new file mode 100644 index 0000000..e67dcbb --- /dev/null +++ b/packages/jsx/test/components/__snapshots__/note.test.tsx.snap @@ -0,0 +1,92 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`Note > can render children as message 1`] = ` +[ + "โ”‚ +โ—‡  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ +โ”‚ โ”‚ +โ”‚ a message โ”‚ +โ”‚ โ”‚ +โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ +", +] +`; + +exports[`Note > can render complex results as message 1`] = ` +[ + "", + "โ”‚ +โ—† say yes +โ”‚ โ— Yes / โ—‹ No +โ”” +", + "", + "", + "", + "โ—‡ say yes +โ”‚ Yes", + " +", + "", + "โ”‚ +โ—‡  โ”€โ”€โ”€โ”€โ”€โ•ฎ +โ”‚ โ”‚ +โ”‚ true โ”‚ +โ”‚ โ”‚ +โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ +", +] +`; + +exports[`Note > can render multiple children as message 1`] = ` +[ + "", + "โ”‚ +โ—† say yes +โ”‚ โ— Yes / โ—‹ No +โ”” +", + "", + "โ”‚ +โ—† say yes again +โ”‚ โ— Yes / โ—‹ No +โ”” +", + "", + "", + "", + "โ—‡ say yes +โ”‚ Yes", + " +", + "", + "", + "", + "", + "โ—‡ say yes again +โ”‚ Yes", + " +", + "", + "โ”‚ +โ—‡  โ”€โ”€โ”€โ”€โ”€โ•ฎ +โ”‚ โ”‚ +โ”‚ true โ”‚ +โ”‚ true โ”‚ +โ”‚ โ”‚ +โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ +", +] +`; + +exports[`Note > can render string message 1`] = ` +[ + "โ”‚ +โ—‡  โ”€โ”€โ”€โ”€โ•ฎ +โ”‚ โ”‚ +โ”‚ foo โ”‚ +โ”‚ โ”‚ +โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ +", +] +`; diff --git a/packages/jsx/test/components/__snapshots__/password.test.tsx.snap b/packages/jsx/test/components/__snapshots__/password.test.tsx.snap new file mode 100644 index 0000000..ca36fd8 --- /dev/null +++ b/packages/jsx/test/components/__snapshots__/password.test.tsx.snap @@ -0,0 +1,78 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`Password > can set custom mask 1`] = ` +[ + "", + "โ”‚ +โ—† foo +โ”‚ _ +โ”” +", + "", + "", + "", + "โ”‚ !_", + "", + "", + "", + "", + "โ”‚ !!_", + "", + "", + "", + "", + "โ—‡ foo +โ”‚ !!", + " +", + "", +] +`; + +exports[`Password > renders password input 1`] = ` +[ + "", + "โ”‚ +โ—† foo +โ”‚ _ +โ”” +", + "", + "", + "", + "โ—‡ foo +โ”‚", + " +", + "", +] +`; + +exports[`Password > renders user input 1`] = ` +[ + "", + "โ”‚ +โ—† foo +โ”‚ _ +โ”” +", + "", + "", + "", + "โ”‚ โ–ช_", + "", + "", + "", + "", + "โ”‚ โ–ชโ–ช_", + "", + "", + "", + "", + "โ—‡ foo +โ”‚ โ–ชโ–ช", + " +", + "", +] +`; diff --git a/packages/jsx/test/components/__snapshots__/select.test.tsx.snap b/packages/jsx/test/components/__snapshots__/select.test.tsx.snap new file mode 100644 index 0000000..f5e77f7 --- /dev/null +++ b/packages/jsx/test/components/__snapshots__/select.test.tsx.snap @@ -0,0 +1,61 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`Select > renders options 1`] = ` +[ + "", + "โ”‚ +โ—† foo +โ”‚ โ— opt0 +โ”‚ โ—‹ opt1 +โ”” +", + "", + "", + "", + "โ—‡ foo +โ”‚ opt0", + " +", + "", +] +`; + +exports[`Select > renders options with hints 1`] = ` +[ + "", + "โ”‚ +โ—† foo +โ”‚ โ— Three o three (hint one) +โ”‚ โ—‹ Eight o eight +โ”” +", + "", + "", + "", + "โ—‡ foo +โ”‚ Three o three", + " +", + "", +] +`; + +exports[`Select > renders options with labels 1`] = ` +[ + "", + "โ”‚ +โ—† foo +โ”‚ โ— Three o three +โ”‚ โ—‹ Eight o eight +โ”” +", + "", + "", + "", + "โ—‡ foo +โ”‚ Three o three", + " +", + "", +] +`; diff --git a/packages/jsx/test/components/__snapshots__/text.test.tsx.snap b/packages/jsx/test/components/__snapshots__/text.test.tsx.snap new file mode 100644 index 0000000..72a9ace --- /dev/null +++ b/packages/jsx/test/components/__snapshots__/text.test.tsx.snap @@ -0,0 +1,77 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`Text > can set default value 1`] = ` +[ + "", + "โ”‚ +โ—† foo +โ”‚ _ +โ”” +", + "", + "", + "", + "โ—‡ foo +โ”‚ bar", + " +", + "", +] +`; + +exports[`Text > can set initial value 1`] = ` +[ + "", + "โ”‚ +โ—† foo +โ”‚ barโ–ˆ +โ”” +", + "", + "", + "", + "โ—‡ foo +โ”‚ bar", + " +", + "", +] +`; + +exports[`Text > can set placeholder 1`] = ` +[ + "", + "โ”‚ +โ—† foo +โ”‚ bar +โ”” +", + "", + "", + "", + "โ—‡ foo +โ”‚", + " +", + "", +] +`; + +exports[`Text > renders text input 1`] = ` +[ + "", + "โ”‚ +โ—† foo +โ”‚ _ +โ”” +", + "", + "", + "", + "โ—‡ foo +โ”‚", + " +", + "", +] +`; diff --git a/packages/jsx/test/components/confirm.test.tsx b/packages/jsx/test/components/confirm.test.tsx new file mode 100644 index 0000000..2485b1b --- /dev/null +++ b/packages/jsx/test/components/confirm.test.tsx @@ -0,0 +1,37 @@ +import { MockReadable, MockWritable } from '@clack/test-utils'; +import { beforeEach, describe, expect, test } from 'vitest'; +import { Confirm } from '../../src/index.js'; + +describe('Confirm', () => { + let input: MockReadable; + let output: MockWritable; + + beforeEach(() => { + input = new MockReadable(); + output = new MockWritable(); + }); + + test('can set message', async () => { + const task = ; + input.emit('keypress', '', { name: 'return' }); + const result = await task; + expect(result).to.equal(true); + expect(output.buffer).toMatchSnapshot(); + }); + + test('can set active text', async () => { + const task = ; + input.emit('keypress', '', { name: 'return' }); + const result = await task; + expect(result).to.equal(true); + expect(output.buffer).toMatchSnapshot(); + }); + + test('can set inactive text', async () => { + const task = ; + input.emit('keypress', '', { name: 'return' }); + const result = await task; + expect(result).to.equal(true); + expect(output.buffer).toMatchSnapshot(); + }); +}); diff --git a/packages/jsx/test/components/note.test.tsx b/packages/jsx/test/components/note.test.tsx new file mode 100644 index 0000000..9c5ba72 --- /dev/null +++ b/packages/jsx/test/components/note.test.tsx @@ -0,0 +1,53 @@ +import { MockReadable, MockWritable } from '@clack/test-utils'; +import { beforeEach, describe, expect, test } from 'vitest'; +import { Confirm, Note } from '../../src/index.js'; + +describe('Note', () => { + let input: MockReadable; + let output: MockWritable; + + beforeEach(() => { + input = new MockReadable(); + output = new MockWritable(); + }); + + test('can render string message', async () => { + const task = ; + await task; + + expect(output.buffer).toMatchSnapshot(); + }); + + test('can render children as message', async () => { + const task = a message; + await task; + + expect(output.buffer).toMatchSnapshot(); + }); + + test('can render complex results as message', async () => { + const task = ( + + + + ); + input.emit('keypress', '', { name: 'return' }); + await task; + + expect(output.buffer).toMatchSnapshot(); + }); + + test('can render multiple children as message', async () => { + const task = ( + + + + + ); + input.emit('keypress', '', { name: 'return' }); + input.emit('keypress', '', { name: 'return' }); + await task; + + expect(output.buffer).toMatchSnapshot(); + }); +}); diff --git a/packages/jsx/test/components/password.test.tsx b/packages/jsx/test/components/password.test.tsx new file mode 100644 index 0000000..745b3c4 --- /dev/null +++ b/packages/jsx/test/components/password.test.tsx @@ -0,0 +1,50 @@ +import { MockReadable, MockWritable } from '@clack/test-utils'; +import { beforeEach, describe, expect, test } from 'vitest'; +import { Password } from '../../src/index.js'; + +describe('Password', () => { + let input: MockReadable; + let output: MockWritable; + + beforeEach(() => { + input = new MockReadable(); + output = new MockWritable(); + }); + + test('renders password input', async () => { + const task = ; + + input.emit('keypress', '', { name: 'return' }); + + const result = await task; + + expect(result).to.equal(undefined); + expect(output.buffer).toMatchSnapshot(); + }); + + test('renders user input', async () => { + const task = ; + + input.emit('keypress', 'a', { name: 'a' }); + input.emit('keypress', 'b', { name: 'b' }); + input.emit('keypress', '', { name: 'return' }); + + const result = await task; + + expect(result).to.equal('ab'); + expect(output.buffer).toMatchSnapshot(); + }); + + test('can set custom mask', async () => { + const task = ; + + input.emit('keypress', 'a', { name: 'a' }); + input.emit('keypress', 'b', { name: 'b' }); + input.emit('keypress', '', { name: 'return' }); + + const result = await task; + + expect(result).to.equal('ab'); + expect(output.buffer).toMatchSnapshot(); + }); +}); diff --git a/packages/jsx/test/components/select.test.tsx b/packages/jsx/test/components/select.test.tsx new file mode 100644 index 0000000..d8457ca --- /dev/null +++ b/packages/jsx/test/components/select.test.tsx @@ -0,0 +1,74 @@ +import { MockReadable, MockWritable } from '@clack/test-utils'; +import { beforeEach, describe, expect, test } from 'vitest'; +import { Option, Select } from '../../src/index.js'; + +describe('Select', () => { + let input: MockReadable; + let output: MockWritable; + + beforeEach(() => { + input = new MockReadable(); + output = new MockWritable(); + }); + + test('renders options', async () => { + const task = ( + + ); + + // wait a tick... sad times + await new Promise((res) => setTimeout(res, 0)); + + input.emit('keypress', '', { name: 'return' }); + + const result = await task; + + expect(result).to.equal('opt0'); + expect(output.buffer).toMatchSnapshot(); + }); + + test('renders options with labels', async () => { + const task = ( + + ); + + // wait a tick... sad times + await new Promise((res) => setTimeout(res, 0)); + + input.emit('keypress', '', { name: 'return' }); + + const result = await task; + + expect(result).to.equal(303); + expect(output.buffer).toMatchSnapshot(); + }); + + test('renders options with hints', async () => { + const task = ( + + ); + + // wait a tick... sad times + await new Promise((res) => setTimeout(res, 0)); + + input.emit('keypress', '', { name: 'return' }); + + const result = await task; + + expect(result).to.equal(303); + expect(output.buffer).toMatchSnapshot(); + }); +}); diff --git a/packages/jsx/test/components/text.test.tsx b/packages/jsx/test/components/text.test.tsx new file mode 100644 index 0000000..dd5e29d --- /dev/null +++ b/packages/jsx/test/components/text.test.tsx @@ -0,0 +1,57 @@ +import { MockReadable, MockWritable } from '@clack/test-utils'; +import { beforeEach, describe, expect, test } from 'vitest'; +import { Text } from '../../src/index.js'; + +describe('Text', () => { + let input: MockReadable; + let output: MockWritable; + + beforeEach(() => { + input = new MockReadable(); + output = new MockWritable(); + }); + + test('renders text input', async () => { + const task = ; + + input.emit('keypress', '', { name: 'return' }); + + const result = await task; + + expect(result).to.equal(''); + expect(output.buffer).toMatchSnapshot(); + }); + + test('can set placeholder', async () => { + const task = ; + + input.emit('keypress', '', { name: 'return' }); + + const result = await task; + + expect(result).to.equal(''); + expect(output.buffer).toMatchSnapshot(); + }); + + test('can set default value', async () => { + const task = ; + + input.emit('keypress', '', { name: 'return' }); + + const result = await task; + + expect(result).to.equal('bar'); + expect(output.buffer).toMatchSnapshot(); + }); + + test('can set initial value', async () => { + const task = ; + + input.emit('keypress', '', { name: 'return' }); + + const result = await task; + + expect(result).to.equal('bar'); + expect(output.buffer).toMatchSnapshot(); + }); +}); diff --git a/packages/jsx/test/jsx.test.tsx b/packages/jsx/test/jsx.test.tsx index d7cab1e..87625e5 100644 --- a/packages/jsx/test/jsx.test.tsx +++ b/packages/jsx/test/jsx.test.tsx @@ -1,6 +1,6 @@ import { MockReadable, MockWritable } from '@clack/test-utils'; import { beforeEach, describe, expect, test } from 'vitest'; -import { Confirm, Note, Option, Password, Select, Text, jsx } from '../src/index.js'; +import { Confirm, jsx } from '../src/index.js'; describe('jsx', () => { let input: MockReadable; @@ -34,175 +34,4 @@ describe('jsx', () => { const result = await task; expect(result).to.equal(null); }); - - describe('Confirm', () => { - test('can set message', async () => { - const task = ; - input.emit('keypress', '', { name: 'return' }); - const result = await task; - expect(result).to.equal(true); - expect(output.buffer).toMatchSnapshot(); - }); - - test('can set active text', async () => { - const task = ; - input.emit('keypress', '', { name: 'return' }); - const result = await task; - expect(result).to.equal(true); - expect(output.buffer).toMatchSnapshot(); - }); - - test('can set inactive text', async () => { - const task = ; - input.emit('keypress', '', { name: 'return' }); - const result = await task; - expect(result).to.equal(true); - expect(output.buffer).toMatchSnapshot(); - }); - }); - - describe('Note', () => { - test('can render string message', async () => { - const task = ; - await task; - - expect(output.buffer).toMatchSnapshot(); - }); - - test('can render children as message', async () => { - const task = a message; - await task; - - expect(output.buffer).toMatchSnapshot(); - }); - - test('can render complex results as message', async () => { - const task = ( - - - - ); - input.emit('keypress', '', { name: 'return' }); - await task; - - expect(output.buffer).toMatchSnapshot(); - }); - - test('can render multiple children as message', async () => { - const task = ( - - - - - ); - input.emit('keypress', '', { name: 'return' }); - input.emit('keypress', '', { name: 'return' }); - await task; - - expect(output.buffer).toMatchSnapshot(); - }); - }); - - describe('Text', () => { - test('renders text input', async () => { - const task = ; - - input.emit('keypress', '', { name: 'return' }); - - const result = await task; - - expect(result).to.equal(''); - expect(output.buffer).toMatchSnapshot(); - }); - - test('can set placeholder', async () => { - const task = ; - - input.emit('keypress', '', { name: 'return' }); - - const result = await task; - - expect(result).to.equal(''); - expect(output.buffer).toMatchSnapshot(); - }); - - test('can set default value', async () => { - const task = ; - - input.emit('keypress', '', { name: 'return' }); - - const result = await task; - - expect(result).to.equal('bar'); - expect(output.buffer).toMatchSnapshot(); - }); - - test('can set initial value', async () => { - const task = ; - - input.emit('keypress', '', { name: 'return' }); - - const result = await task; - - expect(result).to.equal('bar'); - expect(output.buffer).toMatchSnapshot(); - }); - }); - - describe('Password', () => { - test('renders password input', async () => { - const task = ; - - input.emit('keypress', '', { name: 'return' }); - - const result = await task; - - expect(result).to.equal(undefined); - expect(output.buffer).toMatchSnapshot(); - }); - - test('renders user input', async () => { - const task = ; - - input.emit('keypress', 'a', { name: 'a' }); - input.emit('keypress', 'b', { name: 'b' }); - input.emit('keypress', '', { name: 'return' }); - - const result = await task; - - expect(result).to.equal('ab'); - expect(output.buffer).toMatchSnapshot(); - }); - - test('can set custom mask', async () => { - const task = ; - - input.emit('keypress', 'a', { name: 'a' }); - input.emit('keypress', 'b', { name: 'b' }); - input.emit('keypress', '', { name: 'return' }); - - const result = await task; - - expect(result).to.equal('ab'); - expect(output.buffer).toMatchSnapshot(); - }); - }); - - describe('Select', () => { - test('renders options', async () => { - const task = ( - - ); - - input.emit('keypress', '', { name: 'return' }); - - const result = await task; - - expect(result).to.equal(303); - expect(output.buffer).toMatchSnapshot(); - }); - }); });