Title: [opsview] [10576] merge in 10481 - fix for checkboxes in shared notification profiles
Revision
10576
Author
aburzynski
Date
2012-10-23 10:00:15 +0100 (Tue, 23 Oct 2012)

Log Message

merge in 10481 - fix for checkboxes in shared notification profiles

Modified Paths


Property Changed


Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/DEV-capside/release-3.9.0:6365-6370
/branches/DEV-extra-notification-data:6734-6746
/branches/DEV-odw-calculations:9016-9160
/branches/DEV-restapi-monitoringservers:9778
/branches/DEV-snmp-multi:7324-7376
/branches/US187:9403-9479
/branches/US198b:8875-8994
/branches/US310:9851-9873
/branches/enterprise/BRAN-3.14:6874,6882,6956
/branches/enterprise/DEV-professional:6494-8475,8477-8478,8486,8490,8492,8494,8499-8500,8515,8518-8519,8524,8527-8529,8531-8532,8536,8538,8540-8544,8547-8552,8554,8557,8600-8601,8637,8749,8772,8897,8917,8944-8945,8947,8950-8952,8967,8969,8979,8982,8987,8998,9006,9008,9011,9013,9026,9033-9036,9038,9040,9042,9044,9048,9050-9053,9062,9064-9065,9069,9078,9081,9088,9096,9099-9101,9103,9105,9115,9118,9347,9353-9354,9411,9432,9445,9486,9538-9550,9569-9571,9620,9635,9637-9638,9645-9647,9693,9699,9721,9814,9825,9857,9879,9881,9939,10002,10029,10038-10041,10070,10086,10093,10345,10347,10388,10407,10560-10562,10565,10568,10571
/branches/nagvis-iframe:9764-9786
/branches/us168:8759,8762-8763,8766-8768,8770,8774-8777,8794,8798-8799,8801-8803,8821-8822,8834,8837-8838,8932,8937,8947,8969,8977,8981,9004,9007,9009-9010,9012,9024,9049
/commercial/branches/US306-slaves:9804-9823
/commercial/branches/US307-network-map:9685-9837
   + /branches/DEV-capside/release-3.9.0:6365-6370
/branches/DEV-extra-notification-data:6734-6746
/branches/DEV-odw-calculations:9016-9160
/branches/DEV-restapi-monitoringservers:9778
/branches/DEV-snmp-multi:7324-7376
/branches/US187:9403-9479
/branches/US198b:8875-8994
/branches/US310:9851-9873
/branches/enterprise/BRAN-3.14:6874,6882,6956
/branches/enterprise/DEV-professional:6494-8475,8477-8478,8486,8490,8492,8494,8499-8500,8515,8518-8519,8524,8527-8529,8531-8532,8536,8538,8540-8544,8547-8552,8554,8557,8600-8601,8637,8749,8772,8897,8917,8944-8945,8947,8950-8952,8967,8969,8979,8982,8987,8998,9006,9008,9011,9013,9026,9033-9036,9038,9040,9042,9044,9048,9050-9053,9062,9064-9065,9069,9078,9081,9088,9096,9099-9101,9103,9105,9115,9118,9347,9353-9354,9411,9432,9445,9486,9538-9550,9569-9571,9620,9635,9637-9638,9645-9647,9693,9699,9721,9814,9825,9857,9879,9881,9939,10002,10029,10038-10041,10070,10086,10093,10345,10347,10388,10407,10481,10560-10562,10565,10568,10571
/branches/nagvis-iframe:9764-9786
/branches/us168:8759,8762-8763,8766-8768,8770,8774-8777,8794,8798-8799,8801-8803,8821-8822,8834,8837-8838,8932,8937,8947,8969,8977,8981,9004,9007,9009-9010,9012,9024,9049
/commercial/branches/US306-slaves:9804-9823
/commercial/branches/US307-network-map:9685-9837

Modified: trunk/opsview-core/lib/Opsview/Schema/Sharednotificationprofiles.pm
===================================================================
--- trunk/opsview-core/lib/Opsview/Schema/Sharednotificationprofiles.pm	2012-10-22 22:19:02 UTC (rev 10575)
+++ trunk/opsview-core/lib/Opsview/Schema/Sharednotificationprofiles.pm	2012-10-23 09:00:15 UTC (rev 10576)
@@ -361,35 +361,20 @@
     return @cgs;
 }
 
