Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 1 | use Mojo::Base -strict; |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 2 | use Mojolicious::Lite; |
| 3 | use Test::More; |
| 4 | use Test::Mojo; |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 5 | use utf8; |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 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 |
Akron | 254fe21 | 2019-10-24 14:33:28 +0200 | [diff] [blame] | 14 | $app->routes->get('/doc/:scope/:page')->to(cb => sub {}, scope => undef)->name('doc'); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 15 | |
| 16 | # Load plugin to test |
Akron | 41a190a | 2019-10-16 18:01:02 +0200 | [diff] [blame] | 17 | $app->plugin('KalamarPages'); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 18 | |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 19 | my $languages = [qw/en de/]; |
| 20 | $app->plugin('Localize' => { |
| 21 | dict => { |
| 22 | Nav => { |
| 23 | _ => sub { $languages }, |
| 24 | -en => { |
Marc Kupietz | b82939b | 2021-09-07 22:45:38 +0200 | [diff] [blame] | 25 | faq => 'FAQ', |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 26 | '#default-foundries' => 'Default Foundries', |
| 27 | }, |
| 28 | de => { |
Marc Kupietz | b82939b | 2021-09-07 22:45:38 +0200 | [diff] [blame] | 29 | faq => 'FAQ', |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 30 | '#default-foundries' => 'Standard Foundries' |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | }); |
| 35 | |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 36 | my $navi = [ |
| 37 | { |
Marc Kupietz | fcadda6 | 2021-09-08 09:06:25 +0200 | [diff] [blame] | 38 | id => 'development', |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 39 | title => 'KorAP' |
| 40 | } |
| 41 | ]; |
| 42 | |
Akron | d512ea6 | 2019-10-24 15:50:04 +0200 | [diff] [blame] | 43 | my $render = $app->navigation('doc', $navi); |
Marc Kupietz | fcadda6 | 2021-09-08 09:06:25 +0200 | [diff] [blame] | 44 | like($render, qr!/doc/development!, 'Path matches doc/development'); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 45 | like($render, qr!KorAP!, 'Title matches'); |
| 46 | |
| 47 | $navi = [ |
| 48 | { |
Marc Kupietz | fcadda6 | 2021-09-08 09:06:25 +0200 | [diff] [blame] | 49 | id => 'development', |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 50 | title => 'KorAP' |
| 51 | }, |
| 52 | { |
| 53 | id => 'krill', |
| 54 | title => 'Krill' |
| 55 | } |
| 56 | ]; |
| 57 | |
Akron | d512ea6 | 2019-10-24 15:50:04 +0200 | [diff] [blame] | 58 | $render = $app->navigation('doc', $navi); |
Marc Kupietz | fcadda6 | 2021-09-08 09:06:25 +0200 | [diff] [blame] | 59 | like($render, qr!/doc/development!, 'Path matches doc/development'); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 60 | like($render, qr!KorAP!, 'Title matches'); |
| 61 | like($render, qr!/doc/krill!, 'Path matches doc/krill'); |
| 62 | like($render, qr!Krill!, 'Title matches'); |
| 63 | |
| 64 | $navi = [ |
| 65 | { |
Marc Kupietz | fcadda6 | 2021-09-08 09:06:25 +0200 | [diff] [blame] | 66 | id => 'development', |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 67 | title => 'KorAP', |
| 68 | items => [ |
| 69 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 70 | id => 'krill', |
| 71 | title => 'Krill', |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 72 | } |
| 73 | ] |
| 74 | }, |
| 75 | { |
| 76 | id => 'faq', |
Marc Kupietz | b82939b | 2021-09-07 22:45:38 +0200 | [diff] [blame] | 77 | title => 'FAQ' |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 78 | } |
| 79 | ]; |
| 80 | |
Akron | d512ea6 | 2019-10-24 15:50:04 +0200 | [diff] [blame] | 81 | $render = $app->navigation('doc', $navi); |
Marc Kupietz | fcadda6 | 2021-09-08 09:06:25 +0200 | [diff] [blame] | 82 | like($render, qr!/doc/development!, 'Path matches doc/development'); |
| 83 | like($render, qr!/doc/development/krill!, 'Path matches development/krill'); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 84 | like($render, qr!/doc/faq!, 'Path matches doc/faq'); |
| 85 | |
| 86 | $navi = [ |
| 87 | { |
Marc Kupietz | fcadda6 | 2021-09-08 09:06:25 +0200 | [diff] [blame] | 88 | id => 'development', |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 89 | title => 'KorAP', |
| 90 | items => [ |
| 91 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 92 | id => 'krill', |
| 93 | title => 'Krill', |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 94 | }, |
| 95 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 96 | id => 'koral', |
| 97 | title => 'Koral' |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 98 | } |
| 99 | ] |
| 100 | }, |
| 101 | { |
| 102 | title => 'Query Languages', |
| 103 | id => 'ql', |
| 104 | items => [ |
| 105 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 106 | title => 'Cosmas II', |
| 107 | id => 'cosmas2' |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 108 | }, |
| 109 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 110 | 'title' => 'Poliqarp+', |
| 111 | 'id' => 'poliqarp-plus', |
| 112 | items => [ |
| 113 | { |
| 114 | "title" => "Simple Segments", |
| 115 | "id" => "#segments" |
| 116 | }, |
| 117 | { |
| 118 | "title" => "Complex Segments", |
| 119 | "id" => "#complex" |
| 120 | } |
| 121 | ] |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 122 | } |
| 123 | ] |
| 124 | }, |
| 125 | { |
| 126 | id => 'faq', |
Marc Kupietz | b82939b | 2021-09-07 22:45:38 +0200 | [diff] [blame] | 127 | title => 'FAQ' |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 128 | } |
| 129 | ]; |
| 130 | |
Akron | d512ea6 | 2019-10-24 15:50:04 +0200 | [diff] [blame] | 131 | $render = $app->navigation('doc', $navi); |
Marc Kupietz | fcadda6 | 2021-09-08 09:06:25 +0200 | [diff] [blame] | 132 | like($render, qr!/doc/development!, 'Path matches doc/development'); |
| 133 | like($render, qr!/doc/development/krill!, 'Path matches development/krill'); |
| 134 | like($render, qr!/doc/development/koral!, 'Path matches development/koral'); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 135 | like($render, qr!/doc/ql!, 'Path matches doc/ql'); |
| 136 | like($render, qr!/doc/ql/cosmas2!, 'Path matches doc/ql/cosmas2'); |
| 137 | like($render, qr!/doc/ql/poliqarp-plus!, 'Path matches doc/ql/poliqarp-plus'); |
| 138 | like($render, qr!/doc/ql/poliqarp-plus#segments!, |
| 139 | 'Path matches doc/ql/poliqarp-plus#segments'); |
| 140 | like($render, qr!/doc/ql/poliqarp-plus#complex!, |
| 141 | 'Path matches doc/ql/poliqarp-plus#complex'); |
| 142 | like($render, qr!/doc/faq!, 'Path matches doc/faq'); |
| 143 | |
Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 144 | ok($app->navi->exists('doc')); |
| 145 | ok(!$app->navi->exists('xy')); |
| 146 | is($app->navigation('xy'), '');; |
| 147 | |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 148 | |
| 149 | my $c = $app->build_controller; |
Marc Kupietz | fcadda6 | 2021-09-08 09:06:25 +0200 | [diff] [blame] | 150 | $c->stash(page => 'development'); |
Akron | d512ea6 | 2019-10-24 15:50:04 +0200 | [diff] [blame] | 151 | $render = $c->navigation('doc', $navi); |
Marc Kupietz | fcadda6 | 2021-09-08 09:06:25 +0200 | [diff] [blame] | 152 | like($render, qr!/doc/development!, 'Path matches doc/development'); |
| 153 | like($render, qr!/doc/development/krill!, 'Path matches development/krill'); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 154 | like($render, qr!/doc/ql!, 'Path matches doc/ql'); |
| 155 | like($render, qr!/doc/ql/poliqarp-plus#segments!, |
| 156 | 'Path matches doc/ql/poliqarp-plus#segments'); |
| 157 | like($render, qr!/doc/ql/poliqarp-plus#complex!, |
| 158 | 'Path matches doc/ql/poliqarp-plus#complex'); |
| 159 | like($render, qr!class="active".*?KorAP!, 'Active value for KorAP'); |
| 160 | |
| 161 | $c->stash(page => 'poliqarp-plus'); |
Akron | d512ea6 | 2019-10-24 15:50:04 +0200 | [diff] [blame] | 162 | $render = $c->navigation('doc', $navi); |
Marc Kupietz | fcadda6 | 2021-09-08 09:06:25 +0200 | [diff] [blame] | 163 | like($render, qr!/doc/development!, 'Path matches doc/development'); |
| 164 | like($render, qr!/doc/development/krill!, 'Path matches development/krill'); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 165 | like($render, qr!/doc/ql!, 'Path matches doc/ql'); |
| 166 | like($render, qr!/doc/ql/poliqarp-plus#segments!, |
| 167 | 'Path matches doc/ql/poliqarp-plus#segments'); |
| 168 | like($render, qr!/doc/ql/poliqarp-plus#complex!, |
| 169 | 'Path matches doc/ql/poliqarp-plus#complex'); |
| 170 | like($render, qr!class="active".*?Poliqarp\+!, 'Active value for Poliqarp+'); |
| 171 | |
| 172 | |
| 173 | $navi = [ |
| 174 | { |
Marc Kupietz | fcadda6 | 2021-09-08 09:06:25 +0200 | [diff] [blame] | 175 | id => 'development', |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 176 | title => 'KorAP', |
| 177 | items => [ |
| 178 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 179 | id => 'krill', |
| 180 | title => 'Krill', |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 181 | }, |
| 182 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 183 | id => 'koral', |
| 184 | title => 'Koral' |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 185 | } |
| 186 | ] |
| 187 | }, |
| 188 | { |
| 189 | title => 'Query Languages', |
| 190 | id => 'ql', |
Akron | 64833cc | 2021-09-08 17:19:27 +0200 | [diff] [blame] | 191 | class => 'folded', |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 192 | items => [ |
| 193 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 194 | title => 'Cosmas II', |
| 195 | id => 'cosmas2' |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 196 | }, |
| 197 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 198 | 'title' => 'Poliqarp+', |
| 199 | 'id' => 'poliqarp-plus', |
| 200 | 'class' => 'folded', |
| 201 | items => [ |
| 202 | { |
| 203 | "title" => "Simple Segments", |
| 204 | "id" => "#segments" |
| 205 | }, |
| 206 | { |
| 207 | "title" => "Complex Segments", |
| 208 | "id" => "#complex" |
| 209 | } |
| 210 | ] |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 211 | } |
| 212 | ] |
| 213 | }, |
| 214 | { |
| 215 | id => 'faq', |
Marc Kupietz | b82939b | 2021-09-07 22:45:38 +0200 | [diff] [blame] | 216 | title => 'FAQ' |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 217 | } |
| 218 | ]; |
Akron | d512ea6 | 2019-10-24 15:50:04 +0200 | [diff] [blame] | 219 | $render = $c->navigation('doc', $navi); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 220 | |
Marc Kupietz | fcadda6 | 2021-09-08 09:06:25 +0200 | [diff] [blame] | 221 | like($render, qr!/doc/development!, 'Path matches doc/development'); |
| 222 | like($render, qr!/doc/development/krill!, 'Path matches development/krill'); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 223 | like($render, qr!/doc/ql!, 'Path matches doc/ql'); |
| 224 | like($render, qr!/doc/ql/poliqarp-plus#segments!, |
| 225 | 'Path matches doc/ql/poliqarp-plus#segments'); |
| 226 | like($render, qr!/doc/ql/poliqarp-plus#complex!, |
| 227 | 'Path matches doc/ql/poliqarp-plus#complex'); |
| 228 | like($render, qr!class="folded active".*?Poliqarp\+!, 'Active and folded value for Poliqarp+'); |
| 229 | |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 230 | |
Akron | 64833cc | 2021-09-08 17:19:27 +0200 | [diff] [blame] | 231 | $c->stash(page => 'cosmas2'); |
| 232 | $render = $c->navigation('doc', $navi); |
| 233 | |
| 234 | like($render, qr!\<li class=\"folded\">\s*<a href="/doc/ql\#page-top">Query Languages</a>\s*<ul class="nav nav-doc active">\s*<li class="active"><a href="/doc/ql/cosmas2\#page-top">Cosmas II</a></li>!); |
| 235 | |
| 236 | delete $c->stash->{cosmas2}; |
| 237 | |
| 238 | |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 239 | # Test for translations |
| 240 | $navi = [ |
| 241 | { |
Marc Kupietz | fcadda6 | 2021-09-08 09:06:25 +0200 | [diff] [blame] | 242 | id => 'development', |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 243 | title => 'KorAP', |
| 244 | items => [ |
| 245 | { |
| 246 | id => 'krill', |
| 247 | title => 'Krill', |
| 248 | } |
| 249 | ] |
| 250 | }, |
| 251 | { |
| 252 | id => 'faq', |
Marc Kupietz | b82939b | 2021-09-07 22:45:38 +0200 | [diff] [blame] | 253 | title => 'FAQ' |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 254 | } |
| 255 | ]; |
| 256 | |
Akron | d512ea6 | 2019-10-24 15:50:04 +0200 | [diff] [blame] | 257 | $render = $app->navigation('doc', $navi); |
Marc Kupietz | fcadda6 | 2021-09-08 09:06:25 +0200 | [diff] [blame] | 258 | like($render, qr!/doc/development!, 'Path matches doc/development'); |
| 259 | like($render, qr!/doc/development/krill!, 'Path matches development/krill'); |
| 260 | like($render, qr!<a href="/doc/development/krill(?:#[^"]+)?">Krill</a>!, |
| 261 | 'Path matches development/krill'); |
Marc Kupietz | b82939b | 2021-09-07 22:45:38 +0200 | [diff] [blame] | 262 | like($render, qr!<a href="/doc/faq(?:#[^"]+)?">FAQ</a>!, |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 263 | 'Path matches FAQ'); |
| 264 | |
| 265 | # Change preferred language |
| 266 | $languages = [qw/de en/]; |
| 267 | |
Akron | d512ea6 | 2019-10-24 15:50:04 +0200 | [diff] [blame] | 268 | $render = $app->navigation('doc', $navi); |
Marc Kupietz | fcadda6 | 2021-09-08 09:06:25 +0200 | [diff] [blame] | 269 | like($render, qr!/doc/development!, 'Path matches doc/development'); |
| 270 | like($render, qr!/doc/development/krill!, 'Path matches development/krill'); |
| 271 | like($render, qr!<a href="/doc/development/krill(?:#[^"]+)?">Krill</a>!, |
| 272 | 'Path matches development/krill'); |
Marc Kupietz | b82939b | 2021-09-07 22:45:38 +0200 | [diff] [blame] | 273 | like($render, qr!<a href="/doc/faq(?:#[^"]+)?">FAQ</a>!, |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 274 | 'Path matches FAQ'); |
| 275 | |
Akron | 64833cc | 2021-09-08 17:19:27 +0200 | [diff] [blame] | 276 | |
| 277 | |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 278 | done_testing; |
| 279 | |
| 280 | __END__ |
| 281 | |