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