-# Returns an rs based on hostgroups this contact is allowed to see
+# Returns an rs based on hostgroups this role is allowed to see
 sub valid_hostgroups {
     my ($self) = @_;
-    if ( $self->all_hostgroups ) {
-        return $self->role->valid_hostgroups;
-    }
-    else {
-        return $self->hostgroups;
-    }
+    return $self->role->valid_hostgroups;
 }
 
 sub valid_servicegroups {
     my ($self) = @_;
-    if ( $self->all_servicegroups ) {
-        return $self->role->valid_servicegroups;
-    }
-    else {
-        return $self->servicegroups;
-    }
+    return $self->role->valid_servicegroups;
 }
 
 sub valid_keywords {
     my ($self) = @_;
-    if ( $self->all_keywords ) {
-        return $self->role->valid_keywords;
-    }
-    else {
-        return $self->keywords;
-    }
+    return $self->role->valid_keywords;
 }
 
 sub host_notification_options {

Modified: trunk/opsview-web/t/tests/Test/Opsview/Web/Sharednotificationprofiles.pm
===================================================================
--- trunk/opsview-web/t/tests/Test/Opsview/Web/Sharednotificationprofiles.pm	2012-10-22 22:19:02 UTC (rev 10575)
+++ trunk/opsview-web/t/tests/Test/Opsview/Web/Sharednotificationprofiles.pm	2012-10-23 09:00:15 UTC (rev 10576)
@@ -10,25 +10,23 @@
 use Test::More;
 
 # Create a shared notification profile.
-sub create : Tests(15) {
+sub create : Tests(43) {
 
     my $self = shift;
     my $mech = $self->{mech};
 
-    # This must not be set, otherwise get strange behaviour
-    #$mech->max_redirect(0);
-
     $mech->get_ok( '/' );
     $mech->follow_link_ok( { text => 'Shared Notification Profiles' } );
     $mech->text_contains( 'Admin role profile 1' );
     $mech->text_contains( 'Admin role profile 2' );
     $mech->follow_link_ok( { url ="" '/admin/sharednotificationprofile/new' } );
     $mech->text_contains( 'New Shared notification profile' );
+
     $mech->submit_form_ok(
         {
             with_fields => {
                 name => 'A New Shared Profile',
-                role => 18, # 'View some, change some - somehosts'
+                role => 10,                    # 'Admin'
             },
         },
         "Basic form submitted"
@@ -37,18 +35,111 @@
         qr|URL=""
         "We're redirected to another edit page"
     );
-    my ($link) = ( $mech->content ) =~ m|URL=""
-    $mech->get_ok( $link, "Followed redirect link" );
+    my ($link_edit) = ( $mech->content ) =~ m|URL=""
+    $mech->get_ok( $link_edit, "Followed redirect link: $link_edit" );
+    my @available_options;
+    {
+        my $form = $mech->form_name( 'main_form' );
+        @available_options = $mech->grep_inputs(
+            {
+                type => qr/^checkbox$/,
+                name => qr/^(hostgroups|servicegroups|keywords)/,
+            }
+        );
+    }
+
+    note "Untick all all_hostgroups/all_servicegroups/all_keywords checkboxes";
+    $mech->untick( $_, 1 ) for qw(
+      all_hostgroups all_servicegroups all_keywords
+    );
+    note "Enable all hostgroups/servicegroups/keywords checkboxes";
+    $_->disabled(0) for @available_options;
+
+    my @selected_options = (
+        hostgroups    => 9,
+        hostgroups    => 10,
+        servicegroups => 2,
+        keywords      => 8,
+    );
+
+    $mech->tick( 'hostgroups',    9 );
+    $mech->tick( 'hostgroups',    10 );
+    $mech->tick( 'servicegroups', 2 );
+    $mech->tick( 'keywords',      8 );
+
+    for ( my $i = 0; $i < @selected_options; $i += 2 ) {
+        my $name = $selected_options[$i];
+        my $val  = $selected_options[ $i + 1 ];
+
+        $mech->tick( $name, $val );
+    }
+
     $mech->text_contains( 'Edit: A New Shared Profile' );
+
+    $mech->submit_form_ok(
+        { form_name => 'main_form', },
+        "Advanced form submitted"
+    );
+
+    my ($link_list) = ( $mech->content ) =~ m|URL=""
+    $mech->get_ok( $link_list, "Followed redirect link: $link_list" );
+
+    $mech->text_contains( 'Shared notification profile > List' );
+    $mech->text_contains( 'A New Shared Profile' );
+    $mech->text_contains( 'Time Period: 24x7' );
+    $mech->text_contains( 'Keywords: All' );
+
+    $mech->follow_link_ok( { text => 'A New Shared Profile' } );
+    my @available_edit_options;
     {
-        local $TODO = "The submit button can't be clicked - _javascript_?";
-        $mech->submit_form_ok( {}, "Advanced form submitted" );
-        $mech->text_contains( 'Shared notification profile &gt; List' );
-        $mech->text_contains( 'A New Shared Profile' );
-        $mech->text_contains( 'Time Period: 24x7' );
-        $mech->text_contains( 'Keywords: All' );
+        my $form = $mech->form_name( 'main_form' );
+        @available_edit_options = $mech->grep_inputs(
+            {
+                type => qr/^checkbox$/,
+                name => qr/^(hostgroups|servicegroups|keywords)/,
+            }
+        );
     }
 
+    # confirm that all correct options are checked
+    for my $chk_all (qw( all_hostgroups all_servicegroups all_keywords)) {
+        my ($input) = $mech->grep_inputs( { name => qr/^$chk_all$/, } );
+        is( $input->value, undef, "$chk_all is not checked" );
+    }
+
+    for my $checkbox (@available_edit_options) {
+        my ($possible_value) = grep {defined} $checkbox->possible_values;
+        my $expected;
+        for ( my $i = 0; $i < @selected_options; $i += 2 ) {
+            my $name = $selected_options[$i];
+            my $val  = $selected_options[ $i + 1 ];
+
+            next unless $name eq $checkbox->name;
+
+            if ( $val == $possible_value ) {
+                $expected = $val;
+                last;
+            }
+        }
+
+        is(
+            $checkbox->value,
+            $expected,
+            $checkbox->name . " is "
+              . ( $expected ? "checked: $expected" : "not checked" )
+        );
+        is( $checkbox->disabled, 0, "..and is not disabled" );
+    }
+
+    my @norm_prev =
+      map { +{ $_->name => [ $_->possible_values ] } } @available_options;
+    my @norm_cur =
+      map { +{ $_->name => [ $_->possible_values ] } } @available_edit_options;
+    is_deeply(
+        \@norm_prev,
+        \@norm_cur,
+        "available hostgroups/servicegroups/keywords for edits are the same as for new profiles"
+    );
 }
 
 1;

_______________________________________________
Opsview-checkins mailing list
[email protected]
http://lists.opsview.org/lists/listinfo/opsview-checkins

Reply via email to