MCPcopy
hub / github.com/cli/cli / TestSurveyPrompter

Function TestSurveyPrompter

internal/prompter/accessible_prompter_test.go:812–837  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

810}
811
812func TestSurveyPrompter(t *testing.T) {
813 // This not a comprehensive test of the survey prompter, but it does
814 // demonstrate that the survey prompter is used when the
815 // accessible prompter is disabled.
816 t.Run("Select uses survey prompter when accessible prompter is disabled", func(t *testing.T) {
817 console := newTestVirtualTerminal(t)
818 p := newTestSurveyPrompter(t, console)
819
820 go func() {
821 // Wait for prompt to appear
822 _, err := console.ExpectString("Select a number")
823 require.NoError(t, err)
824
825 // Send a newline to select the first option
826 // Note: This would not work with the accessible prompter
827 // because it would requires sending a 1 to select the first option.
828 // So it proves we are seeing a survey prompter.
829 _, err = console.SendLine("")
830 require.NoError(t, err)
831 }()
832
833 selectValue, err := p.Select("Select a number", "", []string{"1", "2", "3"})
834 require.NoError(t, err)
835 assert.Equal(t, 0, selectValue)
836 })
837}
838
839func newTestVirtualTerminal(t *testing.T) *expect.Console {
840 t.Helper()

Callers

nothing calls this directly

Calls 5

newTestSurveyPrompterFunction · 0.85
EqualMethod · 0.80
newTestVirtualTerminalFunction · 0.70
RunMethod · 0.65
SelectMethod · 0.65

Tested by

no test coverage detected