mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
- Service worker keeps the Log Flight form when opened via Turbo, serves the offline page's script and icon, and treats 502/503/504 as offline; the offline page only links forms actually kept - Serviced sub-components restart from the airframe time flown since the entry - New logbook entries can complete inspections (recorded and linked to the entry) - Components: replacement limit can count from installation (life limit) - Component-level "Inspect every" / "Inspection critical" removed; a migration converts any unlinked settings into inspection types with a first record; component page lists its inspections Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
121 lines
6.3 KiB
Ruby
121 lines
6.3 KiB
Ruby
require "test_helper"
|
|
|
|
# The Overview's Last flight card, intervals entered as days, months or years,
|
|
# and the status report opening as its own page.
|
|
class OverviewAndIntervalsTest < ActionDispatch::IntegrationTest
|
|
setup do
|
|
@owner = create_user("owner@example.com")
|
|
@pilot = create_user("pilot@example.com")
|
|
@a = create_aircraft(owner: @owner, pilot: @pilot, tail_number: "N12345", tach_time: 1000)
|
|
@a.flight_logs.create!(date: Date.current - 20, tach_time: 1.0, departure_location: "KAAA", destination_location: "KAAA")
|
|
@a.flight_logs.create!(date: Date.current - 3, tach_time: 1.2, departure_location: "KAAA", destination_location: "KBBB")
|
|
@a.flight_logs.create!(date: Date.current - 3, tach_time: 0.9, departure_location: "KBBB", destination_location: "KAAA",
|
|
tach_in: 1000, fuel_level_after: 18, oil_level_after: 5)
|
|
@oil = create_component(@a, component_type: component_type("Oil"), manufacturer: "Phillips", model: "20W50",
|
|
replacement_hours: 50, hours_since_overhaul: 46, overhaul_date: Date.current - 30)
|
|
create_component(@a, component_type: component_type("Magneto"), manufacturer: "Bendix", model: "S4LN-21",
|
|
replacement_hours: 500, hours_since_overhaul: 100, overhaul_date: Date.current - 30)
|
|
end
|
|
|
|
test "the overview shows the last day's flying" do
|
|
sign_in @pilot
|
|
get aircraft_path(@a)
|
|
assert_response :success
|
|
body = response.body
|
|
assert_includes body, "KAAA → KBBB → KAAA"
|
|
assert_includes body, "2 legs"
|
|
assert_includes body, "18 gal"
|
|
assert_includes body, "5 qt"
|
|
end
|
|
|
|
test "the overview copes with nothing logged" do
|
|
bare = create_aircraft(owner: @owner, tail_number: "N54321")
|
|
sign_in @owner
|
|
get aircraft_path(bare)
|
|
assert_response :success
|
|
assert_includes response.body, "No flights logged yet."
|
|
end
|
|
|
|
test "hours already run out count as overdue" do
|
|
filter = create_component(@a, component_type: component_type("Oil Filter"), manufacturer: "Champion", model: "CH48110",
|
|
replacement_hours: 50, hours_since_overhaul: 60, overhaul_date: Date.current - 300)
|
|
items = DueList.new(@a).items.index_by(&:key)
|
|
assert items["replace-#{filter.id}"].overdue?
|
|
assert_equal Date.current, items["replace-#{filter.id}"].date
|
|
refute items["replace-#{@oil.id}"].overdue?
|
|
end
|
|
|
|
test "a component's page lists the inspections applied to it and offers to add one for it" do
|
|
sign_in @owner
|
|
mag = create_component(@a, component_type: component_type("Magneto"), manufacturer: "Slick", model: "4371", install_location: "Left")
|
|
get aircraft_component_path(@a, mag)
|
|
assert_select "#inspections", text: /None/
|
|
get new_aircraft_inspection_type_path(@a, component_id: mag.id)
|
|
assert_select "input[name='inspection_type[name]'][value='Magneto (Left) inspection']"
|
|
assert_select "input#comp_#{mag.id}[checked]"
|
|
assert_select "input[name=applies_to_airframe]:not([checked])"
|
|
|
|
InspectionType.create!(name: "Left magneto 500-hour", effect: "advisory", recurring: true, recurring_hours: 500).components << mag
|
|
get aircraft_component_path(@a, mag)
|
|
assert_select "#inspections td", text: /Left magneto 500-hour/
|
|
get edit_aircraft_component_path(@a, mag)
|
|
assert_select "input[name='component[inspection_hours]']", 0
|
|
end
|
|
|
|
test "a component limit in years is stored as months and lands on the same date" do
|
|
sign_in @owner
|
|
get edit_aircraft_component_path(@a, @oil)
|
|
assert_select "select[name='component[replacement_unit]'] option", text: "years"
|
|
|
|
patch aircraft_component_path(@a, @oil), params: { component: { replacement_every: "2", replacement_unit: "years",
|
|
overhaul_date: "2026-03-10" } }
|
|
@oil.reload
|
|
assert_equal [ nil, 24 ], [ @oil.replacement_days, @oil.replacement_months ]
|
|
assert_equal Date.new(2028, 3, 10), @oil.next_replacement_date
|
|
assert_equal "2 years", @oil.replacement_interval_label
|
|
|
|
get edit_aircraft_component_path(@a, @oil)
|
|
assert_select "input[name='component[replacement_every]'][value='2']"
|
|
assert_select "select[name='component[replacement_unit]'] option[selected]", text: "years"
|
|
|
|
patch aircraft_component_path(@a, @oil), params: { component: { replacement_every: "90", replacement_unit: "days" } }
|
|
assert_equal [ 90, nil ], @oil.reload.then { [ _1.replacement_days, _1.replacement_months ] }
|
|
|
|
patch aircraft_component_path(@a, @oil), params: { component: { replacement_every: "", replacement_unit: "days" } }
|
|
assert_equal [ nil, nil ], @oil.reload.then { [ _1.replacement_days, _1.replacement_months ] }
|
|
|
|
patch aircraft_component_path(@a, @oil), params: { component: { replacement_every: "1.5", replacement_unit: "months" } }
|
|
assert_response :unprocessable_entity
|
|
assert_includes response.body, "must be a whole number more than 0"
|
|
end
|
|
|
|
test "inspection types and ADs take months or years, still due at the end of the month" do
|
|
sign_in @owner
|
|
post aircraft_inspection_types_path(@a), params: { inspection_type: { name: "ELT check", effect: "grounds", recurring: "1",
|
|
recurring_hours: "0", recurring_every: "1", recurring_unit: "years" },
|
|
applies_to_airframe: "1" }
|
|
type = InspectionType.find_by!(name: "ELT check")
|
|
assert_equal [ 12, 0 ], [ type.recurring_months, type.recurring_days ]
|
|
assert_equal "Every 1 year", type.interval_description
|
|
|
|
ad = AirworthinessDirective.new(name: "2020-01-01", short_description: "Seat rails", recurring: true, recurring_every: "100", recurring_unit: "days")
|
|
ad.valid?
|
|
assert_equal [ 100, 0 ], [ ad.recurring_days, ad.recurring_months ]
|
|
assert_equal({ hours: 0.0, months: 0, days: 100 }, ad.due_rule)
|
|
ad.recurring_every = "2"
|
|
ad.recurring_unit = "years"
|
|
ad.valid?
|
|
assert_equal [ 0, 24 ], [ ad.recurring_days, ad.recurring_months ]
|
|
assert_equal "2 years", ad.recurring_interval_label
|
|
end
|
|
|
|
test "the status report always opens as a full page, without Turbo" do
|
|
sign_in @pilot
|
|
get aircraft_report_path(@a)
|
|
assert_response :success
|
|
assert_select "meta[name='turbo-visit-control'][content='reload']"
|
|
assert_select "script[type='importmap']", false
|
|
assert_select "button[data-print]"
|
|
end
|
|
end
|