Initial MoonModel implementation
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
require "stringio"
|
||||
|
||||
class WizardTest < Minitest::Test
|
||||
def test_blank_input_accepts_false_default
|
||||
answer, output = ask_yes_no("\n", false)
|
||||
|
||||
refute answer
|
||||
assert_includes output, "|no|"
|
||||
refute_includes output, 'Please enter "yes" or "no".'
|
||||
end
|
||||
|
||||
def test_blank_input_accepts_true_default
|
||||
answer, output = ask_yes_no("\n", true)
|
||||
|
||||
assert answer
|
||||
assert_includes output, "|yes|"
|
||||
refute_includes output, 'Please enter "yes" or "no".'
|
||||
end
|
||||
|
||||
def test_explicit_answers_override_defaults
|
||||
{ "yes\n" => true, "y\n" => true, "no\n" => false, "n\n" => false }.each do |input, expected|
|
||||
answer, = ask_yes_no(input, !expected)
|
||||
assert_equal expected, answer, "expected #{input.inspect} to override the default"
|
||||
end
|
||||
end
|
||||
|
||||
def test_selects_a_new_named_model
|
||||
Dir.mktmpdir do |dir|
|
||||
output = StringIO.new
|
||||
wizard = MoonModel::Wizard.new(io: HighLine.new(StringIO.new("My Moon\n"), output), output_root: dir)
|
||||
|
||||
values = wizard.send(:select_model)
|
||||
|
||||
assert_equal "My Moon", values.dig("output", "name")
|
||||
refute Dir.exist?(File.join(dir, "My_Moon"))
|
||||
end
|
||||
end
|
||||
|
||||
def test_existing_model_can_seed_revision_defaults
|
||||
Dir.mktmpdir do |dir|
|
||||
model = File.join(dir, "Saved_Moon")
|
||||
Dir.mkdir(model)
|
||||
config = MoonModel::Config.new("vertical_exaggeration" => 5, "output" => { "name" => "Saved Moon" })
|
||||
config.save(File.join(model, "config.yml"))
|
||||
File.write(File.join(model, "manifest.md"), "Generated by MoonModel test")
|
||||
output = StringIO.new
|
||||
wizard = MoonModel::Wizard.new(io: HighLine.new(StringIO.new("Saved Moon\n\n"), output), output_root: dir)
|
||||
|
||||
values = wizard.send(:select_model)
|
||||
|
||||
assert_equal 5, values["vertical_exaggeration"]
|
||||
assert_equal "Saved Moon", values.dig("output", "name")
|
||||
assert_includes output.string, "Revise the existing Saved Moon model?"
|
||||
end
|
||||
end
|
||||
|
||||
def test_warns_when_user_chooses_less_than_recommended_stand_clearance
|
||||
output = StringIO.new
|
||||
highline = HighLine.new(StringIO.new("\n\n5\n"), output)
|
||||
wizard = MoonModel::Wizard.new(io: highline)
|
||||
values = { "purpose" => "display", "assembly" => "auto" }
|
||||
|
||||
wizard.send(:purpose, values)
|
||||
|
||||
assert_equal 5.0, values.dig("stand", "base_clearance_mm")
|
||||
assert_includes output.string, "waive the recommended terrain safety margin"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ask_yes_no(input, default)
|
||||
output = StringIO.new
|
||||
highline = HighLine.new(StringIO.new(input), output)
|
||||
wizard = MoonModel::Wizard.new(io: highline)
|
||||
[wizard.send(:yes_no, "Continue?", default), output.string]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user