(t *testing.T)
| 810 | } |
| 811 | |
| 812 | func 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 | |
| 839 | func newTestVirtualTerminal(t *testing.T) *expect.Console { |
| 840 | t.Helper() |
nothing calls this directly
no test coverage detected