Skip to content

Commit 40e9c36

Browse files
committed
Add tests for news archives plugin
Provide tests that check the used layouts for news archive pages. This targets issues like e.g. the one related to behavior changed with Jekyll 4.2.0, fixed in f29a3d5.
1 parent fc6a499 commit 40e9c36

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

test/test_plugin_news.rb

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# frozen_string_literal: true
2+
3+
require "helper"
4+
5+
require "jekyll"
6+
require_relative "../_plugins/news"
7+
8+
9+
describe NewsArchivePlugin do
10+
11+
before do
12+
chdir_tempdir
13+
14+
content = <<~CONFIG
15+
CONFIG
16+
17+
create_file("source/_config.yml", content)
18+
19+
content = <<~LOCALES
20+
month_names:
21+
- January
22+
- February
23+
24+
news:
25+
recent_news: Recent News
26+
yearly_archive_title: "%Y Archives"
27+
monthly_archive_title: "%B %Y Archives"
28+
yearly_archive_link: "%Y Archives"
29+
monthly_archive_link: "%B %Y"
30+
LOCALES
31+
32+
create_file("source/_data/locales/en.yml", content)
33+
34+
content = <<~LAYOUT
35+
---
36+
layout: default
37+
---
38+
NEWS LAYOUT
39+
40+
{% for post in page.posts %}
41+
{{ post.title }}
42+
{% endfor %}
43+
LAYOUT
44+
45+
create_file("source/_layouts/news.html", content)
46+
47+
content = <<~LAYOUT
48+
---
49+
layout: default
50+
---
51+
NEWS ARCHIVE YEAR LAYOUT
52+
53+
{% for post in page.posts %}
54+
{{ post.title }}
55+
{% endfor %}
56+
LAYOUT
57+
58+
create_file("source/_layouts/news_archive_year.html", content)
59+
60+
content = <<~LAYOUT
61+
---
62+
layout: default
63+
---
64+
NEWS ARCHIVE MONTH LAYOUT
65+
66+
{% for post in page.posts %}
67+
{{ post.title }}
68+
{% endfor %}
69+
LAYOUT
70+
71+
create_file("source/_layouts/news_archive_month.html", content)
72+
73+
content = <<~POST
74+
---
75+
title: "Post Jan 2020"
76+
author: "stomar"
77+
date: 2020-01-01 12:00:00 +0000
78+
lang: en
79+
---
80+
81+
Content
82+
POST
83+
84+
create_file("source/en/news/_posts/2020-01-01-post.md", content)
85+
86+
config = Jekyll.configuration(
87+
source: "source",
88+
destination: "_site",
89+
quiet: true
90+
)
91+
site = Jekyll::Site.new(config)
92+
93+
file_wont_exist("_site")
94+
site.process
95+
end
96+
97+
after do
98+
teardown_tempdir
99+
end
100+
101+
it "should create news page" do
102+
file_must_exist("_site/en/news/index.html")
103+
end
104+
105+
it "should use the correct layout for news page" do
106+
_(File.read("_site/en/news/index.html")).must_match "NEWS LAYOUT"
107+
end
108+
109+
it "should create news/2020 page" do
110+
file_must_exist("_site/en/news/2020/index.html")
111+
end
112+
113+
it "should use the correct layout for news/2020 page" do
114+
_(File.read("_site/en/news/2020/index.html")).must_match "YEAR LAYOUT"
115+
end
116+
117+
it "should create news/2020/01 page" do
118+
file_must_exist("_site/en/news/2020/index.html")
119+
end
120+
121+
it "should use the correct layout for news/2020/01 page" do
122+
_(File.read("_site/en/news/2020/01/index.html")).must_match "MONTH LAYOUT"
123+
end
124+
end

0 commit comments

Comments
 (0)