diff --git a/lib/Lacuna/RPC/Building/PlanetaryCommand.pm b/lib/Lacuna/RPC/Building/PlanetaryCommand.pm index d4e2a3d7..63ed5f93 100644 --- a/lib/Lacuna/RPC/Building/PlanetaryCommand.pm +++ b/lib/Lacuna/RPC/Building/PlanetaryCommand.pm @@ -36,6 +36,9 @@ sub view_plans { extra_build_level => $plan->extra_build_level, } } + # sort plans into a sensible order + @out = sort {$a->{name} cmp $b->{name} || $a->{level} <=> $b->{level} || $b->{extra_build_level} <=> $a->{extra_build_level} } @out; + return { status => $self->format_status($empire, $building->body), plans => \@out, diff --git a/t/bugs/0008_HighNegativeHappiness.t b/t/bugs/0008_HighNegativeHappiness.t index 78f11bdf..79adefcd 100644 --- a/t/bugs/0008_HighNegativeHappiness.t +++ b/t/bugs/0008_HighNegativeHappiness.t @@ -30,6 +30,9 @@ $home->happiness(-1000,000,000,000,000); $home->update; $home->tick; + + + END { # TestHelper->clear_all_test_empires; } diff --git a/t/bugs/0028_PlansInRandomOrder.t b/t/bugs/0028_PlansInRandomOrder.t new file mode 100644 index 00000000..3d76bb12 --- /dev/null +++ b/t/bugs/0028_PlansInRandomOrder.t @@ -0,0 +1,38 @@ +use lib '..','../../lib'; +use Test::More tests => 2; +use Test::Deep; +use 5.010; + +use strict; +use warnings; + +use TestHelper; +TestHelper->clear_all_test_empires; + +# BUG Plans are not displayed in alpha order in the Planetary Command Centre + +my $tester = TestHelper->new({ big_producer => 1 })->generate_test_empire->build_infrastructure; +my $tester_session_id = $tester->session->id; +my $empire = $tester->empire; +my $home = $empire->home_planet; + +# add an assortment of plans of different names and levels + +$home->add_plan('Lacuna::DB::Result::Building::Permanent::Ravine', 1); +$home->add_plan('Lacuna::DB::Result::Building::Permanent::Ravine', 1, 2); +$home->add_plan('Lacuna::DB::Result::Building::Permanent::Ravine', 4); +$home->add_plan('Lacuna::DB::Result::Building::Permanent::Ravine', 1); +$home->add_plan('Lacuna::DB::Result::Building::Permanent::Ravine', 3); +$home->add_plan('Lacuna::DB::Result::Building::Permanent::Ravine', 1,1); +$home->add_plan('Lacuna::DB::Result::Building::Permanent::Lake', 1); +$home->add_plan('Lacuna::DB::Result::Building::Permanent::AlgaePond', 1); + +my ($pcc) = $home->buildings->search({class => 'Lacuna::DB::Result::Building::PlanetaryCommand'}); + +$tester->post('planetarycommand', 'view_plans', [$session_id, $shipyard->id, 'dory']); + +diag($pcc->id); + +END { +# TestHelper->clear_all_test_empires; +}