spec/unit/multi_select_spec.rb in tty-prompt-0.18.0 vs spec/unit/multi_select_spec.rb in tty-prompt-0.18.1
- old
+ new
@@ -43,11 +43,11 @@
# Ensure a wide prompt on CI
before { allow(TTY::Screen).to receive(:width).and_return(200) }
it "selects nothing when return pressed immediately" do
prompt = TTY::TestPrompt.new
- choices = %w(vodka beer wine whisky bourbon)
+ choices = %i(vodka beer wine whisky bourbon)
prompt.input << "\r"
prompt.input.rewind
expect(prompt.multi_select("Select drinks?", choices)). to eq([])
expect(prompt.output.string).to eq([
"\e[?25lSelect drinks? \e[90m(Use arrow keys, press Space to select and Enter to finish)\e[0m\n",
@@ -423,16 +423,32 @@
expect(prompt.output.string).to eql(expected_prompt_output)
end
end
context "with :disabled" do
- it "fails when active item is also disabled" do
+ it "fails when default item is also disabled" do
prompt = TTY::TestPrompt.new
- choices = [{name: 'vodka', disabled: true}, 'beer', 'wine', 'whisky', 'bourbon']
+ choices = [
+ {name: 'vodka', disabled: true},
+ 'beer', 'wine', 'whisky', 'bourbon'
+ ]
expect {
- prompt.multi_select("Select drinks?", choices)
+ prompt.multi_select("Select drinks?", choices, default: 1)
}.to raise_error(TTY::Prompt::ConfigurationError,
- /active choice 'vodka' matches disabled item/)
+ /default index `1` matches disabled choice item/)
+ end
+
+ it "adjusts active index to match first non-disabled choice" do
+ choices = [
+ {name: 'vodka', disabled: true},
+ 'beer', 'wine', 'whisky', 'bourbon'
+ ]
+ prompt = TTY::TestPrompt.new
+ prompt.input << " " << "\r"
+ prompt.input.rewind
+
+ answer = prompt.multi_select("Select drinks?", choices)
+ expect(answer).to eq(['beer'])
end
it "omits disabled choice when nagivating menu" do
choices = [
{name: 'A'},