Skip to content

Commit

Permalink
Test asset charts
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnavy committed Dec 20, 2023
1 parent 5be73b5 commit 3eceb99
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 0 deletions.
102 changes: 102 additions & 0 deletions t/charts/asset.t
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 12 additions & 0 deletions t/web/charting.t
Original file line number Diff line number Diff line change
Expand Up @@ -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{<th[^>]*>Status\s*</th>\s*<th[^>]*>Asset count\s*</th>}, "Grouped by status" );
$m->content_like( qr{new\s*</th>\s*<td[^>]*>\s*<a[^>]*>1</a>}, "Found results in table" );
$m->content_like( qr{<img src="/Search/Chart\?}, "Found image" );
$m->get_ok("/Search/Chart?Class=RT::Assets&Query=id>0");
is( $m->content_type, "image/png" );
ok( length( $m->content ), "Has content" );

done_testing;
31 changes: 31 additions & 0 deletions t/web/custom_frontpage.t
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
30 changes: 30 additions & 0 deletions t/web/saved_search_chart.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 3eceb99

Please sign in to comment.