blob: b1a9f8ebecc123cfbb49e4400127d1f27e4c2266 [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 => {
25 faq => 'F.A.Q.',
26 '#default-foundries' => 'Default Foundries',
27 },
28 de => {
29 faq => 'Häufige Fragen',
30 '#default-foundries' => 'Standard Foundries'
31 }
32 }
33 }
34});
35
Nils Diewalda898dac2015-05-06 21:04:16 +000036my $navi = [
37 {
38 id => 'korap',
39 title => 'KorAP'
40 }
41];
42
Akrond512ea62019-10-24 15:50:04 +020043my $render = $app->navigation('doc', $navi);
Nils Diewalda898dac2015-05-06 21:04:16 +000044like($render, qr!/doc/korap!, 'Path matches doc/korap');
45like($render, qr!KorAP!, 'Title matches');
46
47$navi = [
48 {
49 id => 'korap',
50 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);
Nils Diewalda898dac2015-05-06 21:04:16 +000059like($render, qr!/doc/korap!, 'Path matches doc/korap');
60like($render, qr!KorAP!, 'Title matches');
61like($render, qr!/doc/krill!, 'Path matches doc/krill');
62like($render, qr!Krill!, 'Title matches');
63
64$navi = [
65 {
66 id => 'korap',
67 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',
77 title => 'F.A.Q.'
78 }
79];
80
Akrond512ea62019-10-24 15:50:04 +020081$render = $app->navigation('doc', $navi);
Nils Diewalda898dac2015-05-06 21:04:16 +000082like($render, qr!/doc/korap!, 'Path matches doc/korap');
83like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
84like($render, qr!/doc/faq!, 'Path matches doc/faq');
85
86$navi = [
87 {
88 id => 'korap',
89 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',
127 title => 'F.A.Q.'
128 }
129];
130
Akrond512ea62019-10-24 15:50:04 +0200131$render = $app->navigation('doc', $navi);
Nils Diewalda898dac2015-05-06 21:04:16 +0000132like($render, qr!/doc/korap!, 'Path matches doc/korap');
133like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
134like($render, qr!/doc/korap/koral!, 'Path matches korap/koral');
135like($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;
150$c->stash(page => 'korap');
Akrond512ea62019-10-24 15:50:04 +0200151$render = $c->navigation('doc', $navi);
Nils Diewalda898dac2015-05-06 21:04:16 +0000152like($render, qr!/doc/korap!, 'Path matches doc/korap');
153like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
154like($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);
Nils Diewalda898dac2015-05-06 21:04:16 +0000163like($render, qr!/doc/korap!, 'Path matches doc/korap');
164like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
165like($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 {
175 id => 'korap',
176 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',
191 items => [
192 {
Akron0dc10902017-09-01 18:00:16 +0200193 title => 'Cosmas II',
194 id => 'cosmas2'
Nils Diewalda898dac2015-05-06 21:04:16 +0000195 },
196 {
Akron0dc10902017-09-01 18:00:16 +0200197 'title' => 'Poliqarp+',
198 'id' => 'poliqarp-plus',
199 'class' => 'folded',
200 items => [
201 {
202 "title" => "Simple Segments",
203 "id" => "#segments"
204 },
205 {
206 "title" => "Complex Segments",
207 "id" => "#complex"
208 }
209 ]
Nils Diewalda898dac2015-05-06 21:04:16 +0000210 }
211 ]
212 },
213 {
214 id => 'faq',
215 title => 'F.A.Q.'
216 }
217];
Akrond512ea62019-10-24 15:50:04 +0200218$render = $c->navigation('doc', $navi);
Nils Diewalda898dac2015-05-06 21:04:16 +0000219
220like($render, qr!/doc/korap!, 'Path matches doc/korap');
221like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
222like($render, qr!/doc/ql!, 'Path matches doc/ql');
223like($render, qr!/doc/ql/poliqarp-plus#segments!,
224 'Path matches doc/ql/poliqarp-plus#segments');
225like($render, qr!/doc/ql/poliqarp-plus#complex!,
226 'Path matches doc/ql/poliqarp-plus#complex');
227like($render, qr!class="folded active".*?Poliqarp\+!, 'Active and folded value for Poliqarp+');
228
Akron0dc10902017-09-01 18:00:16 +0200229
230# Test for translations
231$navi = [
232 {
233 id => 'korap',
234 title => 'KorAP',
235 items => [
236 {
237 id => 'krill',
238 title => 'Krill',
239 }
240 ]
241 },
242 {
243 id => 'faq',
244 title => 'F.A.Q.'
245 }
246];
247
Akrond512ea62019-10-24 15:50:04 +0200248$render = $app->navigation('doc', $navi);
Akron0dc10902017-09-01 18:00:16 +0200249like($render, qr!/doc/korap!, 'Path matches doc/korap');
250like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
Akron2dd87542017-11-17 11:21:01 +0100251like($render, qr!<a href="/doc/korap/krill(?:#[^"]+)?">Krill</a>!,
Akron0dc10902017-09-01 18:00:16 +0200252 'Path matches korap/krill');
Akron2dd87542017-11-17 11:21:01 +0100253like($render, qr!<a href="/doc/faq(?:#[^"]+)?">F\.A\.Q\.</a>!,
Akron0dc10902017-09-01 18:00:16 +0200254 'Path matches FAQ');
255
256# Change preferred language
257$languages = [qw/de en/];
258
Akrond512ea62019-10-24 15:50:04 +0200259$render = $app->navigation('doc', $navi);
Akron0dc10902017-09-01 18:00:16 +0200260like($render, qr!/doc/korap!, 'Path matches doc/korap');
261like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
Akron2dd87542017-11-17 11:21:01 +0100262like($render, qr!<a href="/doc/korap/krill(?:#[^"]+)?">Krill</a>!,
Akron0dc10902017-09-01 18:00:16 +0200263 'Path matches korap/krill');
Akron2dd87542017-11-17 11:21:01 +0100264like($render, qr!<a href="/doc/faq(?:#[^"]+)?">Häufige Fragen</a>!,
Akron0dc10902017-09-01 18:00:16 +0200265 'Path matches FAQ');
266
Nils Diewalda898dac2015-05-06 21:04:16 +0000267done_testing;
268
269__END__
270