diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-08-22 16:27:32 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-08-31 15:37:09 +0100 |
commit | 27110ac506f071ad0c5925ef74de1321514c23c8 (patch) | |
tree | 61699c019d14a0b6abf4db20734b93f7c09d6093 /t | |
parent | b43813d8f3c5bae07f0c7b9fe120bff32611d8bb (diff) |
Remove hardcoded states from Problem model.
We keep the internal states hardcoded, plus the core open (confirmed)
and closed ones, but the remainder are moved to the database.
Diffstat (limited to 't')
-rw-r--r-- | t/app/controller/report_inspect.t | 4 | ||||
-rw-r--r-- | t/app/model/state.t | 62 |
2 files changed, 64 insertions, 2 deletions
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t index 33486aa28..687692679 100644 --- a/t/app/controller/report_inspect.t +++ b/t/app/controller/report_inspect.t @@ -57,7 +57,7 @@ FixMyStreet::override_config { }; subtest "test basic inspect submission" => sub { - $mech->submit_form_ok({ button => 'save', with_fields => { traffic_information => 'Yes', state => 'Action Scheduled', include_update => undef } }); + $mech->submit_form_ok({ button => 'save', with_fields => { traffic_information => 'Yes', state => 'Action scheduled', include_update => undef } }); $report->discard_changes; my $alert = FixMyStreet::App->model('DB::Alert')->find( { user => $user, alert_type => 'new_updates', confirmed => 1, } @@ -264,7 +264,7 @@ FixMyStreet::override_config { subtest "Oxfordshire-specific traffic management options are shown" => sub { $report->update({ state => 'confirmed' }); $mech->get_ok("/report/$report_id"); - $mech->submit_form_ok({ button => 'save', with_fields => { traffic_information => 'Signs and Cones', state => 'Action Scheduled', include_update => undef } }); + $mech->submit_form_ok({ button => 'save', with_fields => { traffic_information => 'Signs and Cones', state => 'Action scheduled', include_update => undef } }); $report->discard_changes; is $report->state, 'action scheduled', 'report state changed'; is $report->get_extra_metadata('traffic_information'), 'Signs and Cones', 'report data changed'; diff --git a/t/app/model/state.t b/t/app/model/state.t new file mode 100644 index 000000000..1653e36e2 --- /dev/null +++ b/t/app/model/state.t @@ -0,0 +1,62 @@ +use FixMyStreet::Test; +use Test::More; + +my $rs = FixMyStreet::DB->resultset('State'); +my $trans_rs = FixMyStreet::DB->resultset('Translation'); + +for ( + { label => 'in progress', lang => 'de' }, + { label => 'investigating', lang => 'fr' }, + { label => 'duplicate', lang => 'de' }, +) { + my $lang = $_->{lang}; + my $obj = $rs->find({ label => $_->{label} }); + $trans_rs->create({ tbl => 'state', col => 'name', object_id => $obj->id, + lang => $lang, msgstr => "$lang $_->{label}" }); +} + +my $states = $rs->states; +my %states = map { $_->label => $_ } @$states; + +subtest 'Open/closed database data is as expected' => sub { + my $open = $rs->open; + is @$open, 5; + my $closed = $rs->closed; + is @$closed, 5; +}; + +is $rs->display('investigating'), 'Investigating'; +is $rs->display('bad'), 'bad'; +is $rs->display('confirmed'), 'Open'; +is $rs->display('closed'), 'Closed'; +is $rs->display('fixed - council'), 'Fixed - Council'; +is $rs->display('fixed - user'), 'Fixed - User'; +is $rs->display('fixed'), 'Fixed'; + +subtest 'default name is untranslated' => sub { + is $states{'in progress'}->name, 'In progress'; + is $states{'in progress'}->msgstr, 'In progress'; + is $states{'action scheduled'}->name, 'Action scheduled'; + is $states{'action scheduled'}->msgstr, 'Action scheduled'; +}; + +subtest 'msgstr gets translated if available when the language changes' => sub { + FixMyStreet::DB->schema->lang('de'); + is $states{'in progress'}->name, 'In progress'; + is $states{'in progress'}->msgstr, 'de in progress'; + is $states{'investigating'}->name, 'Investigating'; + is $states{'investigating'}->msgstr, 'Investigating'; + is $states{'unable to fix'}->name, 'No further action'; + is $states{'unable to fix'}->msgstr, 'No further action'; +}; + +$rs->clear; + +is_deeply [ sort FixMyStreet::DB::Result::Problem->open_states ], + ['action scheduled', 'confirmed', 'in progress', 'investigating', 'planned'], 'open states okay'; +is_deeply [ sort FixMyStreet::DB::Result::Problem->closed_states ], + ['closed', 'duplicate', 'internal referral', 'not responsible', 'unable to fix'], 'closed states okay'; +is_deeply [ sort FixMyStreet::DB::Result::Problem->fixed_states ], + ['fixed', 'fixed - council', 'fixed - user'], 'fixed states okay'; + +done_testing(); |