File: test_mechanize_form_textarea.rb

package info (click to toggle)
ruby-mechanize 2.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,416 kB
  • sloc: ruby: 11,645; makefile: 7; sh: 4
file content (53 lines) | stat: -rw-r--r-- 1,605 bytes parent folder | download
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
# frozen_string_literal: true
require 'mechanize/test_case'

class TestMechanizeFormTextarea < Mechanize::TestCase
  def setup
    super

    @page  = @mech.get("http://localhost/tc_textarea.html")
  end

  def test_empty_text_area
    form = @page.forms_with(:name => 'form1').first
    assert_equal('', form.field_with(:name => 'text1').value)
    form.text1 = 'Hello World'
    assert_equal('Hello World', form.field_with(:name => 'text1').value)
    page = @mech.submit(form)
    assert_equal(1, page.links.length)
    assert_equal('text1:Hello World', page.links[0].text)
  end

  def test_non_empty_textfield
    form = @page.forms_with(:name => 'form2').first
    assert_equal('sample text', form.field_with(:name => 'text1').value)
    page = @mech.submit(form)
    assert_equal(1, page.links.length)
    assert_equal('text1:sample text', page.links[0].text)
  end

  def test_multi_textfield
    form = @page.form_with(:name => 'form3')

    assert_equal(2, form.fields_with(:name => 'text1').length)
    assert_equal('', form.fields_with(:name => 'text1')[0].value)
    assert_equal('sample text', form.fields_with(:name => 'text1')[1].value)

    form.text1 = 'Hello World'

    assert_equal('Hello World', form.fields_with(:name => 'text1')[0].value)
    assert_equal('sample text', form.fields_with(:name => 'text1')[1].value)

    page = @mech.submit(form)

    assert_equal(2, page.links.length)

    link = page.links_with(:text => 'text1:sample text')

    assert_equal(1, link.length)

    link = page.links_with(:text => 'text1:Hello World')

    assert_equal(1, link.length)
  end
end