first pass RT4 merge, RT#13852
[freeside.git] / rt / t / web / dashboards-deleted-saved-search.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4
5 use RT::Test tests => 20;
6 my ( $url, $m ) = RT::Test->started_ok;
7 ok( $m->login, 'logged in' );
8
9 # create a saved search
10 $m->get_ok( $url . "/Search/Build.html?Query=" . 'id=1' );
11
12 $m->submit_form(
13     form_name => 'BuildQuery',
14     fields    => { SavedSearchDescription => 'foo', },
15     button    => 'SavedSearchSave',
16 );
17
18 my ( $search_uri, $user_id, $search_id ) =
19   $m->content =~ /value="(RT::User-(\d+)-SavedSearch-(\d+))"/;
20 $m->submit_form(
21     form_name => 'BuildQuery',
22     fields    => { SavedSearchLoad => $search_uri },
23     button    => 'SavedSearchSave',
24 );
25
26 $m->content_like( qr/name="SavedSearchDelete"\s+value="Delete"/,
27     'found Delete button' );
28 $m->content_like(
29     qr/name="SavedSearchDescription"\s+value="foo"/,
30     'found Description input with the value filled'
31 );
32
33 # create a dashboard with the created search
34
35 $m->get_ok( $url . "/Dashboards/Modify.html?Create=1" );
36 $m->submit_form(
37     form_name => 'ModifyDashboard',
38     fields    => { Name => 'bar' },
39 );
40
41 $m->content_contains('Saved dashboard bar', 'dashboard saved' );
42 my $dashboard_queries_link = $m->find_link( text_regex => qr/Content/ );
43 my ( $dashboard_id ) = $dashboard_queries_link->url =~ /id=(\d+)/;
44
45 $m->get_ok( $url . "/Dashboards/Queries.html?id=$dashboard_id" );
46
47 $m->content_lacks( 'value="Update"', 'no update button' );
48
49 $m->submit_form(
50     form_name => 'Dashboard-Searches-body',
51     fields =>
52       { 'Searches-body-Available' => "search-$search_id-RT::User-$user_id" },
53     button => 'add',
54 );
55
56 $m->content_contains('Dashboard updated', 'added search foo to dashboard bar' );
57
58 # delete the created search
59
60 $m->get_ok( $url . "/Search/Build.html?Query=" . 'id=1' );
61 $m->submit_form(
62     form_name => 'BuildQuery',
63     fields    => { SavedSearchLoad => $search_uri },
64 );
65 $m->submit_form(
66     form_name => 'BuildQuery',
67     button    => 'SavedSearchDelete',
68 );
69
70 $m->content_lacks( $search_uri, 'deleted search foo' );
71
72 # here is what we really want to test
73
74 $m->get_ok( $url . "/Dashboards/Queries.html?id=$dashboard_id" );
75 $m->content_contains('Deleted queries', 'found deleted message' );
76
77 # Update button shows so we can update the deleted search easily
78 $m->content_contains( 'value="Update"', 'found update button' );
79
80 $m->submit_form(
81     form_name => 'Dashboard-Searches-body',
82     button    => 'update',
83 );
84
85 $m->content_lacks('Deleted queries', 'deleted message is gone' );
86 $m->content_lacks( 'value="Update"', 'update button is gone too' );
87
88 $m->get_warnings; # we'll get a lot of warnings because the deleted search
89