Skip to content

Commit

Permalink
Add more tests for StimulusReflex::HTML::DocumentFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoroth committed Mar 14, 2023
1 parent e32e64c commit e965b79
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 additions & 2 deletions test/html/document_fragment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,24 +148,86 @@ class StimulusReflex::HTML::DocumentFragmentTest < ActiveSupport::TestCase
test "should properly handle a tr without the parent table" do
html = "<tr><td>1</td><td>2</td></tr>"
fragment = StimulusReflex::HTML::DocumentFragment.new(html)

assert_equal html, fragment.to_html.squish
end

test "should properly handle a td without the parent table or td" do
html = "<td>1</td>"
fragment = StimulusReflex::HTML::DocumentFragment.new(html)

assert_equal html, fragment.to_html.squish
end

test "should properly return inner html of a complex tr when parsed as a fragment fragment" do
test "should properly parse <tr>" do
html = '<tr data-foo="1" id="123" class="abc"><td>1</td><td>2</td></tr>'
fragment = StimulusReflex::HTML::DocumentFragment.new(html)

assert_equal '<tr data-foo="1" id="123" class="abc"><td>1</td><td>2</td></tr>', fragment.to_html.squish
assert_equal '<tr data-foo="1" id="123" class="abc"><td>1</td><td>2</td></tr>', fragment.outer_html.squish
assert_equal "<td>1</td><td>2</td>", fragment.inner_html.squish
end

test "should properly return inner html of a td when parsed as a fragment fragment" do
test "should properly parse <td>" do
html = "<td>1</td>"
fragment = StimulusReflex::HTML::DocumentFragment.new(html)

assert_equal "<td>1</td>", fragment.to_html.squish
assert_equal "<td>1</td>", fragment.outer_html.squish
assert_equal "1", fragment.inner_html.squish
end

test "should properly parse <th>" do
html = "<th>1</th>"
fragment = StimulusReflex::HTML::DocumentFragment.new(html)

assert_equal "<th>1</th>", fragment.to_html.squish
assert_equal "<th>1</th>", fragment.outer_html.squish
assert_equal "1", fragment.inner_html.squish
end

test "should properly parse <thead>" do
html = "<thead><tr><th>1</th><th>2</th></tr></thead>"
fragment = StimulusReflex::HTML::DocumentFragment.new(html)

assert_equal "<thead><tr><th>1</th><th>2</th></tr></thead>", fragment.to_html.squish
assert_equal "<thead><tr><th>1</th><th>2</th></tr></thead>", fragment.outer_html.squish
assert_equal "<tr><th>1</th><th>2</th></tr>", fragment.inner_html.squish
end

test "should properly parse <tbody>" do
html = "<tbody><tr><th>1</th><th>2</th></tr></tbody>"
fragment = StimulusReflex::HTML::DocumentFragment.new(html)

assert_equal "<tbody><tr><th>1</th><th>2</th></tr></tbody>", fragment.to_html.squish
assert_equal "<tbody><tr><th>1</th><th>2</th></tr></tbody>", fragment.outer_html.squish
assert_equal "<tr><th>1</th><th>2</th></tr>", fragment.inner_html.squish
end

test "should properly parse <tfoot>" do
html = "<tfoot><tr><th>1</th><th>2</th></tr></tfoot>"
fragment = StimulusReflex::HTML::DocumentFragment.new(html)

assert_equal "<tfoot><tr><th>1</th><th>2</th></tr></tfoot>", fragment.to_html.squish
assert_equal "<tfoot><tr><th>1</th><th>2</th></tr></tfoot>", fragment.outer_html.squish
assert_equal "<tr><th>1</th><th>2</th></tr>", fragment.inner_html.squish
end

test "should properly parse <ul>" do
html = "<ul><li>1</li></ul>"
fragment = StimulusReflex::HTML::DocumentFragment.new(html)

assert_equal "<ul><li>1</li></ul>", fragment.to_html.squish
assert_equal "<ul><li>1</li></ul>", fragment.outer_html.squish
assert_equal "<li>1</li>", fragment.inner_html.squish
end

test "should properly parse <li>" do
html = "<li>1</li>"
fragment = StimulusReflex::HTML::DocumentFragment.new(html)

assert_equal "<li>1</li>", fragment.to_html.squish
assert_equal "<li>1</li>", fragment.outer_html.squish
assert_equal "1", fragment.inner_html.squish
end
end

0 comments on commit e965b79

Please sign in to comment.