Skip to content

Commit

Permalink
Merge pull request Shopify#2101 from Shopify/fix-confirmation-prompts
Browse files Browse the repository at this point in the history
Fix confirmation prompts scrolling
  • Loading branch information
matteodepalo authored Jun 6, 2023
2 parents ce84153 + 316d488 commit 4746f68
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ vi.mock('ink', async () => {
})

const ARROW_DOWN = '\u001B[B'
const ARROW_UP = '\u001B[A'
const ENTER = '\r'

beforeEach(() => {
Expand Down Expand Up @@ -345,6 +346,46 @@ describe('SelectPrompt', async () => {
`)
})

test('allows selecting a different option after having selected an option with a falsy value', async () => {
const items = [
{label: 'yes', value: true},
{label: 'no', value: false},
]

const renderInstance = render(
<SelectPrompt
message="Associate your project with the org Castile Ventures?"
choices={items}
onSubmit={() => {}}
/>,
)

await waitForInputsToBeReady()
await sendInputAndWaitForChange(renderInstance, ARROW_DOWN)

expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`
"? Associate your project with the org Castile Ventures?
(1) yes
> (2) no
Press ↑↓ arrows to select, enter to confirm
"
`)

await sendInputAndWaitForChange(renderInstance, ARROW_UP)

expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`
"? Associate your project with the org Castile Ventures?
> (1) yes
(2) no
Press ↑↓ arrows to select, enter to confirm
"
`)
})

test('abortController can be used to exit the prompt from outside', async () => {
const items = [
{label: 'a', value: 'a'},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ interface ResetAction<T> {
const reducer = <T>(state: State<T>, action: Action<T>): State<T> => {
switch (action.type) {
case 'select-next-option': {
if (!state.value) {
if (typeof state.value === 'undefined') {
return state
}

Expand Down Expand Up @@ -142,7 +142,7 @@ const reducer = <T>(state: State<T>, action: Action<T>): State<T> => {
}

case 'select-previous-option': {
if (!state.value) {
if (typeof state.value === 'undefined') {
return state
}

Expand Down

0 comments on commit 4746f68

Please sign in to comment.