1 # frozen_string_literal: true
5 class ApplicationHelperTest < ActionView::TestCase
6 attr_accessor :current_user
9 %w[http://example.com/test ftp://example.com/test https://example.com/test].each do |link|
10 text = "Test #{link} is <b>made</b> into a link"
13 assert_predicate html, :html_safe?
14 assert_dom_equal "Test <a href=\"#{link}\" rel=\"nofollow\" dir=\"auto\">#{link}</a> is <b>made</b> into a link", html
16 html = linkify(text.html_safe)
17 assert_predicate html, :html_safe?
18 assert_dom_equal "Test <a href=\"#{link}\" rel=\"nofollow\" dir=\"auto\">#{link}</a> is <b>made</b> into a link", html
21 %w[test@example.com mailto:test@example.com].each do |link|
22 text = "Test #{link} is not <b>made</b> into a link"
25 assert_predicate html, :html_safe?
26 assert_dom_equal "Test #{link} is not <b>made</b> into a link", html
28 html = linkify(text.html_safe)
29 assert_predicate html, :html_safe?
30 assert_dom_equal "Test #{link} is not <b>made</b> into a link", html
35 link = rss_link_to(:controller => :diary_entries, :action => :rss)
36 assert_dom_equal "<a href=\"/diary/rss\"><i class=\"bi bi-rss-fill fs-6\" aria-hidden=\"true\"></i></a>", link
40 assert_equal "ltr", dir
43 assert_equal "rtl", dir
46 I18n.with_locale "he" do
47 assert_equal "rtl", dir
50 assert_equal "ltr", dir
55 def test_friendly_date
56 date = friendly_date(Time.utc(2014, 3, 5, 18, 58, 23))
57 assert_match %r{^<time title=" *5 March 2014 at 18:58" datetime="2014-03-05T18:58:23Z">.*</time>$}, date
59 date = friendly_date(Time.now.utc - 1.hour)
60 assert_match %r{^<time title=".*">about 1 hour</time>$}, date
62 date = friendly_date(Time.now.utc - 2.days)
63 assert_match %r{^<time title=".*">2 days</time>$}, date
65 date = friendly_date(Time.now.utc - 3.weeks)
66 assert_match %r{^<time title=".*">21 days</time>$}, date
68 date = friendly_date(Time.now.utc - 4.months)
69 assert_match %r{^<time title=".*">4 months</time>$}, date
72 def test_friendly_date_ago
73 date = friendly_date_ago(Time.utc(2014, 3, 5, 18, 58, 23))
74 assert_match %r{^<time title=" *5 March 2014 at 18:58" datetime="2014-03-05T18:58:23Z">.*</time>$}, date
76 date = friendly_date_ago(Time.now.utc - 1.hour)
77 assert_match %r{^<time title=".*">about 1 hour ago</time>$}, date
79 date = friendly_date_ago(Time.now.utc - 2.days)
80 assert_match %r{^<time title=".*">2 days ago</time>$}, date
82 date = friendly_date_ago(Time.now.utc - 3.weeks)
83 assert_match %r{^<time title=".*">21 days ago</time>$}, date
85 date = friendly_date_ago(Time.now.utc - 4.months)
86 assert_match %r{^<time title=".*">4 months ago</time>$}, date