From 02b49c6de653ccb7b6be456214abaf2d6fd2d3d3 Mon Sep 17 00:00:00 2001 From: sunnavy Date: Mon, 4 Dec 2023 14:30:28 -0500 Subject: [PATCH] Test asset charts --- t/charts/asset.t | 102 +++++++++++++++++++++++++++++++++++++ t/web/charting.t | 12 +++++ t/web/custom_frontpage.t | 31 +++++++++++ t/web/saved_search_chart.t | 30 +++++++++++ 4 files changed, 175 insertions(+) create mode 100644 t/charts/asset.t diff --git a/t/charts/asset.t b/t/charts/asset.t new file mode 100644 index 00000000000..767e53a13db --- /dev/null +++ b/t/charts/asset.t @@ -0,0 +1,102 @@ +use strict; +use warnings; + +use RT::Test::Assets tests => undef; +use RT::Report::Assets; + +for my $status (qw/new in-use in-use allocated/) { # 2 in-use assets + create_asset( Catalog => 'General assets', Name => 'test', Status => $status ); +} + +my $report = RT::Report::Assets->new( RT->SystemUser ); +my %columns = $report->SetupGroupings( + Query => q{Catalog = 'General assets'}, + GroupBy => ['Status'], + Function => ['COUNT'], +); +$report->SortEntries; + +my @colors = RT->Config->Get("ChartColors"); +my $expected = { + 'thead' => [ + { + 'cells' => [ + { + 'type' => 'head', + 'value' => 'Status' + }, + { + 'color' => $colors[0], + 'rowspan' => 1, + 'type' => 'head', + 'value' => 'Asset count' + } + ] + } + ], + 'tbody' => [ + { + 'cells' => [ + { + 'type' => 'label', + 'value' => 'allocated', + }, + { + 'query' => "(Status = 'allocated')", + 'type' => 'value', + 'value' => '1', + } + ], + 'even' => 1 + }, + { + 'even' => 0, + 'cells' => [ + { + 'type' => 'label', + 'value' => 'in-use', + }, + { + 'query' => "(Status = 'in-use')", + 'type' => 'value', + 'value' => '2', + } + ] + }, + { + 'even' => 1, + 'cells' => [ + { + 'type' => 'label', + 'value' => 'new', + }, + { + 'query' => "(Status = 'new')", + 'type' => 'value', + 'value' => '1', + } + ] + } + ], + 'tfoot' => [ + { + 'cells' => [ + { + 'colspan' => 1, + 'type' => 'label', + 'value' => 'Total' + }, + { + 'type' => 'value', + 'value' => 4 + } + ], + 'even' => 0 + } + ], +}; + +my %table = $report->FormatTable(%columns); +is_deeply( \%table, $expected, "basic table" ); + +done_testing; diff --git a/t/web/charting.t b/t/web/charting.t index 1cf81709425..a9c8454cf99 100644 --- a/t/web/charting.t +++ b/t/web/charting.t @@ -141,4 +141,16 @@ $m->get_ok("/Search/Chart?Class=RT::Transactions&Query=Type=Create"); is( $m->content_type, "image/png" ); ok( length( $m->content ), "Has content" ); +# Test asset charts +my $asset = RT::Asset->new( RT->SystemUser ); +$asset->Create( Name => 'test', Catalog => 'General assets', Status => 'new' ); +ok( $asset->Id, 'Created test asset' ); +$m->get_ok("/Search/Chart.html?Class=RT::Assets&Query=id>0"); +$m->content_like( qr{]*>Status\s*\s*]*>Asset count\s*}, "Grouped by status" ); +$m->content_like( qr{new\s*\s*]*>\s*]*>1}, "Found results in table" ); +$m->content_like( qr{get_ok("/Search/Chart?Class=RT::Assets&Query=id>0"); +is( $m->content_type, "image/png" ); +ok( length( $m->content ), "Has content" ); + done_testing; diff --git a/t/web/custom_frontpage.t b/t/web/custom_frontpage.t index 5ed6b4964cf..a634b9f2004 100644 --- a/t/web/custom_frontpage.t +++ b/t/web/custom_frontpage.t @@ -205,12 +205,40 @@ $m->submit_form( ); $m->content_contains("Chart first txn chart saved", 'saved first txn chart' ); +# Add asset saved searches +$m->get_ok( $url . "/Search/Build.html?Class=RT::Assets&Query=" . 'id>0' ); + +$m->submit_form( + form_name => 'BuildQuery', + fields => { + SavedSearchDescription => 'first asset search', + SavedSearchOwner => 'RT::System-1', + }, + button => 'SavedSearchSave', +); +# We don't show saved message on page :/ +$m->content_contains("Save as New", 'saved first asset search' ); + +$m->get_ok( $url . "/Search/Chart.html?Class=RT::Assets&Query=" . 'id>0' ); + +$m->submit_form( + form_name => 'SaveSearch', + fields => { + SavedSearchDescription => 'first asset chart', + SavedSearchOwner => 'RT::System-1', + }, + button => 'SavedSearchSave', +); +$m->content_contains("Chart first asset chart saved", 'saved first txn chart' ); + $m->get_ok( $url . "Dashboards/Queries.html?id=$id" ); push( @{$args->{body}}, "saved-" . $m->dom->find('[data-description="first chart"]')->first->attr('data-name'), "saved-" . $m->dom->find('[data-description="first txn search"]')->first->attr('data-name'), "saved-" . $m->dom->find('[data-description="first txn chart"]')->first->attr('data-name'), + "saved-" . $m->dom->find('[data-description="first asset search"]')->first->attr('data-name'), + "saved-" . $m->dom->find('[data-description="first asset chart"]')->first->attr('data-name'), ); $res = $m->post( @@ -226,5 +254,8 @@ $m->text_contains('first chart'); $m->text_contains('first txn search'); $m->text_contains('first txn chart'); $m->text_contains('Transaction count', 'txn chart content'); +$m->text_contains('first asset search'); +$m->text_contains('first asset chart'); +$m->text_contains('Asset count', 'asset chart content'); done_testing; diff --git a/t/web/saved_search_chart.t b/t/web/saved_search_chart.t index 26366cc101c..93fb297bd2c 100644 --- a/t/web/saved_search_chart.t +++ b/t/web/saved_search_chart.t @@ -261,4 +261,34 @@ diag 'testing transaction saved searches'; is( $search->Name, 'txn chart 1', 'loaded search' ); } + +diag 'testing asset saved searches'; +{ + $m->get_ok("/Search/Chart.html?Class=RT::Assets&Query=id>0"); + $m->submit_form( + form_name => 'SaveSearch', + fields => { + SavedSearchDescription => 'asset chart 1', + SavedSearchOwner => $owner, + }, + button => 'SavedSearchSave', + ); + $m->form_name('SaveSearch'); + @saved_search_ids = $m->current_form->find_input('SavedSearchLoad')->possible_values; + shift @saved_search_ids; # first value is blank + my $chart_without_updates_id = $saved_search_ids[0]; + ok( $chart_without_updates_id, 'got a saved chart id' ); + is( scalar @saved_search_ids, 1, 'got only one saved chart id' ); + + my ( $privacy, $user_id, $search_id ) = $chart_without_updates_id =~ /^(RT::User-(\d+))-SavedSearch-(\d+)$/; + my $user = RT::User->new( RT->SystemUser ); + $user->Load($user_id); + is( $user->Name, 'root', 'loaded user' ); + my $currentuser = RT::CurrentUser->new($user); + + my $search = RT::SavedSearch->new($currentuser); + $search->Load( $privacy, $search_id ); + is( $search->Name, 'asset chart 1', 'loaded search' ); +} + done_testing;