Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 1 | use Mojo::Base -strict; |
| 2 | use lib '../lib', 'lib'; |
| 3 | use Mojolicious::Lite; |
| 4 | use Test::More; |
| 5 | use Test::Mojo; |
| 6 | |
| 7 | my $t = Test::Mojo->new; |
| 8 | my $app = $t->app; |
| 9 | |
| 10 | # Add additional plugin path |
| 11 | push(@{$app->plugins->namespaces}, 'Kalamar::Plugin'); |
| 12 | |
| 13 | # Establish test route |
| 14 | $app->routes->get('/doc/(*scope)/:page')->to(cb => sub {})->name('doc'); |
| 15 | |
| 16 | # Load plugin to test |
| 17 | $app->plugin('KalamarHelpers'); |
| 18 | |
| 19 | my $navi = [ |
| 20 | { |
| 21 | id => 'korap', |
| 22 | title => 'KorAP' |
| 23 | } |
| 24 | ]; |
| 25 | |
| 26 | my $render = $app->doc_navi($navi); |
| 27 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 28 | like($render, qr!KorAP!, 'Title matches'); |
| 29 | |
| 30 | $navi = [ |
| 31 | { |
| 32 | id => 'korap', |
| 33 | title => 'KorAP' |
| 34 | }, |
| 35 | { |
| 36 | id => 'krill', |
| 37 | title => 'Krill' |
| 38 | } |
| 39 | ]; |
| 40 | |
| 41 | $render = $app->doc_navi($navi); |
| 42 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 43 | like($render, qr!KorAP!, 'Title matches'); |
| 44 | like($render, qr!/doc/krill!, 'Path matches doc/krill'); |
| 45 | like($render, qr!Krill!, 'Title matches'); |
| 46 | |
| 47 | $navi = [ |
| 48 | { |
| 49 | id => 'korap', |
| 50 | title => 'KorAP', |
| 51 | items => [ |
| 52 | { |
| 53 | id => 'krill', |
| 54 | title => 'Krill', |
| 55 | } |
| 56 | ] |
| 57 | }, |
| 58 | { |
| 59 | id => 'faq', |
| 60 | title => 'F.A.Q.' |
| 61 | } |
| 62 | ]; |
| 63 | |
| 64 | $render = $app->doc_navi($navi); |
| 65 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 66 | like($render, qr!/doc/korap/krill!, 'Path matches korap/krill'); |
| 67 | like($render, qr!/doc/faq!, 'Path matches doc/faq'); |
| 68 | |
| 69 | $navi = [ |
| 70 | { |
| 71 | id => 'korap', |
| 72 | title => 'KorAP', |
| 73 | items => [ |
| 74 | { |
| 75 | id => 'krill', |
| 76 | title => 'Krill', |
| 77 | }, |
| 78 | { |
| 79 | id => 'koral', |
| 80 | title => 'Koral' |
| 81 | } |
| 82 | ] |
| 83 | }, |
| 84 | { |
| 85 | title => 'Query Languages', |
| 86 | id => 'ql', |
| 87 | items => [ |
| 88 | { |
| 89 | title => 'Cosmas II', |
| 90 | id => 'cosmas2' |
| 91 | }, |
| 92 | { |
| 93 | 'title' => 'Poliqarp+', |
| 94 | 'id' => 'poliqarp-plus', |
| 95 | items => [ |
| 96 | { |
| 97 | "title" => "Simple Segments", |
| 98 | "id" => "#segments" |
| 99 | }, |
| 100 | { |
| 101 | "title" => "Complex Segments", |
| 102 | "id" => "#complex" |
| 103 | } |
| 104 | ] |
| 105 | } |
| 106 | ] |
| 107 | }, |
| 108 | { |
| 109 | id => 'faq', |
| 110 | title => 'F.A.Q.' |
| 111 | } |
| 112 | ]; |
| 113 | |
| 114 | $render = $app->doc_navi($navi); |
| 115 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 116 | like($render, qr!/doc/korap/krill!, 'Path matches korap/krill'); |
| 117 | like($render, qr!/doc/korap/koral!, 'Path matches korap/koral'); |
| 118 | like($render, qr!/doc/ql!, 'Path matches doc/ql'); |
| 119 | like($render, qr!/doc/ql/cosmas2!, 'Path matches doc/ql/cosmas2'); |
| 120 | like($render, qr!/doc/ql/poliqarp-plus!, 'Path matches doc/ql/poliqarp-plus'); |
| 121 | like($render, qr!/doc/ql/poliqarp-plus#segments!, |
| 122 | 'Path matches doc/ql/poliqarp-plus#segments'); |
| 123 | like($render, qr!/doc/ql/poliqarp-plus#complex!, |
| 124 | 'Path matches doc/ql/poliqarp-plus#complex'); |
| 125 | like($render, qr!/doc/faq!, 'Path matches doc/faq'); |
| 126 | |
| 127 | |
| 128 | my $c = $app->build_controller; |
| 129 | $c->stash(page => 'korap'); |
| 130 | $render = $c->doc_navi($navi); |
| 131 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 132 | like($render, qr!/doc/korap/krill!, 'Path matches korap/krill'); |
| 133 | like($render, qr!/doc/ql!, 'Path matches doc/ql'); |
| 134 | like($render, qr!/doc/ql/poliqarp-plus#segments!, |
| 135 | 'Path matches doc/ql/poliqarp-plus#segments'); |
| 136 | like($render, qr!/doc/ql/poliqarp-plus#complex!, |
| 137 | 'Path matches doc/ql/poliqarp-plus#complex'); |
| 138 | like($render, qr!class="active".*?KorAP!, 'Active value for KorAP'); |
| 139 | |
| 140 | $c->stash(page => 'poliqarp-plus'); |
| 141 | $render = $c->doc_navi($navi); |
| 142 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 143 | like($render, qr!/doc/korap/krill!, 'Path matches korap/krill'); |
| 144 | like($render, qr!/doc/ql!, 'Path matches doc/ql'); |
| 145 | like($render, qr!/doc/ql/poliqarp-plus#segments!, |
| 146 | 'Path matches doc/ql/poliqarp-plus#segments'); |
| 147 | like($render, qr!/doc/ql/poliqarp-plus#complex!, |
| 148 | 'Path matches doc/ql/poliqarp-plus#complex'); |
| 149 | like($render, qr!class="active".*?Poliqarp\+!, 'Active value for Poliqarp+'); |
| 150 | |
| 151 | |
| 152 | $navi = [ |
| 153 | { |
| 154 | id => 'korap', |
| 155 | title => 'KorAP', |
| 156 | items => [ |
| 157 | { |
| 158 | id => 'krill', |
| 159 | title => 'Krill', |
| 160 | }, |
| 161 | { |
| 162 | id => 'koral', |
| 163 | title => 'Koral' |
| 164 | } |
| 165 | ] |
| 166 | }, |
| 167 | { |
| 168 | title => 'Query Languages', |
| 169 | id => 'ql', |
| 170 | items => [ |
| 171 | { |
| 172 | title => 'Cosmas II', |
| 173 | id => 'cosmas2' |
| 174 | }, |
| 175 | { |
| 176 | 'title' => 'Poliqarp+', |
| 177 | 'id' => 'poliqarp-plus', |
| 178 | 'class' => 'folded', |
| 179 | items => [ |
| 180 | { |
| 181 | "title" => "Simple Segments", |
| 182 | "id" => "#segments" |
| 183 | }, |
| 184 | { |
| 185 | "title" => "Complex Segments", |
| 186 | "id" => "#complex" |
| 187 | } |
| 188 | ] |
| 189 | } |
| 190 | ] |
| 191 | }, |
| 192 | { |
| 193 | id => 'faq', |
| 194 | title => 'F.A.Q.' |
| 195 | } |
| 196 | ]; |
| 197 | $render = $c->doc_navi($navi); |
| 198 | |
| 199 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 200 | like($render, qr!/doc/korap/krill!, 'Path matches korap/krill'); |
| 201 | like($render, qr!/doc/ql!, 'Path matches doc/ql'); |
| 202 | like($render, qr!/doc/ql/poliqarp-plus#segments!, |
| 203 | 'Path matches doc/ql/poliqarp-plus#segments'); |
| 204 | like($render, qr!/doc/ql/poliqarp-plus#complex!, |
| 205 | 'Path matches doc/ql/poliqarp-plus#complex'); |
| 206 | like($render, qr!class="folded active".*?Poliqarp\+!, 'Active and folded value for Poliqarp+'); |
| 207 | |
| 208 | done_testing; |
| 209 | |
| 210 | __END__ |
| 211 | |