blob: 576db846a7769c3307bc3cf09c7ba9593ace57b7 [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
Akron1b1a2712018-12-21 14:59:05 +010014$app->routes->get('/doc/:page')->to(cb => sub {})->name('doc1');
15$app->routes->get('/doc/*scope/:page')->to(cb => sub {})->name('doc2');
Nils Diewalda898dac2015-05-06 21:04:16 +000016
17# Load plugin to test
18$app->plugin('KalamarHelpers');
19
Akron0dc10902017-09-01 18:00:16 +020020my $languages = [qw/en de/];
21$app->plugin('Localize' => {
22 dict => {
23 Nav => {
24 _ => sub { $languages },
25 -en => {
26 faq => 'F.A.Q.',
27 '#default-foundries' => 'Default Foundries',
28 },
29 de => {
30 faq => 'Häufige Fragen',
31 '#default-foundries' => 'Standard Foundries'
32 }
33 }
34 }
35});
36
Nils Diewalda898dac2015-05-06 21:04:16 +000037my $navi = [
38 {
39 id => 'korap',
40 title => 'KorAP'
41 }
42];
43
44my $render = $app->doc_navi($navi);
45like($render, qr!/doc/korap!, 'Path matches doc/korap');
46like($render, qr!KorAP!, 'Title matches');
47
48$navi = [
49 {
50 id => 'korap',
51 title => 'KorAP'
52 },
53 {
54 id => 'krill',
55 title => 'Krill'
56 }
57];
58
59$render = $app->doc_navi($navi);
60like($render, qr!/doc/korap!, 'Path matches doc/korap');
61like($render, qr!KorAP!, 'Title matches');
62like($render, qr!/doc/krill!, 'Path matches doc/krill');
63like($render, qr!Krill!, 'Title matches');
64
65$navi = [
66 {
67 id => 'korap',
68 title => 'KorAP',
69 items => [
70 {
Akron0dc10902017-09-01 18:00:16 +020071 id => 'krill',
72 title => 'Krill',
Nils Diewalda898dac2015-05-06 21:04:16 +000073 }
74 ]
75 },
76 {
77 id => 'faq',
78 title => 'F.A.Q.'
79 }
80];
81
82$render = $app->doc_navi($navi);
83like($render, qr!/doc/korap!, 'Path matches doc/korap');
84like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
85like($render, qr!/doc/faq!, 'Path matches doc/faq');
86
87$navi = [
88 {
89 id => 'korap',
90 title => 'KorAP',
91 items => [
92 {
Akron0dc10902017-09-01 18:00:16 +020093 id => 'krill',
94 title => 'Krill',
Nils Diewalda898dac2015-05-06 21:04:16 +000095 },
96 {
Akron0dc10902017-09-01 18:00:16 +020097 id => 'koral',
98 title => 'Koral'
Nils Diewalda898dac2015-05-06 21:04:16 +000099 }
100 ]
101 },
102 {
103 title => 'Query Languages',
104 id => 'ql',
105 items => [
106 {
Akron0dc10902017-09-01 18:00:16 +0200107 title => 'Cosmas II',
108 id => 'cosmas2'
Nils Diewalda898dac2015-05-06 21:04:16 +0000109 },
110 {
Akron0dc10902017-09-01 18:00:16 +0200111 'title' => 'Poliqarp+',
112 'id' => 'poliqarp-plus',
113 items => [
114 {
115 "title" => "Simple Segments",
116 "id" => "#segments"
117 },
118 {
119 "title" => "Complex Segments",
120 "id" => "#complex"
121 }
122 ]
Nils Diewalda898dac2015-05-06 21:04:16 +0000123 }
124 ]
125 },
126 {
127 id => 'faq',
128 title => 'F.A.Q.'
129 }
130];
131
132$render = $app->doc_navi($navi);
133like($render, qr!/doc/korap!, 'Path matches doc/korap');
134like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
135like($render, qr!/doc/korap/koral!, 'Path matches korap/koral');
136like($render, qr!/doc/ql!, 'Path matches doc/ql');
137like($render, qr!/doc/ql/cosmas2!, 'Path matches doc/ql/cosmas2');
138like($render, qr!/doc/ql/poliqarp-plus!, 'Path matches doc/ql/poliqarp-plus');
139like($render, qr!/doc/ql/poliqarp-plus#segments!,
140 'Path matches doc/ql/poliqarp-plus#segments');
141like($render, qr!/doc/ql/poliqarp-plus#complex!,
142 'Path matches doc/ql/poliqarp-plus#complex');
143like($render, qr!/doc/faq!, 'Path matches doc/faq');
144
145
146my $c = $app->build_controller;
147$c->stash(page => 'korap');
148$render = $c->doc_navi($navi);
149like($render, qr!/doc/korap!, 'Path matches doc/korap');
150like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
151like($render, qr!/doc/ql!, 'Path matches doc/ql');
152like($render, qr!/doc/ql/poliqarp-plus#segments!,
153 'Path matches doc/ql/poliqarp-plus#segments');
154like($render, qr!/doc/ql/poliqarp-plus#complex!,
155 'Path matches doc/ql/poliqarp-plus#complex');
156like($render, qr!class="active".*?KorAP!, 'Active value for KorAP');
157
158$c->stash(page => 'poliqarp-plus');
159$render = $c->doc_navi($navi);
160like($render, qr!/doc/korap!, 'Path matches doc/korap');
161like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
162like($render, qr!/doc/ql!, 'Path matches doc/ql');
163like($render, qr!/doc/ql/poliqarp-plus#segments!,
164 'Path matches doc/ql/poliqarp-plus#segments');
165like($render, qr!/doc/ql/poliqarp-plus#complex!,
166 'Path matches doc/ql/poliqarp-plus#complex');
167like($render, qr!class="active".*?Poliqarp\+!, 'Active value for Poliqarp+');
168
169
170$navi = [
171 {
172 id => 'korap',
173 title => 'KorAP',
174 items => [
175 {
Akron0dc10902017-09-01 18:00:16 +0200176 id => 'krill',
177 title => 'Krill',
Nils Diewalda898dac2015-05-06 21:04:16 +0000178 },
179 {
Akron0dc10902017-09-01 18:00:16 +0200180 id => 'koral',
181 title => 'Koral'
Nils Diewalda898dac2015-05-06 21:04:16 +0000182 }
183 ]
184 },
185 {
186 title => 'Query Languages',
187 id => 'ql',
188 items => [
189 {
Akron0dc10902017-09-01 18:00:16 +0200190 title => 'Cosmas II',
191 id => 'cosmas2'
Nils Diewalda898dac2015-05-06 21:04:16 +0000192 },
193 {
Akron0dc10902017-09-01 18:00:16 +0200194 'title' => 'Poliqarp+',
195 'id' => 'poliqarp-plus',
196 'class' => 'folded',
197 items => [
198 {
199 "title" => "Simple Segments",
200 "id" => "#segments"
201 },
202 {
203 "title" => "Complex Segments",
204 "id" => "#complex"
205 }
206 ]
Nils Diewalda898dac2015-05-06 21:04:16 +0000207 }
208 ]
209 },
210 {
211 id => 'faq',
212 title => 'F.A.Q.'
213 }
214];
215$render = $c->doc_navi($navi);
216
217like($render, qr!/doc/korap!, 'Path matches doc/korap');
218like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
219like($render, qr!/doc/ql!, 'Path matches doc/ql');
220like($render, qr!/doc/ql/poliqarp-plus#segments!,
221 'Path matches doc/ql/poliqarp-plus#segments');
222like($render, qr!/doc/ql/poliqarp-plus#complex!,
223 'Path matches doc/ql/poliqarp-plus#complex');
224like($render, qr!class="folded active".*?Poliqarp\+!, 'Active and folded value for Poliqarp+');
225
Akron0dc10902017-09-01 18:00:16 +0200226
227# Test for translations
228$navi = [
229 {
230 id => 'korap',
231 title => 'KorAP',
232 items => [
233 {
234 id => 'krill',
235 title => 'Krill',
236 }
237 ]
238 },
239 {
240 id => 'faq',
241 title => 'F.A.Q.'
242 }
243];
244
245$render = $app->doc_navi($navi);
246like($render, qr!/doc/korap!, 'Path matches doc/korap');
247like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
Akron2dd87542017-11-17 11:21:01 +0100248like($render, qr!<a href="/doc/korap/krill(?:#[^"]+)?">Krill</a>!,
Akron0dc10902017-09-01 18:00:16 +0200249 'Path matches korap/krill');
Akron2dd87542017-11-17 11:21:01 +0100250like($render, qr!<a href="/doc/faq(?:#[^"]+)?">F\.A\.Q\.</a>!,
Akron0dc10902017-09-01 18:00:16 +0200251 'Path matches FAQ');
252
253# Change preferred language
254$languages = [qw/de en/];
255
256$render = $app->doc_navi($navi);
257like($render, qr!/doc/korap!, 'Path matches doc/korap');
258like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
Akron2dd87542017-11-17 11:21:01 +0100259like($render, qr!<a href="/doc/korap/krill(?:#[^"]+)?">Krill</a>!,
Akron0dc10902017-09-01 18:00:16 +0200260 'Path matches korap/krill');
Akron2dd87542017-11-17 11:21:01 +0100261like($render, qr!<a href="/doc/faq(?:#[^"]+)?">Häufige Fragen</a>!,
Akron0dc10902017-09-01 18:00:16 +0200262 'Path matches FAQ');
263
264
Akron1b1a2712018-12-21 14:59:05 +0100265is($app->doc_link_to('privacy', 'privacy'), '<a class="doc-link" href="/doc/privacy">privacy</a>');
266is($app->doc_link_to('privacy', 'korap', 'privacy'), '<a class="doc-link" href="/doc/korap/privacy">privacy</a>');
267
Nils Diewalda898dac2015-05-06 21:04:16 +0000268done_testing;
269
270__END__
271