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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
require "helper"
class MultiSelectTest < Test::Unit::TestCase
def setup
@agent = Mechanize.new
end
def test_select_none
page = @agent.get("http://localhost/form_multi_select.html")
form = page.forms.first
form.field_with(:name => 'list').select_none
page = @agent.submit(form)
assert_equal(0, page.links.length)
end
def test_select_all
page = @agent.get("http://localhost/form_multi_select.html")
form = page.forms.first
form.field_with(:name => 'list').select_all
page = @agent.submit(form)
assert_equal(6, page.links.length)
assert_equal(1, page.links_with(:text => 'list:1').length)
assert_equal(1, page.links_with(:text => 'list:2').length)
assert_equal(1, page.links_with(:text => 'list:3').length)
assert_equal(1, page.links_with(:text => 'list:4').length)
assert_equal(1, page.links_with(:text => 'list:5').length)
assert_equal(1, page.links_with(:text => 'list:6').length)
end
def test_click_all
page = @agent.get("http://localhost/form_multi_select.html")
form = page.forms.first
form.field_with(:name => 'list').options.each { |o| o.click }
page = @agent.submit(form)
assert_equal(5, page.links.length)
assert_equal(1, page.links_with(:text => 'list:1').length)
assert_equal(1, page.links_with(:text => 'list:3').length)
assert_equal(1, page.links_with(:text => 'list:4').length)
assert_equal(1, page.links_with(:text => 'list:5').length)
assert_equal(1, page.links_with(:text => 'list:6').length)
end
def test_select_default
page = @agent.get("http://localhost/form_multi_select.html")
form = page.forms.first
page = @agent.submit(form)
assert_equal(1, page.links.length)
assert_equal(1, page.links_with(:text => 'list:2').length)
end
def test_select_one
page = @agent.get("http://localhost/form_multi_select.html")
form = page.forms.first
form.list = 'Aaron'
assert_equal(['Aaron'], form.list)
page = @agent.submit(form)
assert_equal(1, page.links.length)
assert_equal('list:Aaron', page.links.first.text)
end
def test_select_two
page = @agent.get("http://localhost/form_multi_select.html")
form = page.forms.first
form.list = ['1', 'Aaron']
page = @agent.submit(form)
assert_equal(2, page.links.length)
assert_equal(1, page.links_with(:text => 'list:1').length)
assert_equal(1, page.links_with(:text => 'list:Aaron').length)
end
def test_select_three
page = @agent.get("http://localhost/form_multi_select.html")
form = page.forms.first
form.list = ['1', '2', '3']
page = @agent.submit(form)
assert_equal(3, page.links.length)
assert_equal(1, page.links_with(:text => 'list:1').length)
assert_equal(1, page.links_with(:text => 'list:2').length)
assert_equal(1, page.links_with(:text => 'list:3').length)
end
def test_select_three_twice
page = @agent.get("http://localhost/form_multi_select.html")
form = page.forms.first
form.list = ['1', '2', '3']
form.list = ['1', '2', '3']
page = @agent.submit(form)
assert_equal(3, page.links.length)
assert_equal(1, page.links_with(:text => 'list:1').length)
assert_equal(1, page.links_with(:text => 'list:2').length)
assert_equal(1, page.links_with(:text => 'list:3').length)
end
def test_select_with_click
page = @agent.get("http://localhost/form_multi_select.html")
form = page.forms.first
form.list = ['1', 'Aaron']
form.field_with(:name => 'list').options[3].tick
assert_equal(['1', 'Aaron', '4'].sort, form.list.sort)
page = @agent.submit(form)
assert_equal(3, page.links.length)
assert_equal(1, page.links_with(:text => 'list:1').length)
assert_equal(1, page.links_with(:text => 'list:Aaron').length)
assert_equal(1, page.links_with(:text => 'list:4').length)
end
end
|