Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
131 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,68 @@ | ||
require 'test_helper' | ||
require 'barby/barcode/code_128' | ||
#require 'barby/outputter/html_outputter' | ||
|
||
class HtmlOutputterTest < Barby::TestCase | ||
|
||
class MockCode | ||
attr_reader :encoding | ||
def initialize(e) | ||
@encoding = e | ||
end | ||
def two_dimensional? | ||
encoding.is_a? Array | ||
end | ||
end | ||
|
||
before do | ||
load_outputter('html') | ||
@barcode = Barby::Code128B.new('BARBY') | ||
@outputter = HtmlOutputter.new(@barcode) | ||
end | ||
|
||
it "should register to_html" do | ||
Barcode.outputters.must_include(:to_html) | ||
end | ||
|
||
it "should include css style tag by default with option to leave out" do | ||
@barcode.to_html.must_include "<style>#{Barby::HtmlOutputter.css}</style>" | ||
@barcode.to_html(:css => false).wont_include "<style>#{Barby::HtmlOutputter.css}</style>" | ||
|
||
it 'should have the expected start HTML' do | ||
assert_equal '<table class="barby-barcode"><tbody>', @outputter.start | ||
end | ||
|
||
it 'should be able to set additional class name' do | ||
@outputter.class_name = 'humbaba' | ||
assert_equal '<table class="barby-barcode humbaba"><tbody>', @outputter.start | ||
end | ||
|
||
it 'should have the expected stop HTML' do | ||
assert_equal '</tbody></table>', @outputter.stop | ||
end | ||
|
||
it "should include inline parent style for width and height with option to disable" do | ||
@barcode.to_html.must_include '<table class="barby_code" style="width: 100px; height: 100px;">' | ||
@barcode.to_html(:parent_style => false).must_include '<table class="barby_code" >' | ||
|
||
it 'should build the expected cells' do | ||
assert_equal ['<td class="barby-cell on"></td>', '<td class="barby-cell off"></td>', '<td class="barby-cell off"></td>', '<td class="barby-cell on"></td>'], | ||
@outputter.cells_for([true, false, false, true]) | ||
end | ||
|
||
it 'should build the expected rows' do | ||
assert_equal( | ||
[ | ||
@outputter.cells_for([true, false]).map{|c| "<tr class=\"barby-row\">#{c}</tr>" }.join, | ||
@outputter.cells_for([false, true]).map{|c| "<tr class=\"barby-row\">#{c}</tr>" }.join | ||
], | ||
@outputter.rows_for([[true, false],[false, true]]) | ||
) | ||
end | ||
|
||
it 'should have the expected rows' do | ||
barcode = MockCode.new('101100') | ||
outputter = HtmlOutputter.new(barcode) | ||
assert_equal outputter.rows_for([[true, false, true, true, false, false]]), outputter.rows | ||
barcode = MockCode.new(['101', '010']) | ||
outputter = HtmlOutputter.new(barcode) | ||
assert_equal outputter.rows_for([[true, false, true], [false, true, false]]), outputter.rows | ||
end | ||
|
||
it 'should have the expected html' do | ||
assert_equal @outputter.start + @outputter.rows.join + @outputter.stop, @outputter.to_html | ||
end | ||
|
||
end |