blob: ce522c726f81597b2987e5225e8c0687ad43cfa9 [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
14$app->routes->get('/doc/(*scope)/:page')->to(cb => sub {})->name('doc');
15
16# Load plugin to test
17$app->plugin('KalamarHelpers');
18
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
43my $render = $app->doc_navi($navi);
44like($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
58$render = $app->doc_navi($navi);
59like($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
81$render = $app->doc_navi($navi);
82like($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
131$render = $app->doc_navi($navi);
132like($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
144
145my $c = $app->build_controller;
146$c->stash(page => 'korap');
147$render = $c->doc_navi($navi);
148like($render, qr!/doc/korap!, 'Path matches doc/korap');
149like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
150like($render, qr!/doc/ql!, 'Path matches doc/ql');
151like($render, qr!/doc/ql/poliqarp-plus#segments!,
152 'Path matches doc/ql/poliqarp-plus#segments');
153like($render, qr!/doc/ql/poliqarp-plus#complex!,
154 'Path matches doc/ql/poliqarp-plus#complex');
155like($render, qr!class="active".*?KorAP!, 'Active value for KorAP');
156
157$c->stash(page => 'poliqarp-plus');
158$render = $c->doc_navi($navi);
159like($render, qr!/doc/korap!, 'Path matches doc/korap');
160like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
161like($render, qr!/doc/ql!, 'Path matches doc/ql');
162like($render, qr!/doc/ql/poliqarp-plus#segments!,
163 'Path matches doc/ql/poliqarp-plus#segments');
164like($render, qr!/doc/ql/poliqarp-plus#complex!,
165 'Path matches doc/ql/poliqarp-plus#complex');
166like($render, qr!class="active".*?Poliqarp\+!, 'Active value for Poliqarp+');
167
168
169$navi = [
170 {
171 id => 'korap',
172 title => 'KorAP',
173 items => [
174 {
Akron0dc10902017-09-01 18:00:16 +0200175 id => 'krill',
176 title => 'Krill',
Nils Diewalda898dac2015-05-06 21:04:16 +0000177 },
178 {
Akron0dc10902017-09-01 18:00:16 +0200179 id => 'koral',
180 title => 'Koral'
Nils Diewalda898dac2015-05-06 21:04:16 +0000181 }
182 ]
183 },
184 {
185 title => 'Query Languages',
186 id => 'ql',
187 items => [
188 {
Akron0dc10902017-09-01 18:00:16 +0200189 title => 'Cosmas II',
190 id => 'cosmas2'
Nils Diewalda898dac2015-05-06 21:04:16 +0000191 },
192 {
Akron0dc10902017-09-01 18:00:16 +0200193 'title' => 'Poliqarp+',
194 'id' => 'poliqarp-plus',
195 'class' => 'folded',
196 items => [
197 {
198 "title" => "Simple Segments",
199 "id" => "#segments"
200 },
201 {
202 "title" => "Complex Segments",
203 "id" => "#complex"
204 }
205 ]
Nils Diewalda898dac2015-05-06 21:04:16 +0000206 }
207 ]
208 },
209 {
210 id => 'faq',
211 title => 'F.A.Q.'
212 }
213];
214$render = $c->doc_navi($navi);
215
216like($render, qr!/doc/korap!, 'Path matches doc/korap');
217like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
218like($render, qr!/doc/ql!, 'Path matches doc/ql');
219like($render, qr!/doc/ql/poliqarp-plus#segments!,
220 'Path matches doc/ql/poliqarp-plus#segments');
221like($render, qr!/doc/ql/poliqarp-plus#complex!,
222 'Path matches doc/ql/poliqarp-plus#complex');
223like($render, qr!class="folded active".*?Poliqarp\+!, 'Active and folded value for Poliqarp+');
224
Akron0dc10902017-09-01 18:00:16 +0200225
226# Test for translations
227$navi = [
228 {
229 id => 'korap',
230 title => 'KorAP',
231 items => [
232 {
233 id => 'krill',
234 title => 'Krill',
235 }
236 ]
237 },
238 {
239 id => 'faq',
240 title => 'F.A.Q.'
241 }
242];
243
244$render = $app->doc_navi($navi);
245like($render, qr!/doc/korap!, 'Path matches doc/korap');
246like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
Akron2dd87542017-11-17 11:21:01 +0100247like($render, qr!<a href="/doc/korap/krill(?:#[^"]+)?">Krill</a>!,
Akron0dc10902017-09-01 18:00:16 +0200248 'Path matches korap/krill');
Akron2dd87542017-11-17 11:21:01 +0100249like($render, qr!<a href="/doc/faq(?:#[^"]+)?">F\.A\.Q\.</a>!,
Akron0dc10902017-09-01 18:00:16 +0200250 'Path matches FAQ');
251
252# Change preferred language
253$languages = [qw/de en/];
254
255$render = $app->doc_navi($navi);
256like($render, qr!/doc/korap!, 'Path matches doc/korap');
257like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
Akron2dd87542017-11-17 11:21:01 +0100258like($render, qr!<a href="/doc/korap/krill(?:#[^"]+)?">Krill</a>!,
Akron0dc10902017-09-01 18:00:16 +0200259 'Path matches korap/krill');
Akron2dd87542017-11-17 11:21:01 +0100260like($render, qr!<a href="/doc/faq(?:#[^"]+)?">Häufige Fragen</a>!,
Akron0dc10902017-09-01 18:00:16 +0200261 'Path matches FAQ');
262
263
Nils Diewalda898dac2015-05-06 21:04:16 +0000264done_testing;
265
266__END__
267