Minor changes to improve testability of helpers
[castle.git] / MonoRail / WatirTestCases / ARSupport / condition.rb
blobf5a4d903982ca2c22734cf3b95ae4c93186f751b
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 comments and\r
13 ## limitations under the License.\r
15 require '../common'\r
17 class Condition\r
19         class << self\r
21                 include Test::Unit::Assertions\r
23                 def create(ie, name, type_id, *comments)\r
25                         ie.goto("#{$base_url}/condition/new.castle")\r
26                         \r
27                         ie.text_field(:id, "condition_name").set(name)\r
28                         ie.select_list(:id, "condition_ConditionType_id").select_value(type_id.to_s)\r
29                         \r
30                         comments.each { |value|\r
31                                 ie.checkbox(:id, 'condition_comments', value.to_s).set\r
32                         }\r
33                         \r
34                         ie.button(:id, 'insertbutton').click\r
36                         # Check for errors\r
37                         \r
38                         fail('There were databind errors') if ie.contains_text('binding error')\r
39                         fail('Unexpected exception') if ie.contains_text('Exception')\r
40                         \r
41                         assert_equal(name, ie.span(:id, 'name').text)\r
42                         assert_equal(type_id, ie.span(:id, 'type').text) unless type_id == "0"\r
43                         assert_equal(comments.sort!, ie.span(:id, 'comments').text.split(',').sort!)\r
45                         # returns new created id\r
46                         \r
47                         ie.span(:id, 'newid').text\r
48                 end\r
50                 def edit(ie, id, name, type_id, *comments)\r
52                         ie.goto("#{$base_url}/condition/edit.castle?id=#{id}")\r
53                         \r
54                         ie.text_field(:id, "condition_name").set(name)\r
55                         ie.select_list(:id, "condition_ConditionType_id").select_value(type_id.to_s)\r
56                         \r
57                         # ie.checkboxes.each { |check| check.clear() }\r
58                         \r
59                         # comments.each { |value|\r
60                         #       ie.checkbox(:id, 'condition_comments', value.to_s).set\r
61                         # }\r
62                         \r
63                         ie.button(:id, 'updatebutton').click\r
65                         # Check for errors\r
66                         \r
67                         fail('There were databind errors') if ie.contains_text('binding error')\r
68                         fail('Unexpected exception') if ie.contains_text('Exception')\r
69                         \r
70                         assert_equal(name, ie.span(:id, 'name').text)\r
71                         assert_equal(type_id, ie.span(:id, 'type').text) unless type_id == "0"\r
72                         assert_equal(comments.sort!, ie.span(:id, 'comments').text.split(',').sort!)\r
73                 end\r
74                 \r
75         end\r
77 end\r