4 use Test::More tests => 31;
5 use Test::WWW::Mechanize;
6 use HTTP::Request::Common;
11 my $cookie_jar = HTTP::Cookies->new;
12 my $agent = Test::WWW::Mechanize->new();
14 # give the agent a place to stash the cookies
16 $agent->cookie_jar($cookie_jar);
22 my $url = $RT::WebURL;
25 is ($agent->{'status'}, 200, "Loaded a page");
30 # follow the link marked "Login"
32 ok($agent->{form}->find_input('user'));
34 ok($agent->{form}->find_input('pass'));
35 ok ($agent->{'content'} =~ /username:/i);
36 $agent->field( 'user' => 'root' );
37 $agent->field( 'pass' => 'password' );
38 # the field isn't named, so we have to click link 0
40 is($agent->{'status'}, 200, "Fetched the page ok");
41 ok( $agent->{'content'} =~ /Logout/i, "Found a logout link");
45 # {{{ Query Builder tests
47 my $response = $agent->get($url."Search/Build.html");
48 ok( $response->is_success, "Fetched " . $url."Search/Build.html" );
53 ok($agent->form_name('BuildQuery'), "found the form once");
54 $agent->field("ActorField", "Owner");
55 $agent->field("ActorOp", "=");
56 $agent->field("ValueOfActor", "Nobody");
60 ok($agent->form_name('BuildQuery'), "found the form again");
61 $agent->field("QueueOp", "!=");
62 $agent->field("ValueOfQueue", "Regression");
65 ok($agent->form_name('BuildQuery'), "found the form a third time");
67 sub getQueryFromForm {
68 # This pulls out the "hidden input" query from the page
69 my $q = $agent->current_form->find_input("Query")->value;
76 is (getQueryFromForm, "Owner = 'Nobody' AND Queue != 'Regression'");
78 # We're going to delete the owner
80 $agent->select("clauses", ["0"] );
82 $agent->click("DeleteClause");
84 ok($agent->form_name('BuildQuery'), "found the form a fourth time");
86 is (getQueryFromForm, "Queue != 'Regression'");
88 $agent->field("AndOr", "OR");
90 $agent->select("idOp", ">");
92 $agent->field("ValueOfid" => "1234");
94 $agent->click("AddClause");
96 ok($agent->form_name('BuildQuery'), "found the form again");
98 local $TODO = "query builder incorrectly quotes numbers";
99 is(getQueryFromForm, "Queue != 'Regression' OR id > 1234", "added something as OR, and number not quoted");
102 sub selectedClauses {
103 my @clauses = grep { defined } map { $_->value } $agent->current_form->find_input("clauses");
108 is_deeply(selectedClauses, ["1"], 'the id that we just entered is still selected');
110 # Move the second one up a level
113 ok($agent->form_name('BuildQuery'), "found the form again");
114 is(getQueryFromForm, "id > 1234 OR Queue != 'Regression'", "moved up one");
116 is_deeply(selectedClauses, ["0"], 'the one we moved up is selected');
118 $agent->click("Right");
120 ok($agent->form_name('BuildQuery'), "found the form again");
121 is(getQueryFromForm, "Queue != 'Regression' OR ( id > 1234 )", "moved over to the right (and down)");
122 is_deeply(selectedClauses, ["2"], 'the one we moved right is selected');
124 $agent->select("clauses", ["1"]);
128 ok($agent->form_name('BuildQuery'), "found the form again");
130 local $TODO = "query builder incorrectly changes OR to AND";
131 is(getQueryFromForm, "( id > 1234 ) OR Queue != 'Regression'", "moved up");
134 $agent->select("clauses", ["0"]); # this is a null clause
138 ok($agent->form_name('BuildQuery'), "found the form again");
140 $agent->content_like(qr/error: can\S+t move up/, "i shouldn't have been able to hit up");
142 $agent->click("Left");
144 ok($agent->form_name('BuildQuery'), "found the form again");
146 $agent->content_like(qr/error: can\S+t move left/, "i shouldn't have been able to hit left");
148 $agent->select("clauses", ["1"]);
149 $agent->select("ValueOfStatus" => "stalled");
152 ok($agent->form_name('BuildQuery'), "found the form again");
153 is_deeply(selectedClauses, ["2"], 'the one we added is selected');
155 local $TODO = "query builder incorrectly changes OR to AND";
156 is(getQueryFromForm, "( id > 1234 AND Status = 'stalled' ) OR Queue != 'Regression'", "added new one");
161 # - new items go one level down
162 # - add items at currently selected level
163 # - if nothing is selected, add at end, one level down
166 # - error if nothing selected
167 # - same item should be selected after move
168 # - can't move left if you're at the top level
171 # - error if nothing selected
172 # - same item should be selected after move
173 # - can always move right (no max depth...should there be?)
176 # - error if nothing selected
177 # - same item should be selected after move
178 # - can't move up if you're first in the list
181 # - error if nothing selected
182 # - same item should be selected after move
183 # - can't move down if you're last in the list
186 # - error if nothing selected
187 # - change all aggregators in the grouping
188 # - don't change any others
191 # - error if nothing selected
192 # - delete currently selected item
193 # - delete all children of a grouping
194 # - if delete leaves a node with no children, delete that, too
195 # - what should be selected?
198 # - clears entire query
199 # - clears it from the session, too