Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / MonoRail / WatirTestCases / AjaxHelper / ajaxhelper.rb
blob276c7faaa53ca3c15f2bf54326ca52c9cd398268
1 ## Copyright 2004-2007 Castle Project - http://www.castleproject.org/\r
2 ## \r
3 ## Licensed under the Apache License, Version 2.0 (the "License");\r
4 ## you may not use this file except in compliance with the License.\r
5 ## You may obtain a copy of the License at\r
6 ## \r
7 ##     http://www.apache.org/licenses/LICENSE-2.0\r
8 ## \r
9 ## Unless required by applicable law or agreed to in writing, software\r
10 ## distributed under the License is distributed on an "AS IS" BASIS,\r
11 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 ## See the License for the specific language governing permissions and\r
13 ## limitations under the License.\r
15 require 'rubygems'\r
16 require 'watir'\r
17 require 'test/unit'\r
18 require 'test/unit/ui/console/testrunner'\r
20 include Watir\r
22 require '../common'\r
24 # Test cases for MonoRail AjaxHelper\r
26 class ObserveFieldTestCase < Test::Unit::TestCase\r
27         include CommonIEDriver\r
29         def test_fieldchange()\r
30                 $ie.goto("#{$base_url}/ajax/observefield.rails")\r
32                 content = 'hello!';\r
33                 \r
34                 $ie.text_field(:id, "zip").set(content)\r
35                 \r
36                 sleep 2\r
37                 \r
38                 assert_equal("Address #{content}", $ie.div(:id, 'address').text)\r
39         end\r
41 end\r
43 class ObserveFormTestCase < Test::Unit::TestCase\r
44         include CommonIEDriver\r
46         def test_fieldchange()\r
47                 $ie.goto("#{$base_url}/ajax/observeform.rails")\r
49                 name = 'hammett';\r
50                 address = 'sao paulo';\r
51                 \r
52                 $ie.text_field(:id, "name").set(name)\r
53                 $ie.text_field(:id, "addressf").set(address)\r
54                 \r
55                 sleep 2\r
56                 \r
57                 assert_equal("name #{name} address #{address}", $ie.div(:id, 'message').text)\r
58         end\r
60 end\r
62 class PeriodicallyCallRemoteTestCase < Test::Unit::TestCase\r
63         include CommonIEDriver\r
65         def test_fieldchange()\r
66                 $ie.goto("#{$base_url}/ajax/periodicallycall.rails")\r
68                 $ie.text_field(:id, "value").set('1')\r
69                 \r
70                 sleep 2\r
71                 \r
72                 assert_equal("2", $ie.div(:id, 'newValue').text)\r
74                 $ie.text_field(:id, "value").set('4')\r
75                 \r
76                 sleep 2\r
77                 \r
78                 assert_equal("8", $ie.div(:id, 'newValue').text)\r
79         end\r
81 end\r
83 class JsProxiesTestCase < Test::Unit::TestCase\r
84         include CommonIEDriver\r
86         def test_parameterless_remote_method()\r
87                 $ie.goto("#{$base_url}/ajax/jsproxies.rails")\r
89                 $ie.button(:id, 'invocableMethodButton').click\r
90                 \r
91                 sleep 1\r
92                 \r
93                 assert_equal("Success", $ie.div(:id, 'result').text)\r
94         end\r
95         \r
96         def test_parameterful_remote_method()\r
97                 $ie.goto("#{$base_url}/ajax/jsproxies.rails")\r
99                 $ie.button(:id, 'anotherMethodButton').click\r
100                 \r
101                 sleep 1\r
102                 \r
103                 assert_equal("Success something", $ie.div(:id, 'result').text)\r
104         end\r
106 end\r
108 class FormRemoteTagTestCase < Test::Unit::TestCase\r
109         include CommonIEDriver\r
111         def test_submit_form_async()\r
112                 $ie.goto("#{$base_url}/ajax/formremotetag.rails")\r
114                 $ie.text_field(:id, "name").set('hammett')\r
115                 $ie.text_field(:id, "email").set('hammett@apache.org')\r
117                 $ie.button(:id, 'sub').click\r
118                 \r
119                 sleep 1\r
120                 \r
121                 assert_equal("hammett", $ie.span(:id, 'hammett_name').text)\r
122                 assert_equal("hammett@apache.org", $ie.span(:id, 'hammett_email').text)\r
123         end\r
125 end\r
127 class CastleTests\r
128         def self.suite\r
129                 suite = Test::Unit::TestSuite.new\r
130                 suite << ObserveFieldTestCase.suite\r
131                 suite << ObserveFormTestCase.suite\r
132                 suite << PeriodicallyCallRemoteTestCase.suite\r
133                 suite << JsProxiesTestCase.suite\r
134                 suite << FormRemoteTagTestCase.suite\r
135                 return suite\r
136         end\r
137 end\r
139 $base_url = "http://localhost:88"\r
141 $ie = IE.new()\r
142 #$ie.set_fast_speed\r
143 Test::Unit::UI::Console::TestRunner.run(CastleTests)\r
144 #$ie.close\r