]> git.openstreetmap.org Git - rails.git/blob - test/helpers/note_helper_test.rb
Merge pull request #6394 from openstreetmap/dependabot/github_actions/ruby/setup...
[rails.git] / test / helpers / note_helper_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class NoteHelperTest < ActionView::TestCase
6   include ERB::Util
7   include ApplicationHelper
8
9   def test_note_event
10     date = Time.utc(2014, 3, 5, 21, 37, 45)
11     user = create(:user)
12
13     note_event_dom = Rails::Dom::Testing.html_document_fragment.parse "<div>#{note_event('opened', date, nil)}</div>"
14     assert_dom note_event_dom, ":root", :text => /^Created by anonymous .* ago$/ do
15       assert_dom "> a", :count => 0
16       assert_dom "> time", :count => 1 do
17         assert_dom "> @title", "5 March 2014 at 21:37"
18         assert_dom "> @datetime", "2014-03-05T21:37:45Z"
19       end
20     end
21
22     note_event_dom = Rails::Dom::Testing.html_document_fragment.parse "<div>#{note_event('closed', date, user)}</div>"
23     assert_dom note_event_dom, ":root", :text => /^Resolved by #{user.display_name} .* ago$/ do
24       assert_dom "> a", :count => 1, :text => user.display_name do
25         assert_dom "> @href", "/user/#{ERB::Util.u(user.display_name)}"
26       end
27       assert_dom "> time", :count => 1 do
28         assert_dom "> @title", "5 March 2014 at 21:37"
29         assert_dom "> @datetime", "2014-03-05T21:37:45Z"
30       end
31     end
32   end
33
34   def test_note_author
35     deleted_user = create(:user, :deleted)
36     user = create(:user)
37
38     assert_equal "", note_author(nil)
39
40     assert_equal "deleted", note_author(deleted_user)
41
42     note_author_dom = Rails::Dom::Testing.html_document_fragment.parse note_author(user)
43     assert_dom note_author_dom, "a:root", :text => user.display_name do
44       assert_dom "> @href", "/user/#{ERB::Util.u(user.display_name)}"
45     end
46
47     note_author_dom = Rails::Dom::Testing.html_document_fragment.parse note_author(user, :only_path => false)
48     assert_dom note_author_dom, "a:root", :text => user.display_name do
49       assert_dom "> @href", "http://test.host/user/#{ERB::Util.u(user.display_name)}"
50     end
51   end
52 end