| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | use lib 'lib'; |
|---|
| 6 | |
|---|
| 7 | use Test::More tests => 16; |
|---|
| 8 | |
|---|
| 9 | BEGIN { $ENV{CATALYST_DEBUG} = 0; } |
|---|
| 10 | BEGIN { use_ok 'Catalyst::Test', 'Vee' } |
|---|
| 11 | BEGIN { use_ok 'Vee::Controller::Dex::Search' } |
|---|
| 12 | |
|---|
| 13 | sub search_ok; |
|---|
| 14 | |
|---|
| 15 | ### Same idea as Pokemon search tests |
|---|
| 16 | |
|---|
| 17 | ok request('/dex/moves/search')->is_success, "Move search page loads"; |
|---|
| 18 | |
|---|
| 19 | search_ok { name => 'fire' }, |
|---|
| 20 | [qw/ 7 83 126 221 424 /], |
|---|
| 21 | "Name substring"; |
|---|
| 22 | |
|---|
| 23 | search_ok { name => '???' }, |
|---|
| 24 | [qw/ 15 19 91 /], |
|---|
| 25 | "Name with wildcards"; |
|---|
| 26 | |
|---|
| 27 | search_ok { name => 'fire', class => 'physical' }, |
|---|
| 28 | [qw/ 7 221 424 /], |
|---|
| 29 | "Damage class (+ name)"; |
|---|
| 30 | |
|---|
| 31 | search_ok { class => 'special', type => 'dark' }, |
|---|
| 32 | [qw/ 399 /], |
|---|
| 33 | "Type (+ damage class)"; |
|---|
| 34 | |
|---|
| 35 | search_ok { type => 'dragon', generation => 1 }, |
|---|
| 36 | [qw/ 200 225 239/], |
|---|
| 37 | "Generation (+ type)"; |
|---|
| 38 | |
|---|
| 39 | search_ok { type => 'steel', generation => 0 }, |
|---|
| 40 | [qw/ /], |
|---|
| 41 | "Impossible generation + type"; |
|---|
| 42 | |
|---|
| 43 | search_ok { pokemon => [qw/ flareon charizard /], move_method => 'level' }, |
|---|
| 44 | [qw/ 43 52 53 83 99 184 424 /], |
|---|
| 45 | "Multiple Pokemon, by level"; |
|---|
| 46 | |
|---|
| 47 | search_ok { pokemon => 'ditto' }, |
|---|
| 48 | [qw/ 144 /], |
|---|
| 49 | "Single Pokemon"; |
|---|
| 50 | |
|---|
| 51 | search_ok { pokemon => 'charizard', move_method => 'tutor', move_version => 'c' }, |
|---|
| 52 | [qw/ 53 /], |
|---|
| 53 | "Single Pokemon, via tutor, in Crystal"; |
|---|
| 54 | |
|---|
| 55 | search_ok { power_lb => 200 }, |
|---|
| 56 | [qw/ 120 153 /], |
|---|
| 57 | "Lower bound on power"; |
|---|
| 58 | |
|---|
| 59 | search_ok { power_lb => 14, power_ub => 16 }, |
|---|
| 60 | [qw/ 3 20 31 35 40 42 83 140 250 292 328 /], |
|---|
| 61 | "Lower and upper bounds on power"; |
|---|
| 62 | |
|---|
| 63 | search_ok { accuracy_lb => 30, accuracy_ub => 30 }, |
|---|
| 64 | [qw/ 12 32 90 329 /], |
|---|
| 65 | "Exact accuracy"; |
|---|
| 66 | |
|---|
| 67 | search_ok { name => 'fire', sort => 'name' }, |
|---|
| 68 | [qw/ 126 424 7 83 221 /], |
|---|
| 69 | "Sorting (+ name)"; |
|---|
| 70 | |
|---|
| 71 | # TODO: This is remarkably similar to the Pokemon search sub! Generalize and |
|---|
| 72 | # throw it in Veekun::Test::*. |
|---|
| 73 | sub search_ok { |
|---|
| 74 | my ($params, $expected, $test_name) = @_; |
|---|
| 75 | |
|---|
| 76 | if (not $params->{sort}) { |
|---|
| 77 | # sort by id for simplicity |
|---|
| 78 | $params->{sort} = 'id'; |
|---|
| 79 | delete $params->{sort_desc}; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | my $context = Vee->prepare; |
|---|
| 83 | $context->req->params($params); |
|---|
| 84 | Vee::Controller::Dex::Search->move_search($context); |
|---|
| 85 | |
|---|
| 86 | my $move_rows = $context->stash->{results} || []; |
|---|
| 87 | my @moves = map { $_->id } @$move_rows; |
|---|
| 88 | |
|---|
| 89 | is_deeply \@moves, $expected, $test_name; |
|---|
| 90 | } |
|---|