-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathtest_jekyll_archives.rb
261 lines (217 loc) · 7.41 KB
/
test_jekyll_archives.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# frozen_string_literal: true
require "helper"
class TestJekyllArchives < Minitest::Test
context "the jekyll-archives plugin" do
setup do
@site = fixture_site("jekyll-archives" => {
"enabled" => true,
})
@site.read
@archives = Jekyll::Archives::Archives.new(@site.config)
end
should "generate archive pages by year" do
@archives.generate(@site)
assert archive_exists? @site, "2014/index.html"
assert archive_exists? @site, "2013/index.html"
end
should "generate archive pages by month" do
@archives.generate(@site)
assert archive_exists? @site, "2014/08/index.html"
assert archive_exists? @site, "2014/03/index.html"
end
should "generate archive pages by day" do
@archives.generate(@site)
assert archive_exists? @site, "2014/08/17/index.html"
assert archive_exists? @site, "2013/08/16/index.html"
end
should "generate archive pages by tag" do
@archives.generate(@site)
assert archive_exists? @site, "tag/test-tag/index.html"
assert archive_exists? @site, "tag/tagged/index.html"
assert archive_exists? @site, "tag/new/index.html"
end
should "generate archive pages by category" do
@archives.generate(@site)
assert archive_exists? @site, "category/plugins/index.html"
end
should "generate archive pages with a layout" do
@site.process
assert_equal "Test", read_file("tag/test-tag/index.html")
end
end
context "the jekyll-archives plugin with a custom slug mode" do
setup do
# slug mode other than those expected by Jekyll returns the given string after
# downcasing it.
@site = fixture_site("jekyll-archives" => {
"slug_mode" => "raw",
"enabled" => true,
})
@site.read
@archives = Jekyll::Archives::Archives.new(@site.config)
end
should "generate slugs using the mode specified" do
@archives.generate(@site)
assert archive_exists? @site, "category/💎/index.html"
end
end
context "the jekyll-archives plugin with custom layout path" do
setup do
@site = fixture_site("jekyll-archives" => {
"layout" => "archive-too",
"enabled" => true,
})
@site.process
end
should "use custom layout" do
@site.process
assert_equal "Test too", read_file("tag/test-tag/index.html")
end
end
context "the jekyll-archives plugin with type-specific layout" do
setup do
@site = fixture_site(
"jekyll-archives" => {
"enabled" => true,
"layouts" => {
"year" => "archive-too",
},
}
)
@site.process
end
should "use custom layout for specific type only" do
assert_equal "Test too", read_file("/2014/index.html")
assert_equal "Test too", read_file("/2013/index.html")
assert_equal "Test", read_file("/tag/test-tag/index.html")
end
end
context "the jekyll-archives plugin with custom permalinks" do
setup do
@site = fixture_site(
"jekyll-archives" => {
"enabled" => true,
"permalinks" => {
"year" => "/year/:year/",
"tag" => "/tag-:name.html",
"category" => "/category-:name.html",
},
}
)
@site.process
end
should "use the right permalink" do
assert archive_exists? @site, "year/2014/index.html"
assert archive_exists? @site, "year/2013/index.html"
assert archive_exists? @site, "tag-test-tag.html"
assert archive_exists? @site, "tag-new.html"
assert archive_exists? @site, "category-plugins.html"
end
end
context "the archives" do
setup do
@site = fixture_site("jekyll-archives" => {
"enabled" => true,
})
@site.process
end
should "populate the {{ site.archives }} tag in Liquid" do
assert_equal 16, read_file("length.html").to_i
end
end
context "the jekyll-archives plugin with default config" do
setup do
@site = fixture_site
@site.process
end
should "not generate any archives" do
assert_equal 0, read_file("length.html").to_i
end
end
context "the jekyll-archives plugin with enabled array" do
setup do
@site = fixture_site("jekyll-archives" => {
"enabled" => ["tags"],
})
@site.process
end
should "generate the enabled archives" do
assert archive_exists? @site, "tag/test-tag/index.html"
assert archive_exists? @site, "tag/tagged/index.html"
assert archive_exists? @site, "tag/new/index.html"
end
should "not generate the disabled archives" do
refute archive_exists?(@site, "2014/index.html")
refute archive_exists?(@site, "2014/08/index.html")
refute archive_exists?(@site, "2013/08/16/index.html")
refute archive_exists?(@site, "category/plugins/index.html")
end
end
context "the jekyll-archives plugin" do
setup do
@site = fixture_site("jekyll-archives" => {
"enabled" => true,
})
@site.process
@archives = @site.config["archives"]
@tag_archive = @archives.detect { |a| a.type == "tag" }
@category_archive = @archives.detect { |a| a.type == "category" }
@year_archive = @archives.detect { |a| a.type == "year" }
@month_archive = @archives.detect { |a| a.type == "month" }
@day_archive = @archives.detect { |a| a.type == "day" }
end
should "populate the title field in case of category or tag" do
assert_kind_of String, @tag_archive.title
assert_kind_of String, @category_archive.title
end
should "use nil for the title field in case of dates" do
assert_nil @year_archive.title
assert_nil @month_archive.title
assert_nil @day_archive.title
end
should "use nil for the date field in case of category or tag" do
assert_nil @tag_archive.date
assert_nil @category_archive.date
end
should "populate the date field with a Date in case of dates" do
assert_kind_of Date, @year_archive.date
assert_kind_of Date, @month_archive.date
assert_kind_of Date, @day_archive.date
end
end
context "the jekyll-archives plugin with a non-hash config" do
should "output a warning" do
output = capture_output do
site = fixture_site("jekyll-archives" => %w(apples oranges))
site.read
site.generate
end
assert_includes output, "Archives: Expected a hash but got [\"apples\", \"oranges\"]"
assert_includes output, "Archives will not be generated for this site."
output = capture_output do
site = fixture_site("jekyll-archives" => nil)
site.read
site.generate
end
assert_includes output, "Archives: Expected a hash but got nil"
assert_includes output, "Archives will not be generated for this site."
end
should "not generate archive pages" do
capture_output do
site = fixture_site("jekyll-archives" => nil)
site.read
site.generate
assert_nil(site.pages.find { |p| p.is_a?(Jekyll::Archives::Archive) })
end
end
should "be fine with a basic config" do
output = capture_output do
@site = fixture_site("title" => "Hello World")
@site.read
@site.generate
end
refute_includes output, "Archives: Expected a hash but got nil"
assert_nil(@site.pages.find { |p| p.is_a?(Jekyll::Archives::Archive) })
end
end
end