require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
require 'test/unit'
require 'nitro/helper/table'
class TC_TableHelper < Test::Unit::TestCase # :nodoc: all
include Nitro
include TableHelper
User = Struct.new(:name, :password, :email)
def setup
@headers = %w{Name Password Email}
@users = [
User.new('gmosx', 'huh?', 'gm@nowhere.com'),
User.new('renos', 'nah', 'renos@nowhere.com'),
User.new('stella', 'hoh', 'stella@love.com')
]
end
def teardown
@users = nil
end
def test_table
values = @users.collect { |u| [u.name, u.password, u.email] }
table = build_table(:id => 'test', :headers => @headers, :values => values)
res = %|
Name | Password | Email |
---|
gmosx | huh? | gm@nowhere.com |
renos | nah | renos@nowhere.com |
stella | hoh | stella@love.com |
|
assert_equal res, table
end
def test_table_footer
values = @users.collect { |u| [u.name, u.password, u.email] }
footers = ["#{@users.size}users", '', '']
table = build_table(:id => 'test2', :headers => @headers, :values => values, :footers => footers)
res = %|Name | Password | Email |
---|
3users | | |
gmosx | huh? | gm@nowhere.com |
renos | nah | renos@nowhere.com |
stella | hoh | stella@love.com |
|
assert_equal res, table
end
def test_table_tbody
values = []
values << @users[0...1].collect { |u| [u.name, u.password, u.email] }
values << @users[1..2].collect { |u| [u.name, u.password, u.email] }
table = build_table(:id => 'test', :headers => @headers, :values => values)
res = %|Name | Password | Email |
---|
gmosx | huh? | gm@nowhere.com |
renos | nah | renos@nowhere.com |
stella | hoh | stella@love.com |
|
assert_equal res, table
end
def test_table_alternating_rows
values = @users.collect { |u| [u.name, u.password, u.email] }
table = build_table(:id => 'test', :headers => @headers, :values => values, :alternating_rows => true)
res = %|Name | Password | Email |
---|
gmosx | huh? | gm@nowhere.com |
renos | nah | renos@nowhere.com |
stella | hoh | stella@love.com |
|
assert_equal res, table
end
def test_table_alternating_rows_tbody
values = []
values << @users[0...1].collect { |u| [u.name, u.password, u.email] }
values << @users[1..2].collect { |u| [u.name, u.password, u.email] }
table = build_table(:id => 'test', :headers => @headers, :values => values, :alternating_rows => true)
res = %|Name | Password | Email |
---|
gmosx | huh? | gm@nowhere.com |
renos | nah | renos@nowhere.com |
stella | hoh | stella@love.com |
|
assert_equal res, table
end
end