update some deisng parameters and add new cases
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "stringio"
|
||||
require_relative "test_helper"
|
||||
|
||||
class CLITest < Minitest::Test
|
||||
def test_main_prompt_is_not_an_extra_choice
|
||||
output = StringIO.new
|
||||
cli = FeatherCaseWizard::CLI.new(ui: HighLine.new(StringIO.new("4\n"), output))
|
||||
|
||||
assert_equal 0, cli.run
|
||||
assert_includes output.string, "What would you like to do:\n"
|
||||
assert_includes output.string, "4. Exit\n"
|
||||
refute_includes output.string, "5. What would you like to do?"
|
||||
end
|
||||
end
|
||||
+94
-1
@@ -9,11 +9,77 @@ class ConfigTest < Minitest::Test
|
||||
|
||||
def test_default_case_has_expected_parts_and_dimensions
|
||||
assert_equal %w[body lid], config.printable_parts
|
||||
assert_in_delta 60.8, config.dimensions["length"], 0.01
|
||||
assert_in_delta 61.6, config.dimensions["length"], 0.01
|
||||
assert_in_delta 41.66, config.dimensions["width"], 0.01
|
||||
assert_in_delta 12.25, config.parameters["wing_pitch"], 0.001
|
||||
assert_in_delta 6.0, config.parameters["gps_antenna_height"], 0.001
|
||||
assert_in_delta 2.4, config.parameters["oled_component_height"], 0.001
|
||||
assert_in_delta 1.5, config.parameters["oled_display_height"], 0.001
|
||||
assert_in_delta 2.0, config.parameters["usb_board_wall_gap"], 0.001
|
||||
assert config.parameters["usb_opening_enabled"]
|
||||
assert config.parameters["usb_guide_enabled"]
|
||||
assert_equal ["3mf"], config.outputs["formats"]
|
||||
end
|
||||
|
||||
def test_gps_height_uses_stack_pitch_antenna_height_and_top_gap
|
||||
subject = config
|
||||
subject.parameters["top_profile"] = "gps"
|
||||
parameters = subject.parameters
|
||||
|
||||
expected_electronics_height =
|
||||
parameters["wing_pitch"] + parameters["gps_antenna_height"] +
|
||||
parameters["gps_top_gap"]
|
||||
|
||||
assert_in_delta 23.25, expected_electronics_height, 0.001
|
||||
assert_in_delta 35.85, subject.dimensions["height"] + parameters["lid_thickness"], 0.001
|
||||
end
|
||||
|
||||
def test_oled_height_uses_tallest_component_not_display_reference
|
||||
subject = config
|
||||
subject.parameters["top_profile"] = "oled128x64"
|
||||
original_height = subject.dimensions["height"]
|
||||
|
||||
subject.parameters["oled_display_height"] = 10.0
|
||||
|
||||
assert_in_delta original_height, subject.dimensions["height"], 0.001
|
||||
end
|
||||
|
||||
def test_older_config_receives_default_oled_display_height
|
||||
data = FeatherCaseWizard::Config.deep_copy(config.data)
|
||||
data["parameters"].delete("oled_display_height")
|
||||
|
||||
loaded = FeatherCaseWizard::Config.new(data)
|
||||
|
||||
assert_in_delta 1.5, loaded.parameters["oled_display_height"], 0.001
|
||||
end
|
||||
|
||||
def test_older_config_preserves_opening_without_enabling_guide
|
||||
data = FeatherCaseWizard::Config.deep_copy(config.data)
|
||||
data["parameters"].delete("usb_opening_enabled")
|
||||
data["parameters"].delete("usb_guide_enabled")
|
||||
|
||||
loaded = FeatherCaseWizard::Config.new(data)
|
||||
|
||||
assert loaded.parameters["usb_opening_enabled"]
|
||||
refute loaded.parameters["usb_guide_enabled"]
|
||||
end
|
||||
|
||||
def test_usb_guide_requires_opening
|
||||
subject = config
|
||||
subject.parameters["usb_opening_enabled"] = false
|
||||
|
||||
error = assert_raises(FeatherCaseWizard::ConfigError) { subject.validate! }
|
||||
assert_match(/guide requires/, error.message)
|
||||
end
|
||||
|
||||
def test_end_clearances_expand_case_length
|
||||
subject = config
|
||||
subject.parameters["usb_board_wall_gap"] = 20.0
|
||||
subject.parameters["board_rear_clearance"] = 20.0
|
||||
|
||||
assert_in_delta 95.6, subject.dimensions["length"], 0.01
|
||||
end
|
||||
|
||||
def test_oled_buttons_and_selected_coupons_are_printable
|
||||
subject = config
|
||||
subject.parameters["top_profile"] = "oled128x64"
|
||||
@@ -50,6 +116,33 @@ class ConfigTest < Minitest::Test
|
||||
assert_match(/floor/, error.message)
|
||||
end
|
||||
|
||||
def test_cutouts_on_same_wall_require_minimum_web
|
||||
subject = config
|
||||
first = cutout("rear", 18.0).merge("name" => "first")
|
||||
second = cutout("rear", 24.0).merge("name" => "second")
|
||||
subject.data["cutouts"] = [first, second]
|
||||
|
||||
error = assert_raises(FeatherCaseWizard::ConfigError) { subject.validate! }
|
||||
assert_match(/too close/, error.message)
|
||||
end
|
||||
|
||||
def test_front_cutout_cannot_overlap_usb_opening
|
||||
subject = config
|
||||
subject.data["cutouts"] = [
|
||||
cutout("front", subject.dimensions["width"] / 2).merge("z" => 11.0)
|
||||
]
|
||||
|
||||
error = assert_raises(FeatherCaseWizard::ConfigError) { subject.validate! }
|
||||
assert_match(/USB opening or guide/, error.message)
|
||||
end
|
||||
|
||||
def test_front_cutout_can_clear_usb_reservation
|
||||
subject = config
|
||||
subject.data["cutouts"] = [cutout("front", 10.0).merge("z" => 11.0)]
|
||||
|
||||
assert_same subject, subject.validate!
|
||||
end
|
||||
|
||||
def test_yaml_round_trip_preserves_resolved_cutouts
|
||||
subject = config
|
||||
subject.data["cutouts"] = [cutout("left", 20.0)]
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "stringio"
|
||||
require_relative "test_helper"
|
||||
|
||||
class PromptingUITest < Minitest::Test
|
||||
def test_menu_prompt_is_a_header_and_answers_are_separated
|
||||
output = StringIO.new
|
||||
ui = FeatherCaseWizard::PromptingUI.wrap(
|
||||
HighLine.new(StringIO.new("1\nDemo\n"), output)
|
||||
)
|
||||
|
||||
selected = ui.choose("Export format (current: 3mf)") do |menu|
|
||||
menu.choice("3MF") { "3mf" }
|
||||
menu.choice("STL") { "stl" }
|
||||
end
|
||||
name = ui.ask("Case name: ")
|
||||
|
||||
assert_equal "3mf", selected
|
||||
assert_equal "Demo", name
|
||||
assert_includes output.string, "Export format (current: 3mf):\n1. 3MF\n2. STL\n? \n"
|
||||
refute_includes output.string, "3. Export format"
|
||||
assert_match(/\? \nCase name: /, output.string)
|
||||
end
|
||||
|
||||
def test_wrap_is_idempotent
|
||||
ui = FeatherCaseWizard::PromptingUI.wrap(HighLine.new)
|
||||
|
||||
assert_same ui, FeatherCaseWizard::PromptingUI.wrap(ui)
|
||||
end
|
||||
end
|
||||
+53
-14
@@ -6,20 +6,8 @@ require_relative "test_helper"
|
||||
class WizardTest < Minitest::Test
|
||||
def test_minimal_new_case_flow_and_confirmation
|
||||
input = StringIO.new(
|
||||
"Demo Case\n" \
|
||||
"\n" \
|
||||
"1\n" \
|
||||
"1\n" \
|
||||
"\n" \
|
||||
"n\n" \
|
||||
"n\n" \
|
||||
"n\n" \
|
||||
"1\n" \
|
||||
"n\n" \
|
||||
"n\n" \
|
||||
"n\n" \
|
||||
"n\n" \
|
||||
"y\n"
|
||||
["Demo Case", "", "1", "1", "", "n", "n", "", "", "n", "n", "1",
|
||||
"n", "n", "n", "n", "y"].join("\n") + "\n"
|
||||
)
|
||||
output = StringIO.new
|
||||
wizard = FeatherCaseWizard::Wizard.new(ui: HighLine.new(input, output))
|
||||
@@ -31,4 +19,55 @@ class WizardTest < Minitest::Test
|
||||
assert_equal ["3mf"], config.outputs["formats"]
|
||||
assert_equal %w[body lid], config.printable_parts
|
||||
end
|
||||
|
||||
def test_edit_accepts_current_menu_choices_as_defaults
|
||||
config = FeatherCaseWizard::Config.create(name: "GPS", slug: "gps")
|
||||
config.parameters["top_profile"] = "gps"
|
||||
input = StringIO.new(
|
||||
["", "", "", "", "n", "n", "", "", "n", "n", "1", "n", "n", "n",
|
||||
"n"].join("\n") + "\n"
|
||||
)
|
||||
wizard = FeatherCaseWizard::Wizard.new(ui: HighLine.new(input, StringIO.new))
|
||||
|
||||
edited = wizard.edit(config)
|
||||
|
||||
assert_equal ["3mf"], edited.outputs["formats"]
|
||||
assert_equal "gps", edited.parameters["top_profile"]
|
||||
end
|
||||
|
||||
def test_edit_cutout_accepts_current_wall_and_shape_as_defaults
|
||||
config = FeatherCaseWizard::Config.create(name: "GPS", slug: "gps")
|
||||
cutout = {
|
||||
"name" => "cable",
|
||||
"face" => "left",
|
||||
"shape" => "roundrect",
|
||||
"horizontal" => 30.0,
|
||||
"z" => 12.0,
|
||||
"width" => 8.0,
|
||||
"height" => 6.0,
|
||||
"radius" => 1.5
|
||||
}
|
||||
output = StringIO.new
|
||||
wizard = FeatherCaseWizard::Wizard.new(ui: HighLine.new(StringIO.new("\n" * 8), output))
|
||||
|
||||
edited = wizard.send(:ask_cutout, config, cutout)
|
||||
|
||||
assert_equal "left", edited["face"]
|
||||
assert_equal "roundrect", edited["shape"]
|
||||
assert_includes output.string, "Wall:\n1. Front — USB-C short wall\n"
|
||||
assert_includes output.string, "3. Left — plain/non-JST long wall\n"
|
||||
refute_includes output.string, "5. Wall"
|
||||
end
|
||||
|
||||
def test_end_clearance_step_sets_both_board_end_distances
|
||||
config = FeatherCaseWizard::Config.create(name: "Servo", slug: "servo")
|
||||
wizard = FeatherCaseWizard::Wizard.new(
|
||||
ui: HighLine.new(StringIO.new("y\n20\n20\n"), StringIO.new)
|
||||
)
|
||||
|
||||
wizard.send(:choose_end_clearance, config)
|
||||
|
||||
assert_in_delta 20.0, config.parameters["usb_board_wall_gap"], 0.001
|
||||
assert_in_delta 20.0, config.parameters["board_rear_clearance"], 0.001
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user