require "test_helper"
class GovspeakTableWithHeadersTest < Minitest::Test
def expected_outcome
%(
|
Second Column |
Third Column |
First row |
Cell |
Cell |
Second row |
Cell |
Cell |
)
end
def expected_outcome_with_hashes_in_cell_contents
%(
|
Second Column |
Third Column |
First row |
# Cell |
# Cell |
Second row |
Cell |
Cell |
)
end
def expected_outcome_for_table_with_alignments
%(
|
Second Column |
Third Column |
First row |
Cell |
Cell |
Second row |
Cell |
Cell |
)
end
def expected_outcome_for_table_headers_in_the_wrong_place
%(
|
Second Column |
Third Column |
First row |
# Cell |
Cell |
Second row |
Cell |
# Cell |
)
end
def expected_outcome_for_table_with_blank_table_headers
%(
|
Second Column |
Third Column |
|
Cell |
Cell |
Second row |
Cell |
Cell |
)
end
def expected_outcome_for_table_with_table_headers_containing_superscript
%(
Foobar
|
Third Column |
Cell |
Cell |
)
end
def document_body_with_table_headers_containing_superscript
@document_body_with_table_headers_containing_superscript ||= Govspeak::Document.new(%(
| Foobar | Third Column |
| --------------- | ------------------- |
| Cell | Cell |
))
end
def expected_outcome_for_table_headers_containing_links
%(
)
end
def document_body_with_hashes_for_all_headers
@document_body_with_hashes_for_all_headers ||= Govspeak::Document.new(%(
| |# Second Column |# Third Column |
| --------------- | --------------- | ------------------- |
|# First row | Cell | Cell |
|# Second row | Cell | Cell |
))
end
def document_body_with_hashes_for_row_headers
@document_body_with_hashes_for_row_headers ||= Govspeak::Document.new(%(
| | Second Column | Third Column |
| --------------- | --------------- | ------------------- |
|# First row | Cell | Cell |
|# Second row | Cell | Cell |
))
end
def document_body_with_alignments
@document_body_with_alignments ||= Govspeak::Document.new(%(
| | Second Column | Third Column |
| :-------------- | :-------------: | ------------------: |
|# First row | Cell | Cell |
|# Second row | Cell | Cell |
))
end
def document_body_with_table_headers_in_the_wrong_place
@document_body_with_table_headers_in_the_wrong_place ||= Govspeak::Document.new(%(
| | Second Column | Third Column |
| --------------- | --------------- | ------------------- |
|# First row |# Cell | Cell |
|# Second row | Cell |# Cell |
))
end
def document_body_with_blank_table_headers
@document_body_with_blank_table_headers ||= Govspeak::Document.new(%(
| | Second Column | Third Column |
| --------------- | --------------- | ------------------- |
|# | Cell | Cell |
|# Second row | Cell | Cell |
))
end
def document_body_with_table_headers_containing_links
@document_body_with_table_headers_containing_links ||= Govspeak::Document.new(%(
| | Second Column | Third Column |
| ---------------------------------------------------- | --------------- | ------------------- |
|# Link contained in header [link1](http://google.com) | Cell | Cell |
|# No link | Cell | Cell |
|# [Whole header is link](http://www.bbc.co.uk) | Cell | Cell |
))
end
test "Cells with |# are headers" do
assert_equal document_body_with_hashes_for_all_headers.to_html, expected_outcome
end
test "Cells outside of thead with |# are th; thead still only contains th" do
assert_equal document_body_with_hashes_for_row_headers.to_html, expected_outcome
end
test "Cells are aligned correctly" do
assert_equal document_body_with_alignments.to_html, expected_outcome_for_table_with_alignments
end
test "Table headers with a scope of row are only in the first column of the table" do
assert_equal document_body_with_table_headers_in_the_wrong_place.to_html, expected_outcome_for_table_headers_in_the_wrong_place
end
test "Table headers with a scope of row can have embedded links" do
assert_equal document_body_with_table_headers_containing_links.to_html, expected_outcome_for_table_headers_containing_links
end
test "Table headers are not blank" do
assert_equal document_body_with_blank_table_headers.to_html, expected_outcome_for_table_with_blank_table_headers
end
test "Table header superscript should parse" do
assert_equal document_body_with_table_headers_containing_superscript.to_html, expected_outcome_for_table_with_table_headers_containing_superscript
end
end