Skip to content

Commit 81788bf

Browse files
committed
Test Liquid representation of archive pages
1 parent 5ae016b commit 81788bf

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

test/test_jekyll_archive.rb

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# frozen_string_literal: true
2+
3+
require "helper"
4+
5+
class TestJekyllArchive < Minitest::Test
6+
context "the generated archive page" do
7+
setup do
8+
@site = fixture_site("jekyll-archives" => {
9+
"enabled" => true,
10+
})
11+
@site.read
12+
Jekyll::Archives::Archives.new(@site.config).generate(@site)
13+
@archives = @site.config["archives"]
14+
end
15+
16+
should "expose attributes to Liquid templates" do
17+
archive = @archives.find { |a| a.type == "tag" }
18+
archive.posts = []
19+
expected = {
20+
"layout" => "archive",
21+
"posts" => [],
22+
"type" => "tag",
23+
"title" => "Test Tag",
24+
"date" => nil,
25+
"name" => "index",
26+
"path" => "tag/test-tag/index.html",
27+
"url" => "/tag/test-tag/",
28+
"permalink" => nil,
29+
}
30+
assert_equal expected, archive.to_liquid.to_h
31+
32+
archive = @archives.find { |a| a.type == "category" }
33+
archive.posts = []
34+
expected = {
35+
"layout" => "archive",
36+
"posts" => [],
37+
"type" => "category",
38+
"title" => "plugins",
39+
"date" => nil,
40+
"name" => "index",
41+
"path" => "category/plugins/index.html",
42+
"url" => "/category/plugins/",
43+
"permalink" => nil,
44+
}
45+
assert_equal expected, archive.to_liquid.to_h
46+
47+
archive = @archives.find { |a| a.type == "year" }
48+
archive.posts = []
49+
expected = {
50+
"layout" => "archive",
51+
"posts" => [],
52+
"type" => "year",
53+
"title" => nil,
54+
"date" => archive.date,
55+
"name" => "index",
56+
"path" => "2013/index.html",
57+
"url" => "/2013/",
58+
"permalink" => nil,
59+
}
60+
assert_equal expected, archive.to_liquid.to_h
61+
62+
archive = @archives.find { |a| a.type == "month" }
63+
archive.posts = []
64+
expected = {
65+
"layout" => "archive",
66+
"posts" => [],
67+
"type" => "month",
68+
"title" => nil,
69+
"date" => archive.date,
70+
"name" => "index",
71+
"path" => "2013/08/index.html",
72+
"url" => "/2013/08/",
73+
"permalink" => nil,
74+
}
75+
assert_equal expected, archive.to_liquid.to_h
76+
77+
archive = @archives.find { |a| a.type == "day" }
78+
archive.posts = []
79+
expected = {
80+
"layout" => "archive",
81+
"posts" => [],
82+
"type" => "day",
83+
"title" => nil,
84+
"date" => archive.date,
85+
"name" => "index",
86+
"path" => "2013/08/16/index.html",
87+
"url" => "/2013/08/16/",
88+
"permalink" => nil,
89+
}
90+
assert_equal expected, archive.to_liquid.to_h
91+
end
92+
end
93+
end

0 commit comments

Comments
 (0)