blob: bcb9c93df71f3d7cb4d477f143a200945ef7f0d6 [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');
Nils Diewalda898dac2015-05-06 21:04:16 +000015
16# Load plugin to test
Akron41a190a2019-10-16 18:01:02 +020017$app->plugin('KalamarPages');
Nils Diewalda898dac2015-05-06 21:04:16 +000018
Akron0dc10902017-09-01 18:00:16 +020019my $languages = [qw/en de/];
20$app->plugin('Localize' => {
21 dict => {
22 Nav => {
23 _ => sub { $languages },
24 -en => {
Marc Kupietzb82939b2021-09-07 22:45:38 +020025 faq => 'FAQ',
Akron0dc10902017-09-01 18:00:16 +020026 '#default-foundries' => 'Default Foundries',
27 },
28 de => {
Marc Kupietzb82939b2021-09-07 22:45:38 +020029 faq => 'FAQ',
Akron0dc10902017-09-01 18:00:16 +020030 '#default-foundries' => 'Standard Foundries'
31 }
32 }
33 }
34});
35
Nils Diewalda898dac2015-05-06 21:04:16 +000036my $navi = [
37 {
Marc Kupietzfcadda62021-09-08 09:06:25 +020038 id => 'development',
Nils Diewalda898dac2015-05-06 21:04:16 +000039 title => 'KorAP'
40 }
41];
42
Akrond512ea62019-10-24 15:50:04 +020043my $render = $app->navigation('doc', $navi);
Marc Kupietzfcadda62021-09-08 09:06:25 +020044like($render, qr!/doc/development!, 'Path matches doc/development');
Nils Diewalda898dac2015-05-06 21:04:16 +000045like($render, qr!KorAP!, 'Title matches');
46
47$navi = [
48 {
Marc Kupietzfcadda62021-09-08 09:06:25 +020049 id => 'development',
Nils Diewalda898dac2015-05-06 21:04:16 +000050 title => 'KorAP'
51 },
52 {
53 id => 'krill',
54 title => 'Krill'
55 }
56];
57
Akrond512ea62019-10-24 15:50:04 +020058$render = $app->navigation('doc', $navi);
Marc Kupietzfcadda62021-09-08 09:06:25 +020059like($render, qr!/doc/development!, 'Path matches doc/development');
Nils Diewalda898dac2015-05-06 21:04:16 +000060like($render, qr!KorAP!, 'Title matches');
61like($render, qr!/doc/krill!, 'Path matches doc/krill');
62like($render, qr!Krill!, 'Title matches');
63
64$navi = [
65 {
Marc Kupietzfcadda62021-09-08 09:06:25 +020066 id => 'development',
Nils Diewalda898dac2015-05-06 21:04:16 +000067 title => 'KorAP',
68 items => [
69 {
Akron0dc10902017-09-01 18:00:16 +020070 id => 'krill',
71 title => 'Krill',
Nils Diewalda898dac2015-05-06 21:04:16 +000072 }
73 ]
74 },
75 {
76 id => 'faq',
Marc Kupietzb82939b2021-09-07 22:45:38 +020077 title => 'FAQ'
Nils Diewalda898dac2015-05-06 21:04:16 +000078 }
79];
80
Akrond512ea62019-10-24 15:50:04 +020081$render = $app->navigation('doc', $navi);
Marc Kupietzfcadda62021-09-08 09:06:25 +020082like($render, qr!/doc/development!, 'Path matches doc/development');
83like($render, qr!/doc/development/krill!, 'Path matches development/krill');
Nils Diewalda898dac2015-05-06 21:04:16 +000084like($render, qr!/doc/faq!, 'Path matches doc/faq');
85
86$navi = [
87 {
Marc Kupietzfcadda62021-09-08 09:06:25 +020088 id => 'development',
Nils Diewalda898dac2015-05-06 21:04:16 +000089 title => 'KorAP',
90 items => [
91 {
Akron0dc10902017-09-01 18:00:16 +020092 id => 'krill',
93 title => 'Krill',
Nils Diewalda898dac2015-05-06 21:04:16 +000094 },
95 {
Akron0dc10902017-09-01 18:00:16 +020096 id => 'koral',
97 title => 'Koral'
Nils Diewalda898dac2015-05-06 21:04:16 +000098 }
99 ]
100 },
101 {
102 title => 'Query Languages',
103 id => 'ql',
104 items => [
105 {
Akron0dc10902017-09-01 18:00:16 +0200106 title => 'Cosmas II',
107 id => 'cosmas2'
Nils Diewalda898dac2015-05-06 21:04:16 +0000108 },
109 {
Akron0dc10902017-09-01 18:00:16 +0200110 '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 Diewalda898dac2015-05-06 21:04:16 +0000122 }
123 ]
124 },
125 {
126 id => 'faq',
Marc Kupietzb82939b2021-09-07 22:45:38 +0200127 title => 'FAQ'
Nils Diewalda898dac2015-05-06 21:04:16 +0000128 }
129];
130
Akrond512ea62019-10-24 15:50:04 +0200131$render = $app->navigation('doc', $navi);
Marc Kupietzfcadda62021-09-08 09:06:25 +0200132like($render, qr!/doc/development!, 'Path matches doc/development');
133like($render, qr!/doc/development/krill!, 'Path matches development/krill');
134like($render, qr!/doc/development/koral!, 'Path matches development/koral');
Nils Diewalda898dac2015-05-06 21:04:16 +0000135like($render, qr!/doc/ql!, 'Path matches doc/ql');
136like($render, qr!/doc/ql/cosmas2!, 'Path matches doc/ql/cosmas2');
137like($render, qr!/doc/ql/poliqarp-plus!, 'Path matches doc/ql/poliqarp-plus');
138like($render, qr!/doc/ql/poliqarp-plus#segments!,
139 'Path matches doc/ql/poliqarp-plus#segments');
140like($render, qr!/doc/ql/poliqarp-plus#complex!,
141 'Path matches doc/ql/poliqarp-plus#complex');
142like($render, qr!/doc/faq!, 'Path matches doc/faq');
143
Akron59992122019-10-29 11:28:45 +0100144ok($app->navi->exists('doc'));
145ok(!$app->navi->exists('xy'));
146is($app->navigation('xy'), '');;
147
Nils Diewalda898dac2015-05-06 21:04:16 +0000148
149my $c = $app->build_controller;
Marc Kupietzfcadda62021-09-08 09:06:25 +0200150$c->stash(page => 'development');
Akrond512ea62019-10-24 15:50:04 +0200151$render = $c->navigation('doc', $navi);
Marc Kupietzfcadda62021-09-08 09:06:25 +0200152like($render, qr!/doc/development!, 'Path matches doc/development');
153like($render, qr!/doc/development/krill!, 'Path matches development/krill');
Nils Diewalda898dac2015-05-06 21:04:16 +0000154like($render, qr!/doc/ql!, 'Path matches doc/ql');
155like($render, qr!/doc/ql/poliqarp-plus#segments!,
156 'Path matches doc/ql/poliqarp-plus#segments');
157like($render, qr!/doc/ql/poliqarp-plus#complex!,
158 'Path matches doc/ql/poliqarp-plus#complex');
159like($render, qr!class="active".*?KorAP!, 'Active value for KorAP');
160
161$c->stash(page => 'poliqarp-plus');
Akrond512ea62019-10-24 15:50:04 +0200162$render = $c->navigation('doc', $navi);
Marc Kupietzfcadda62021-09-08 09:06:25 +0200163like($render, qr!/doc/development!, 'Path matches doc/development');
164like($render, qr!/doc/development/krill!, 'Path matches development/krill');
Nils Diewalda898dac2015-05-06 21:04:16 +0000165like($render, qr!/doc/ql!, 'Path matches doc/ql');
166like($render, qr!/doc/ql/poliqarp-plus#segments!,
167 'Path matches doc/ql/poliqarp-plus#segments');
168like($render, qr!/doc/ql/poliqarp-plus#complex!,
169 'Path matches doc/ql/poliqarp-plus#complex');
170like($render, qr!class="active".*?Poliqarp\+!, 'Active value for Poliqarp+');
171
172
173$navi = [
174 {
Marc Kupietzfcadda62021-09-08 09:06:25 +0200175 id => 'development',
Nils Diewalda898dac2015-05-06 21:04:16 +0000176 title => 'KorAP',
177 items => [
178 {
Akron0dc10902017-09-01 18:00:16 +0200179 id => 'krill',
180 title => 'Krill',
Nils Diewalda898dac2015-05-06 21:04:16 +0000181 },
182 {
Akron0dc10902017-09-01 18:00:16 +0200183 id => 'koral',
184 title => 'Koral'
Nils Diewalda898dac2015-05-06 21:04:16 +0000185 }
186 ]
187 },
188 {
189 title => 'Query Languages',
190 id => 'ql',
Akron64833cc2021-09-08 17:19:27 +0200191 class => 'folded',
Nils Diewalda898dac2015-05-06 21:04:16 +0000192 items => [
193 {
Akron0dc10902017-09-01 18:00:16 +0200194 title => 'Cosmas II',
195 id => 'cosmas2'
Nils Diewalda898dac2015-05-06 21:04:16 +0000196 },
197 {
Akron0dc10902017-09-01 18:00:16 +0200198 '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 Diewalda898dac2015-05-06 21:04:16 +0000211 }
212 ]
213 },
214 {
215 id => 'faq',
Marc Kupietzb82939b2021-09-07 22:45:38 +0200216 title => 'FAQ'
Nils Diewalda898dac2015-05-06 21:04:16 +0000217 }
218];
Akrond512ea62019-10-24 15:50:04 +0200219$render = $c->navigation('doc', $navi);
Nils Diewalda898dac2015-05-06 21:04:16 +0000220
Marc Kupietzfcadda62021-09-08 09:06:25 +0200221like($render, qr!/doc/development!, 'Path matches doc/development');
222like($render, qr!/doc/development/krill!, 'Path matches development/krill');
Nils Diewalda898dac2015-05-06 21:04:16 +0000223like($render, qr!/doc/ql!, 'Path matches doc/ql');
224like($render, qr!/doc/ql/poliqarp-plus#segments!,
225 'Path matches doc/ql/poliqarp-plus#segments');
226like($render, qr!/doc/ql/poliqarp-plus#complex!,
227 'Path matches doc/ql/poliqarp-plus#complex');
228like($render, qr!class="folded active".*?Poliqarp\+!, 'Active and folded value for Poliqarp+');
229
Akron0dc10902017-09-01 18:00:16 +0200230
Akron64833cc2021-09-08 17:19:27 +0200231$c->stash(page => 'cosmas2');
232$render = $c->navigation('doc', $navi);
233
234like($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
236delete $c->stash->{cosmas2};
237
238
Akron0dc10902017-09-01 18:00:16 +0200239# Test for translations
240$navi = [
241 {
Marc Kupietzfcadda62021-09-08 09:06:25 +0200242 id => 'development',
Akron0dc10902017-09-01 18:00:16 +0200243 title => 'KorAP',
244 items => [
245 {
246 id => 'krill',
247 title => 'Krill',
248 }
249 ]
250 },
251 {
252 id => 'faq',
Marc Kupietzb82939b2021-09-07 22:45:38 +0200253 title => 'FAQ'
Akron0dc10902017-09-01 18:00:16 +0200254 }
255];
256
Akrond512ea62019-10-24 15:50:04 +0200257$render = $app->navigation('doc', $navi);
Marc Kupietzfcadda62021-09-08 09:06:25 +0200258like($render, qr!/doc/development!, 'Path matches doc/development');
259like($render, qr!/doc/development/krill!, 'Path matches development/krill');
260like($render, qr!<a href="/doc/development/krill(?:#[^"]+)?">Krill</a>!,
261 'Path matches development/krill');
Marc Kupietzb82939b2021-09-07 22:45:38 +0200262like($render, qr!<a href="/doc/faq(?:#[^"]+)?">FAQ</a>!,
Akron0dc10902017-09-01 18:00:16 +0200263 'Path matches FAQ');
264
265# Change preferred language
266$languages = [qw/de en/];
267
Akrond512ea62019-10-24 15:50:04 +0200268$render = $app->navigation('doc', $navi);
Marc Kupietzfcadda62021-09-08 09:06:25 +0200269like($render, qr!/doc/development!, 'Path matches doc/development');
270like($render, qr!/doc/development/krill!, 'Path matches development/krill');
271like($render, qr!<a href="/doc/development/krill(?:#[^"]+)?">Krill</a>!,
272 'Path matches development/krill');
Marc Kupietzb82939b2021-09-07 22:45:38 +0200273like($render, qr!<a href="/doc/faq(?:#[^"]+)?">FAQ</a>!,
Akron0dc10902017-09-01 18:00:16 +0200274 'Path matches FAQ');
275
Akron64833cc2021-09-08 17:19:27 +0200276
277
Nils Diewalda898dac2015-05-06 21:04:16 +0000278done_testing;
279
280__END__
281