1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Views
.Brail
.Tests
17 using Castle
.MonoRail
.Framework
.Tests
;
18 using NUnit
.Framework
;
21 public class JSGenerationTestCase
: AbstractTestCase
23 #region Stock operations
26 public void ReplaceHtml()
28 DoGet("jsgeneration/replacehtml.rails");
30 AssertReplyContains("Element.update(\"aa\",\"new content\");");
34 public void ReplaceHtmlUsingPartial()
36 DoGet("jsgeneration/replacehtmlwithpartial.rails");
38 AssertReplyContains("Element.update(\"aa\",\"You\'re hammett <br> [ a ][ b ]\")");
44 DoGet("jsgeneration/replace.rails");
46 AssertReplyContains("Element.replace(\"aa\",\"new content\")");
50 public void InsertHtml()
52 DoGet("jsgeneration/InsertHtml.rails");
54 AssertReplyContains("new Insertion.Top(\"aa\",\"new content\");");
55 AssertReplyContains("new Insertion.Bottom(\"aa\",\"new content\");");
56 AssertReplyContains("new Insertion.After(\"aa\",\"new content\");");
57 AssertReplyContains("new Insertion.Before(\"aa\",\"new content\");");
61 public void VisualEffect()
63 DoGet("jsgeneration/visualeffect.rails");
65 AssertReplyContains("Effect.Highlight('element1', {});");
66 AssertReplyContains("Effect.Highlight('element1', {duration:4});");
70 public void ShowHideToggleRemove()
72 DoGet("jsgeneration/multipleactions.rails");
74 AssertReplyContains("Element.show(\"a\");");
75 AssertReplyContains("Element.show(\"a\",\"b\",\"c\");");
76 AssertReplyContains("Element.hide(\"a\");");
77 AssertReplyContains("Element.hide(\"a\",\"b\",\"c\");");
78 AssertReplyContains("Element.toggle(\"a\");");
79 AssertReplyContains("Element.toggle(\"a\",\"b\",\"c\");");
80 AssertReplyContains("[\"a\",\"b\",\"c\"].each(Element.remove);");
86 DoGet("jsgeneration/mr264.rails");
88 "Element.update(\"holder\",\"test\");\r\n"+
89 "new Effect.Highlight('holder', {});");
94 #region Element related
97 public void SimpleElementAccess()
99 DoGet("jsgeneration/elementaccess.rails");
101 AssertReplyContains("$('aa');");
105 public void AccessingElementAttribute()
107 DoGet("jsgeneration/elementattribute.rails");
109 AssertReplyContains("$('aa').className = \"newclass\";");
113 public void AccessingElementAttributeDepth()
115 DoGet("jsgeneration/elementattributedepth.rails");
117 AssertReplyContains("$('aa').style.display = \"none\";");
121 public void AccessingElementMethod()
123 DoGet("jsgeneration/elementmethod.rails");
125 AssertReplyContains("$('aa').hide();");
129 public void AccessingElementMethodDepth()
131 DoGet("jsgeneration/elementmethoddepth.rails");
133 AssertReplyContains("$('aa').read().test();");
137 public void AccessingElementStockOperationReplaceHtml()
139 DoGet("jsgeneration/elementreplacehtml.rails");
141 AssertReplyContains("$('aa').update(\"new content\")");
145 public void AccessingElementStockOperationReplace()
147 DoGet("jsgeneration/elementreplace.rails");
149 AssertReplyContains("$('aa').replace(\"new content\")");
154 #region Select related
157 public void SimpleCollectionAccess()
159 DoGet("jsgeneration/collectionaccess.rails");
161 AssertReplyContains("$$('aa');");
165 public void CollectionFirstLast()
167 DoGet("jsgeneration/collectionfirstlast.rails");
169 AssertReplyContains("$$('p.welcome b').first().hide();");
170 AssertReplyContains("$$('p.welcome b').last().show();");