1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
require "helper"
class TestRadioButtons < Test::Unit::TestCase
def setup
@agent = Mechanize.new
@page = @agent.get("http://localhost/tc_radiobuttons.html")
end
def test_select_all
form = @page.forms.first
form.radiobuttons_with(:name => 'color').each do |b|
b.check
end
form.radiobutton_with(:name => 'color', :value => 'green').check
assert_equal(true, form.radiobutton_with( :name => 'color',
:value => 'green').checked)
%w{ red blue yellow brown }.each do |button_value|
assert_equal(false, form.radiobutton_with( :name => 'color',
:value => button_value
).checked)
end
end
def test_unselect_all
form = @page.forms.first
form.radiobuttons_with(:name => 'color').each do |b|
b.uncheck
end
%w{ green red blue yellow brown }.each do |button_value|
assert_equal(false, form.radiobutton_with( :name => 'color',
:value => button_value
).checked)
end
end
def test_click_one
form = @page.forms.first
form.radiobutton_with(:name => 'color', :value => 'green').click
assert form.radiobutton_with(:name => 'color', :value => 'green').checked
%w{ red blue yellow brown }.each do |button_value|
assert_equal(false, form.radiobutton_with( :name => 'color',
:value => button_value
).checked)
end
end
def test_click_twice
form = @page.forms.first
form.radiobutton_with(:name => 'color', :value => 'green').click
assert form.radiobutton_with(:name => 'color', :value => 'green').checked
form.radiobutton_with(:name => 'color', :value => 'green').click
%w{ green red blue yellow brown }.each do |button_value|
assert_equal(false, form.radiobutton_with( :name => 'color',
:value => button_value
).checked)
end
end
def test_click_all
form = @page.forms.first
form.radiobuttons_with(:name => 'color').each do |button|
button.click
end
c = form.radiobuttons_with(:name => 'color').inject(0) do |m,button|
m += 1 if button.checked
m
end
assert_equal 1, c, 'Only one radio button should be checked'
end
end
|