X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/f2d13c075660efb9582d7fb600bd6798d7a382ca..5a0e0b2407823f501977d362ddc09664d9fa2f3f:/test/helpers/note_helper_test.rb
diff --git a/test/helpers/note_helper_test.rb b/test/helpers/note_helper_test.rb
index 8fb2bc073..8b8173694 100644
--- a/test/helpers/note_helper_test.rb
+++ b/test/helpers/note_helper_test.rb
@@ -1,21 +1,50 @@
-require 'test_helper'
+require "test_helper"
class NoteHelperTest < ActionView::TestCase
include ERB::Util
include ApplicationHelper
- fixtures :users
-
def test_note_event
- date = Time.new(2014, 3, 5, 21, 37, 45)
+ date = Time.utc(2014, 3, 5, 21, 37, 45)
+ user = create(:user)
+
+ note_event_dom = Rails::Dom::Testing.html_document_fragment.parse "
#{note_event('opened', date, nil)}
"
+ assert_dom note_event_dom, ":root", :text => /^Created by anonymous .* ago$/ do
+ assert_dom "> a", :count => 0
+ assert_dom "> time", :count => 1 do
+ assert_dom "> @title", "5 March 2014 at 21:37"
+ assert_dom "> @datetime", "2014-03-05T21:37:45Z"
+ end
+ end
- assert_match /^Created by anonymous .*<\/span> ago<\/abbr>$/, note_event("open", date, nil)
- assert_match /^Resolved by test2<\/a> .*<\/span> ago<\/abbr>$/, note_event("closed", date, users(:public_user))
+ note_event_dom = Rails::Dom::Testing.html_document_fragment.parse "#{note_event('closed', date, user)}
"
+ assert_dom note_event_dom, ":root", :text => /^Resolved by #{user.display_name} .* ago$/ do
+ assert_dom "> a", :count => 1, :text => user.display_name do
+ assert_dom "> @href", "/user/#{ERB::Util.u(user.display_name)}"
+ end
+ assert_dom "> time", :count => 1 do
+ assert_dom "> @title", "5 March 2014 at 21:37"
+ assert_dom "> @datetime", "2014-03-05T21:37:45Z"
+ end
+ end
end
def test_note_author
+ deleted_user = create(:user, :deleted)
+ user = create(:user)
+
assert_equal "", note_author(nil)
- assert_equal "test2", note_author(users(:public_user))
- assert_equal "test2", note_author(users(:public_user), :only_path => false)
+
+ assert_equal "deleted", note_author(deleted_user)
+
+ note_author_dom = Rails::Dom::Testing.html_document_fragment.parse note_author(user)
+ assert_dom note_author_dom, "a:root", :text => user.display_name do
+ assert_dom "> @href", "/user/#{ERB::Util.u(user.display_name)}"
+ end
+
+ note_author_dom = Rails::Dom::Testing.html_document_fragment.parse note_author(user, :only_path => false)
+ assert_dom note_author_dom, "a:root", :text => user.display_name do
+ assert_dom "> @href", "http://test.host/user/#{ERB::Util.u(user.display_name)}"
+ end
end
end