Skip to content

Commit

Permalink
Merge pull request #181 from mitou/add-test-for-proceeding-schedule
Browse files Browse the repository at this point in the history
Add test for proceeding schedule like #180
  • Loading branch information
yasulab committed May 12, 2024
2 parents 2f29643 + 60b5f43 commit cc5dee3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/custom_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class CustomChecks < ::HTMLProofer::Check
def run
check_meta_tags
check_json_apis if @runner.current_filename == '_site/api.html'
check_deadlines if @runner.current_filename == '_site/guideline.html'
end
end

Expand Down Expand Up @@ -41,3 +42,30 @@ def valid_json?(filename)
rescue JSON::ParserError, TypeError => e
false
end

# Check proceeding schedule is correct in time order:
# e.g. https://github.com/mitou/jr.mitou.org/pull/180
def check_deadlines
this_year = Date.today.year
prev_text = ''
prev_deadline = "#{this_year}-01-23"
this_deadline = "#{this_year}-01-24"

# Fetch heading nodes like "1. プロジェクトの計画を立てる"
@html.search('h3').select{|n| n.text.start_with?(/\d\./)}.each do |node|
month_and_day = node.children.last.text.scan(/\d+月\d+日/).last
next if month_and_day.nil? # 〆切の無い heading は省略

# 〆切のある heading の日付(後半の終端日分)が時間軸に沿っているかチェックする
# 例: "3. 応募フォームから提案書をアップロードする (2024年4月6日 23:59まで)"
# 例: "6. 追加インタビュー期間 (2024年5月14日〜5月27日)"
this_deadline = "#{this_year}-%02d-%02d" % month_and_day.scan(/\d+/)
add_failure(<<~ERROR_MESSAGE) if prev_deadline > this_deadline
This deadline would be inconsistent with previous one:
\s prev_deadline: #{prev_text}
\s this_deadline: #{node.text}
ERROR_MESSAGE
prev_deadline = this_deadline
prev_text = node.text
end
end

0 comments on commit cc5dee3

Please sign in to comment.