blob: 1f56c9943279b6c7a43a567c839ad4df731e04a4 [file] [log] [blame]
Nils Diewalda898dac2015-05-06 21:04:16 +00001use Mojo::Base -strict;
Nils Diewalda898dac2015-05-06 21:04:16 +00002use Mojolicious::Lite;
3use Test::More;
4use Test::Mojo;
Akron0dc10902017-09-01 18:00:16 +02005use utf8;
Nils Diewalda898dac2015-05-06 21:04:16 +00006
7my $t = Test::Mojo->new;
8my $app = $t->app;
9
10# Add additional plugin path
11push(@{$app->plugins->namespaces}, 'Kalamar::Plugin');
12
13# Establish test route
Akron254fe212019-10-24 14:33:28 +020014$app->routes->get('/doc/:scope/:page')->to(cb => sub {}, scope => undef)->name('doc');
Akronb161fcc2024-10-14 16:26:12 +020015$app->routes->get('/settings/:scope/:page')->to(cb => sub {}, scope => undef)->name('settings');
16
Nils Diewalda898dac2015-05-06 21:04:16 +000017
18# Load plugin to test
Akron41a190a2019-10-16 18:01:02 +020019$app->plugin('KalamarPages');
Nils Diewalda898dac2015-05-06 21:04:16 +000020
Akron0dc10902017-09-01 18:00:16 +020021my $languages = [qw/en de/];
22$app->plugin('Localize' => {
23 dict => {
24 Nav => {
25 _ => sub { $languages },
26 -en => {
Marc Kupietzb82939b2021-09-07 22:45:38 +020027 faq => 'FAQ',
Akron0dc10902017-09-01 18:00:16 +020028 '#default-foundries' => 'Default Foundries',
29 },
30 de => {
Marc Kupietzb82939b2021-09-07 22:45:38 +020031 faq => 'FAQ',
Akron0dc10902017-09-01 18:00:16 +020032 '#default-foundries' => 'Standard Foundries'
33 }
34 }
35 }
36});
37
Nils Diewalda898dac2015-05-06 21:04:16 +000038my $navi = [
39 {
Marc Kupietzfcadda62021-09-08 09:06:25 +020040 id => 'development',
Nils Diewalda898dac2015-05-06 21:04:16 +000041 title => 'KorAP'
42 }
43];
44
Akrond512ea62019-10-24 15:50:04 +020045my $render = $app->navigation('doc', $navi);
Marc Kupietzfcadda62021-09-08 09:06:25 +020046like($render, qr!/doc/development!, 'Path matches doc/development');
Nils Diewalda898dac2015-05-06 21:04:16 +000047like($render, qr!KorAP!, 'Title matches');
48
49$navi = [
50 {
Marc Kupietzfcadda62021-09-08 09:06:25 +020051 id => 'development',
Nils Diewalda898dac2015-05-06 21:04:16 +000052 title => 'KorAP'
53 },
54 {
55 id => 'krill',
56 title => 'Krill'
57 }
58];
59
Akrond512ea62019-10-24 15:50:04 +020060$render = $app->navigation('doc', $navi);
Marc Kupietzfcadda62021-09-08 09:06:25 +020061like($render, qr!/doc/development!, 'Path matches doc/development');
Nils Diewalda898dac2015-05-06 21:04:16 +000062like($render, qr!KorAP!, 'Title matches');
63like($render, qr!/doc/krill!, 'Path matches doc/krill');
64like($render, qr!Krill!, 'Title matches');
65
66$navi = [
67 {
Marc Kupietzfcadda62021-09-08 09:06:25 +020068 id => 'development',
Nils Diewalda898dac2015-05-06 21:04:16 +000069 title => 'KorAP',
70 items => [
71 {
Akron0dc10902017-09-01 18:00:16 +020072 id => 'krill',
73 title => 'Krill',
Nils Diewalda898dac2015-05-06 21:04:16 +000074 }
75 ]
76 },
77 {
78 id => 'faq',
Marc Kupietzb82939b2021-09-07 22:45:38 +020079 title => 'FAQ'
Nils Diewalda898dac2015-05-06 21:04:16 +000080 }
81];
82
Akrond512ea62019-10-24 15:50:04 +020083$render = $app->navigation('doc', $navi);
Marc Kupietzfcadda62021-09-08 09:06:25 +020084like($render, qr!/doc/development!, 'Path matches doc/development');
85like($render, qr!/doc/development/krill!, 'Path matches development/krill');
Nils Diewalda898dac2015-05-06 21:04:16 +000086like($render, qr!/doc/faq!, 'Path matches doc/faq');
87
88$navi = [
89 {
Marc Kupietzfcadda62021-09-08 09:06:25 +020090 id => 'development',
Nils Diewalda898dac2015-05-06 21:04:16 +000091 title => 'KorAP',
92 items => [
93 {
Akron0dc10902017-09-01 18:00:16 +020094 id => 'krill',
95 title => 'Krill',
Nils Diewalda898dac2015-05-06 21:04:16 +000096 },
97 {
Akron0dc10902017-09-01 18:00:16 +020098 id => 'koral',
99 title => 'Koral'
Nils Diewalda898dac2015-05-06 21:04:16 +0000100 }
101 ]
102 },
103 {
104 title => 'Query Languages',
105 id => 'ql',
106 items => [
107 {
Akron0dc10902017-09-01 18:00:16 +0200108 title => 'Cosmas II',
109 id => 'cosmas2'
Nils Diewalda898dac2015-05-06 21:04:16 +0000110 },
111 {
Akron0dc10902017-09-01 18:00:16 +0200112 '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 Diewalda898dac2015-05-06 21:04:16 +0000124 }
125 ]
126 },
127 {
128 id => 'faq',
Marc Kupietzb82939b2021-09-07 22:45:38 +0200129 title => 'FAQ'
Nils Diewalda898dac2015-05-06 21:04:16 +0000130 }
131];
132
Akrond512ea62019-10-24 15:50:04 +0200133$render = $app->navigation('doc', $navi);
Marc Kupietzfcadda62021-09-08 09:06:25 +0200134like($render, qr!/doc/development!, 'Path matches doc/development');
135like($render, qr!/doc/development/krill!, 'Path matches development/krill');
136like($render, qr!/doc/development/koral!, 'Path matches development/koral');
Nils Diewalda898dac2015-05-06 21:04:16 +0000137like($render, qr!/doc/ql!, 'Path matches doc/ql');
138like($render, qr!/doc/ql/cosmas2!, 'Path matches doc/ql/cosmas2');
139like($render, qr!/doc/ql/poliqarp-plus!, 'Path matches doc/ql/poliqarp-plus');
140like($render, qr!/doc/ql/poliqarp-plus#segments!,
141 'Path matches doc/ql/poliqarp-plus#segments');
142like($render, qr!/doc/ql/poliqarp-plus#complex!,
143 'Path matches doc/ql/poliqarp-plus#complex');
144like($render, qr!/doc/faq!, 'Path matches doc/faq');
145
Akron59992122019-10-29 11:28:45 +0100146ok($app->navi->exists('doc'));
147ok(!$app->navi->exists('xy'));
148is($app->navigation('xy'), '');;
149
Nils Diewalda898dac2015-05-06 21:04:16 +0000150
151my $c = $app->build_controller;
Marc Kupietzfcadda62021-09-08 09:06:25 +0200152$c->stash(page => 'development');
Akrond512ea62019-10-24 15:50:04 +0200153$render = $c->navigation('doc', $navi);
Marc Kupietzfcadda62021-09-08 09:06:25 +0200154like($render, qr!/doc/development!, 'Path matches doc/development');
155like($render, qr!/doc/development/krill!, 'Path matches development/krill');
Nils Diewalda898dac2015-05-06 21:04:16 +0000156like($render, qr!/doc/ql!, 'Path matches doc/ql');
157like($render, qr!/doc/ql/poliqarp-plus#segments!,
158 'Path matches doc/ql/poliqarp-plus#segments');
159like($render, qr!/doc/ql/poliqarp-plus#complex!,
160 'Path matches doc/ql/poliqarp-plus#complex');
161like($render, qr!class="active".*?KorAP!, 'Active value for KorAP');
162
163$c->stash(page => 'poliqarp-plus');
Akrond512ea62019-10-24 15:50:04 +0200164$render = $c->navigation('doc', $navi);
Marc Kupietzfcadda62021-09-08 09:06:25 +0200165like($render, qr!/doc/development!, 'Path matches doc/development');
166like($render, qr!/doc/development/krill!, 'Path matches development/krill');
Nils Diewalda898dac2015-05-06 21:04:16 +0000167like($render, qr!/doc/ql!, 'Path matches doc/ql');
168like($render, qr!/doc/ql/poliqarp-plus#segments!,
169 'Path matches doc/ql/poliqarp-plus#segments');
170like($render, qr!/doc/ql/poliqarp-plus#complex!,
171 'Path matches doc/ql/poliqarp-plus#complex');
172like($render, qr!class="active".*?Poliqarp\+!, 'Active value for Poliqarp+');
173
174
175$navi = [
176 {
Marc Kupietzfcadda62021-09-08 09:06:25 +0200177 id => 'development',
Nils Diewalda898dac2015-05-06 21:04:16 +0000178 title => 'KorAP',
179 items => [
180 {
Akron0dc10902017-09-01 18:00:16 +0200181 id => 'krill',
182 title => 'Krill',
Nils Diewalda898dac2015-05-06 21:04:16 +0000183 },
184 {
Akron0dc10902017-09-01 18:00:16 +0200185 id => 'koral',
186 title => 'Koral'
Nils Diewalda898dac2015-05-06 21:04:16 +0000187 }
188 ]
189 },
190 {
191 title => 'Query Languages',
192 id => 'ql',
Akron64833cc2021-09-08 17:19:27 +0200193 class => 'folded',
Nils Diewalda898dac2015-05-06 21:04:16 +0000194 items => [
195 {
Akron0dc10902017-09-01 18:00:16 +0200196 title => 'Cosmas II',
197 id => 'cosmas2'
Nils Diewalda898dac2015-05-06 21:04:16 +0000198 },
199 {
Akron0dc10902017-09-01 18:00:16 +0200200 '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 Diewalda898dac2015-05-06 21:04:16 +0000213 }
214 ]
215 },
216 {
217 id => 'faq',
Marc Kupietzb82939b2021-09-07 22:45:38 +0200218 title => 'FAQ'
Nils Diewalda898dac2015-05-06 21:04:16 +0000219 }
220];
Akrond512ea62019-10-24 15:50:04 +0200221$render = $c->navigation('doc', $navi);
Nils Diewalda898dac2015-05-06 21:04:16 +0000222
Marc Kupietzfcadda62021-09-08 09:06:25 +0200223like($render, qr!/doc/development!, 'Path matches doc/development');
224like($render, qr!/doc/development/krill!, 'Path matches development/krill');
Nils Diewalda898dac2015-05-06 21:04:16 +0000225like($render, qr!/doc/ql!, 'Path matches doc/ql');
226like($render, qr!/doc/ql/poliqarp-plus#segments!,
227 'Path matches doc/ql/poliqarp-plus#segments');
228like($render, qr!/doc/ql/poliqarp-plus#complex!,
229 'Path matches doc/ql/poliqarp-plus#complex');
230like($render, qr!class="folded active".*?Poliqarp\+!, 'Active and folded value for Poliqarp+');
231
Akron0dc10902017-09-01 18:00:16 +0200232
Akron64833cc2021-09-08 17:19:27 +0200233$c->stash(page => 'cosmas2');
234$render = $c->navigation('doc', $navi);
235
236like($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
238delete $c->stash->{cosmas2};
239
240
Akron0dc10902017-09-01 18:00:16 +0200241# Test for translations
242$navi = [
243 {
Marc Kupietzfcadda62021-09-08 09:06:25 +0200244 id => 'development',
Akron0dc10902017-09-01 18:00:16 +0200245 title => 'KorAP',
246 items => [
247 {
248 id => 'krill',
249 title => 'Krill',
250 }
251 ]
252 },
253 {
254 id => 'faq',
Marc Kupietzb82939b2021-09-07 22:45:38 +0200255 title => 'FAQ'
Akron0dc10902017-09-01 18:00:16 +0200256 }
257];
258
Akrond512ea62019-10-24 15:50:04 +0200259$render = $app->navigation('doc', $navi);
Marc Kupietzfcadda62021-09-08 09:06:25 +0200260like($render, qr!/doc/development!, 'Path matches doc/development');
261like($render, qr!/doc/development/krill!, 'Path matches development/krill');
262like($render, qr!<a href="/doc/development/krill(?:#[^"]+)?">Krill</a>!,
263 'Path matches development/krill');
Marc Kupietzb82939b2021-09-07 22:45:38 +0200264like($render, qr!<a href="/doc/faq(?:#[^"]+)?">FAQ</a>!,
Akron0dc10902017-09-01 18:00:16 +0200265 'Path matches FAQ');
266
267# Change preferred language
268$languages = [qw/de en/];
269
Akrond512ea62019-10-24 15:50:04 +0200270$render = $app->navigation('doc', $navi);
Marc Kupietzfcadda62021-09-08 09:06:25 +0200271like($render, qr!/doc/development!, 'Path matches doc/development');
272like($render, qr!/doc/development/krill!, 'Path matches development/krill');
273like($render, qr!<a href="/doc/development/krill(?:#[^"]+)?">Krill</a>!,
274 'Path matches development/krill');
Marc Kupietzb82939b2021-09-07 22:45:38 +0200275like($render, qr!<a href="/doc/faq(?:#[^"]+)?">FAQ</a>!,
Akron0dc10902017-09-01 18:00:16 +0200276 'Path matches FAQ');
277
Akronb161fcc2024-10-14 16:26:12 +0200278# Create settings realm
279$app->navi->add(settings => (
280 'OAuth', 'oauth'
281));
Akron64833cc2021-09-08 17:19:27 +0200282
Akronb161fcc2024-10-14 16:26:12 +0200283# Create settings realm
284$app->navi->add(settings => (
285 'Marketplace', 'marketplace'
286));
287
288$render = $app->navigation('settings');
289
290like($render, qr!/settings/oauth#page-top!);
291like($render, qr!/settings/marketplace#page-top!);
292
293my @list = $app->navi->list('settings');
294
295is($list[0]->{url}, '/settings/oauth#page-top');
296is($list[0]->{title}, 'OAuth');
297is($list[1]->{url}, '/settings/marketplace#page-top');
298is($list[1]->{title}, 'Marketplace');
Akron64833cc2021-09-08 17:19:27 +0200299
Nils Diewalda898dac2015-05-06 21:04:16 +0000300done_testing;
301
302__END__
303