require 'test_helper' require 'rails/dom/testing/assertions/dom_assertions' class DomAssertionsTest < ActiveSupport::TestCase Assertion = Minitest::Assertion include Rails::Dom::Testing::Assertions::DomAssertions def test_responds_to_assert_dom_equal assert respond_to?(:assert_dom_equal) end def test_dom_equal html = '' assert_dom_equal(html, html.dup) end def test_equal_doms_with_different_order_attributes attributes = %{} reverse_attributes = %{} assert_dom_equal(attributes, reverse_attributes) end def test_dom_not_equal assert_dom_not_equal('', '') end def test_unequal_doms_attributes_with_different_order_and_values attributes = %{} reverse_attributes = %{} assert_dom_not_equal(attributes, reverse_attributes) end def test_custom_message_is_used_in_failures message = "This is my message." e = assert_raises(Assertion) do assert_dom_equal('', '', message) end assert_equal e.message, message end def test_unequal_dom_attributes_in_children assert_dom_not_equal( %{}, %{} ) end def test_dom_equal_with_whitespace_strict canonical = %{hello world} assert_dom_not_equal(canonical, %{\nhello\n world}, strict: true) assert_dom_not_equal(canonical, %{ \n \n hello world}, strict: true) assert_dom_not_equal(canonical, %{\n\thello world}, strict: true) assert_dom_equal(canonical, %{hello world}, strict: true) end def test_dom_equal_with_whitespace canonical = %{hello world} assert_dom_equal(canonical, %{\nhello\n world}) assert_dom_equal(canonical, %{\nhello \nworld}) assert_dom_equal(canonical, %{ \n \n hello world}) assert_dom_equal(canonical, %{ \n hello world}) assert_dom_equal(canonical, %{ \n hello world\n\n}) assert_dom_equal(canonical, %{\n\thello world}) assert_dom_equal(canonical, %{\n\thello \n\tworld}) end def test_dom_equal_with_attribute_whitespace canonical = %(
) assert_dom_equal(canonical, %(
)) assert_dom_not_equal(canonical, %(
)) end def test_dom_equal_with_indentation canonical = %{hello cruel world} assert_dom_equal(canonical, <<-HTML) hello cruel world HTML assert_dom_equal(canonical, <<-HTML) hello cruel world HTML assert_dom_equal(canonical, <<-HTML) hello cruel world HTML end def test_dom_equal_with_surrounding_whitespace canonical = %{

Lorem ipsum dolor

sit amet, consectetur adipiscing elit

} assert_dom_equal(canonical, <<-HTML)

Lorem ipsum dolor

sit amet, consectetur adipiscing elit

HTML end def test_dom_not_equal_with_interior_whitespace with_space = %{hello world} without_space = %{helloworld} assert_dom_not_equal(with_space, without_space) end end