# #=============================================================================== # # DESCRIPTION: rfc440L # A custom fish worklist based on test selection with a set of templates for # corresponding tests # TODO add a test for fgfr3_igh and fgfr3 to check they are not both selected # #=============================================================================== use HMDS::Perl; use Test::WWW::Mechanize::CGIApp; use Test::Most; # tests => 6; # last test to print use Data::Printer; require 't/test-lib.pl'; my $mech = get_mech(); my $cmyc_test_id; # keep track of test id so it can be removed in last test do_login(); my $dbh; lives_ok { $dbh = get_dbh() or die 'no database handle received from get_dbh'; } 'Dataase handle recieved'; #warn $@ if $@; # setup database # need requests-lab_tests to satisfy get_outstanding_nivestigations # e.g. FISH section and not complete my $dbix = get_dbix(); for my $request_id ( 1, 2 ) { for my $lab_test_id ( 1 .. 5 ) { my %args = ( request_id => $request_id, lab_test_id => $lab_test_id, user_id => 1, status_option_id => 1, ); $dbix->insert( 'request_lab_test_status', \%args ); } } my $fish_section_id; { # lab section fish my %args = ( section_name => 'FISH', has_result_summary => 'yes', has_section_notes => 'yes', has_test_sign_out => 'no', has_foreign_id => 'yes', has_results_import => 'no', has_labels => 'no', auto_expand => 'no', is_active => 'yes', ); $dbix->insert( 'lab_sections', \%args ); $fish_section_id = $dbh->last_insert_id( undef, undef, undef, undef ); } { # lab_tests #+----+-----------+-------------+----------------+-----------+-------------+-----------+ #| id | test_name | field_label | lab_section_id | test_type | has_results | is_active | #+----+-----------+-------------+----------------+-----------+-------------+-----------+ #| 1 | pnh | PNH | 1 | panel | no | yes | #+----+-----------+-------------+----------------+-----------+-------------+-----------+ #MYELOMA WORKSHEET #col#1 # cdkn2c # cks1b #col#5 # cmyc # foreach (qw/he cdkn2c cks1b cytocell_myc cytocell_cen8/) { my %args = ( test_name => $_, field_label => uc, lab_section_id => $fish_section_id, test_type => 'test', has_results => 'no', is_active => 'yes', ); $dbix->insert( 'lab_tests', \%args ); my $fish_test_id = $dbh->last_insert_id( undef, undef, undef, undef ); if ( $_ eq 'cytocell_myc' ) { $cmyc_test_id = $fish_test_id; # for later test } # request_lab_test_status fish #+----+------------+-------------+------------------+---------+---------------------+ #| id | request_id | lab_test_id | status_option_id | user_id | time | #+----+------------+-------------+------------------+---------+---------------------+ #| 1 | 1 | 1 | 1 | 1 | 2018-05-18 13:35:46 | #+----+------------+-------------+------------------+---------+---------------------+ my %status_args = ( request_id => 1, lab_test_id => $fish_test_id, status_option_id => 1, user_id => 1, # time => '2018-05-18 13:35:46', ); $dbix->insert( 'request_lab_test_status', \%status_args ); } } # test that the menu item is in local worklists section # test that selecting it returns the first page $mech->get_ok('/worklist'); # print_and_exit(); $mech->content_like( qr{Other worklists:}, 'Loaded worklists page', ); $mech->content_contains( q(fish_worksheets_custom), 'Worklists yml configured for fish_worksheets_custom', ); # test worklist displays fish custom worklist: SKIP: { skip 'Test only works on older perls' , 5 unless ($] <= 5.014001); ok $mech->form_name('others'), 'Others formname is in page'; ok $mech->select( function_name => 'fish_worksheets_custom' ), 'custom worksheet is listed'; # force error message by making it look like there are no templates in # local/fish/templates/*.tt # ok glob('/*'), 'glob doesnt returns empty list'; no warnings 'redefine'; local *CORE::GLOBAL::glob = sub { return (); }; my @testglob = glob q{/*}; is @testglob, 0, 'glob disabled for test'; $mech->get('/local_worklist?function_name=fish_worksheets_custom') ; #print_and_exit(); $mech->text_contains( q(no FISH templates are installed), 'FISH function doesnt run when there are no templates', ); } { # reset glob (out of scope) so we can check there are some templates installed ok glob(q{/*}), 'glob function reenabled'; $mech->get('/local_worklist?function_name=fish_worksheets_custom') ; # print_and_exit(); # if there are no templates then the html should explain this and then give up my @templates = glob 'templates/worklist/local/fish/templates/*'; ok( scalar @templates, 'templates available in templates/worklist/local/fish/templates' ); $mech->text_contains( q(Print FISH custom worksheets), 'FISH custom worksheet page displays', ); # get list of templates from filesystem $mech->content_contains( q(Select worksheet template), 'Template selector displayed', ); my $template_form = $mech->form_name('fish_worksheets'); my @options = $template_form->find_input('^template'); # check the template options match the directory listing # +1 because there is a dummy option '---' in select widget is( 1 + scalar @templates, scalar @{ $options[0]->{menu} }, 'all templates displayed in form' ); # loads basic template # select option # submit # non existant template (validation error handling) # $DB::single = 1; $mech->submit_form( form_name => 'fish_worksheets', fields => { template => q{doesntexist}, request_id => 1234 }, ); #print_and_exit(); $mech->content_contains( #q{template doesn't exist}, q(Print FISH custom worksheets), q{template doesn't exist so redisplay form} ); # should really use formvalidation $mech->back; $mech->submit_form( form_name => 'fish_worksheets', fields => { template => 'MYELOMA.tt', request_id => 1 } ); $mech->content_contains( 'MYELOMA Worksheet', 'template contains header text' ); # print_and_exit(); my @mark_count = $mech->content =~ /✔/gms; is( scalar @mark_count, 2, ' 2 probes ticked (✔)' ); $mech->content_like( qr{ &\#10004; # MARK (?!.*