blob: a9dc149c73a6548084e2a7e90cdc08b704e999f7 [file] [log] [blame]
Nils Diewalda898dac2015-05-06 21:04:16 +00001use Mojo::Base -strict;
2use lib '../lib', 'lib';
3use Mojolicious::Lite;
4use Test::More;
5use Test::Mojo;
6
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
19my $navi = [
20 {
21 id => 'korap',
22 title => 'KorAP'
23 }
24];
25
26my $render = $app->doc_navi($navi);
27like($render, qr!/doc/korap!, 'Path matches doc/korap');
28like($render, qr!KorAP!, 'Title matches');
29
30$navi = [
31 {
32 id => 'korap',
33 title => 'KorAP'
34 },
35 {
36 id => 'krill',
37 title => 'Krill'
38 }
39];
40
41$render = $app->doc_navi($navi);
42like($render, qr!/doc/korap!, 'Path matches doc/korap');
43like($render, qr!KorAP!, 'Title matches');
44like($render, qr!/doc/krill!, 'Path matches doc/krill');
45like($render, qr!Krill!, 'Title matches');
46
47$navi = [
48 {
49 id => 'korap',
50 title => 'KorAP',
51 items => [
52 {
53 id => 'krill',
54 title => 'Krill',
55 }
56 ]
57 },
58 {
59 id => 'faq',
60 title => 'F.A.Q.'
61 }
62];
63
64$render = $app->doc_navi($navi);
65like($render, qr!/doc/korap!, 'Path matches doc/korap');
66like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
67like($render, qr!/doc/faq!, 'Path matches doc/faq');
68
69$navi = [
70 {
71 id => 'korap',
72 title => 'KorAP',
73 items => [
74 {
75 id => 'krill',
76 title => 'Krill',
77 },
78 {
79 id => 'koral',
80 title => 'Koral'
81 }
82 ]
83 },
84 {
85 title => 'Query Languages',
86 id => 'ql',
87 items => [
88 {
89 title => 'Cosmas II',
90 id => 'cosmas2'
91 },
92 {
93 'title' => 'Poliqarp+',
94 'id' => 'poliqarp-plus',
95 items => [
96 {
97 "title" => "Simple Segments",
98 "id" => "#segments"
99 },
100 {
101 "title" => "Complex Segments",
102 "id" => "#complex"
103 }
104 ]
105 }
106 ]
107 },
108 {
109 id => 'faq',
110 title => 'F.A.Q.'
111 }
112];
113
114$render = $app->doc_navi($navi);
115like($render, qr!/doc/korap!, 'Path matches doc/korap');
116like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
117like($render, qr!/doc/korap/koral!, 'Path matches korap/koral');
118like($render, qr!/doc/ql!, 'Path matches doc/ql');
119like($render, qr!/doc/ql/cosmas2!, 'Path matches doc/ql/cosmas2');
120like($render, qr!/doc/ql/poliqarp-plus!, 'Path matches doc/ql/poliqarp-plus');
121like($render, qr!/doc/ql/poliqarp-plus#segments!,
122 'Path matches doc/ql/poliqarp-plus#segments');
123like($render, qr!/doc/ql/poliqarp-plus#complex!,
124 'Path matches doc/ql/poliqarp-plus#complex');
125like($render, qr!/doc/faq!, 'Path matches doc/faq');
126
127
128my $c = $app->build_controller;
129$c->stash(page => 'korap');
130$render = $c->doc_navi($navi);
131like($render, qr!/doc/korap!, 'Path matches doc/korap');
132like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
133like($render, qr!/doc/ql!, 'Path matches doc/ql');
134like($render, qr!/doc/ql/poliqarp-plus#segments!,
135 'Path matches doc/ql/poliqarp-plus#segments');
136like($render, qr!/doc/ql/poliqarp-plus#complex!,
137 'Path matches doc/ql/poliqarp-plus#complex');
138like($render, qr!class="active".*?KorAP!, 'Active value for KorAP');
139
140$c->stash(page => 'poliqarp-plus');
141$render = $c->doc_navi($navi);
142like($render, qr!/doc/korap!, 'Path matches doc/korap');
143like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
144like($render, qr!/doc/ql!, 'Path matches doc/ql');
145like($render, qr!/doc/ql/poliqarp-plus#segments!,
146 'Path matches doc/ql/poliqarp-plus#segments');
147like($render, qr!/doc/ql/poliqarp-plus#complex!,
148 'Path matches doc/ql/poliqarp-plus#complex');
149like($render, qr!class="active".*?Poliqarp\+!, 'Active value for Poliqarp+');
150
151
152$navi = [
153 {
154 id => 'korap',
155 title => 'KorAP',
156 items => [
157 {
158 id => 'krill',
159 title => 'Krill',
160 },
161 {
162 id => 'koral',
163 title => 'Koral'
164 }
165 ]
166 },
167 {
168 title => 'Query Languages',
169 id => 'ql',
170 items => [
171 {
172 title => 'Cosmas II',
173 id => 'cosmas2'
174 },
175 {
176 'title' => 'Poliqarp+',
177 'id' => 'poliqarp-plus',
178 'class' => 'folded',
179 items => [
180 {
181 "title" => "Simple Segments",
182 "id" => "#segments"
183 },
184 {
185 "title" => "Complex Segments",
186 "id" => "#complex"
187 }
188 ]
189 }
190 ]
191 },
192 {
193 id => 'faq',
194 title => 'F.A.Q.'
195 }
196];
197$render = $c->doc_navi($navi);
198
199like($render, qr!/doc/korap!, 'Path matches doc/korap');
200like($render, qr!/doc/korap/krill!, 'Path matches korap/krill');
201like($render, qr!/doc/ql!, 'Path matches doc/ql');
202like($render, qr!/doc/ql/poliqarp-plus#segments!,
203 'Path matches doc/ql/poliqarp-plus#segments');
204like($render, qr!/doc/ql/poliqarp-plus#complex!,
205 'Path matches doc/ql/poliqarp-plus#complex');
206like($render, qr!class="folded active".*?Poliqarp\+!, 'Active and folded value for Poliqarp+');
207
208done_testing;
209
210__END__
211