PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/2010.Q2.825/Source/Telerik.Web.Mvc.Tests/UI/Window/WindowHtmlBuilderTests.cs

#
C# | 221 lines | 165 code | 56 blank | 0 comment | 0 complexity | 94487ebafe7b96908120730d0f9cd349 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. namespace Telerik.Web.Mvc.UI.Tests
  2. {
  3. using Xunit;
  4. using Infrastructure;
  5. using Moq;
  6. public class WindowHtmlBuilderTests
  7. {
  8. private IWindowHtmlBuilder renderer;
  9. private Window window;
  10. public WindowHtmlBuilderTests()
  11. {
  12. window = WindowTestHelper.CreateWindow(null);
  13. renderer = new WindowHtmlBuilder(window);
  14. window.Name = "Window";
  15. }
  16. [Fact]
  17. public void WindowTag_should_render_div_tag()
  18. {
  19. IHtmlNode tag = renderer.WindowTag();
  20. Assert.Equal(tag.TagName, "div");
  21. }
  22. [Fact]
  23. public void WindowTag_should_render_classes()
  24. {
  25. IHtmlNode tag = renderer.WindowTag();
  26. Assert.Equal(UIPrimitives.Widget.ToString() + " t-window", tag.Attribute("class"));
  27. }
  28. [Fact]
  29. public void WindowTag_should_render_html_attributes()
  30. {
  31. window.HtmlAttributes.Add("title", "genericInput");
  32. IHtmlNode tag = renderer.WindowTag();
  33. Assert.Equal("genericInput", tag.Attribute("title"));
  34. }
  35. [Fact]
  36. public void WindowTag_should_render_id()
  37. {
  38. window.Name = "TestName";
  39. IHtmlNode tag = renderer.WindowTag();
  40. Assert.Equal("TestName", tag.Attribute("id"));
  41. }
  42. [Fact]
  43. public void WindowTag_should_render_style_display_none_if_visible_false()
  44. {
  45. window.Visible = false;
  46. IHtmlNode tag = renderer.WindowTag();
  47. Assert.Contains("display:none", tag.Attribute("style"));
  48. }
  49. [Fact]
  50. public void HeaderTag_should_render_div_tag()
  51. {
  52. IHtmlNode tag = renderer.HeaderTag();
  53. Assert.Equal(tag.TagName, "div");
  54. }
  55. [Fact]
  56. public void HeaderTag_should_render_classes()
  57. {
  58. IHtmlNode tag = renderer.HeaderTag();
  59. Assert.Equal("t-window-titlebar " + UIPrimitives.Header.ToString(), tag.Attribute("class"));
  60. }
  61. [Fact]
  62. public void IconTag_should_render_span_wrapper()
  63. {
  64. const string iconPath = "/Content/Icon.png";
  65. window.IconUrl = iconPath;
  66. IHtmlNode tag = renderer.IconTag();
  67. Assert.Equal("img", tag.TagName);
  68. Assert.Equal(iconPath, tag.Attribute("src"));
  69. Assert.Contains("t-window-icon", tag.Attribute("class"));
  70. Assert.Contains(UIPrimitives.Image, tag.Attribute("class"));
  71. }
  72. [Fact]
  73. public void IconTag_should_render_defoult_alternative_text()
  74. {
  75. const string iconPath = "/Content/Icon.png";
  76. window.IconUrl = iconPath;
  77. window.IconAlternativeText = "";
  78. IHtmlNode tag = renderer.IconTag();
  79. Assert.Equal("icon", tag.Attribute("alt"));
  80. }
  81. [Fact]
  82. public void TitleTag_should_render_span_with_title_text()
  83. {
  84. const string title = "WindowTitle";
  85. window.Title = title;
  86. IHtmlNode tag = renderer.TitleTag();
  87. Assert.Equal("span", tag.TagName);
  88. Assert.Contains("t-window-title", tag.Attribute("class"));
  89. Assert.Contains(title, tag.Children[0].InnerHtml);
  90. }
  91. [Fact]
  92. public void TitleTag_should_render_component_name_if_Title_is_empty()
  93. {
  94. window.Name = "Window";
  95. IHtmlNode tag = renderer.TitleTag();
  96. Assert.Equal("span", tag.TagName);
  97. Assert.Contains("t-window-title", tag.Attribute("class"));
  98. Assert.Contains("Window", tag.Children[0].InnerHtml);
  99. }
  100. [Fact]
  101. public void ButtonTag_should_render_link_with_span_in_it()
  102. {
  103. IHtmlNode linkTag = renderer.ButtonTag(window.Buttons.Container[0]);
  104. IHtmlNode spanTag = linkTag.Children[0];
  105. Assert.Equal("a", linkTag.TagName);
  106. Assert.Contains("#", linkTag.Attribute("href"));
  107. Assert.Contains("t-window-action", linkTag.Attribute("class"));
  108. Assert.Contains(UIPrimitives.Link, linkTag.Attribute("class"));
  109. Assert.Equal("span", spanTag.TagName);
  110. Assert.Equal("Close", spanTag.InnerHtml);
  111. Assert.Contains(UIPrimitives.Icon + " t-close", spanTag.Attribute("class"));
  112. }
  113. [Fact]
  114. public void ContentTag_should_render_div_and_class()
  115. {
  116. IHtmlNode tag = renderer.ContentTag();
  117. Assert.Equal("div", tag.TagName);
  118. Assert.Equal("t-window-content " + UIPrimitives.Content, tag.Attribute("class"));
  119. }
  120. [Fact]
  121. public void ContentTag_should_render_div_tag_with_style()
  122. {
  123. window.Height = 300;
  124. window.Width = 300;
  125. IHtmlNode tag = renderer.ContentTag();
  126. Assert.Equal("overflow:auto;width:300px;height:300px", tag.Attribute("style"));
  127. }
  128. [Fact]
  129. public void ContentTag_should_render_div_tag_with_overflow_hidden_when_scrollable_is_false()
  130. {
  131. window.Height = 300;
  132. window.Width = 300;
  133. window.Scrollable = false;
  134. IHtmlNode tag = renderer.ContentTag();
  135. Assert.Equal("overflow:hidden;width:300px;height:300px", tag.Attribute("style"));
  136. }
  137. [Fact]
  138. public void ContentTag_should_render_IFrame_if_ContentUrl_is_remote()
  139. {
  140. window.ContentUrl = "http://www.abv.bg";
  141. IHtmlNode content = renderer.ContentTag();
  142. Assert.Equal("iframe", content.Children[0].TagName);
  143. }
  144. [Fact]
  145. public void ContentTag_should_render_IFrame_with_url_if_ContentUrl_is_remote()
  146. {
  147. window.ContentUrl = "http://www.abv.bg";
  148. IHtmlNode content = renderer.ContentTag();
  149. Assert.Equal(window.ContentUrl, content.Children[0].Attribute("src"));
  150. }
  151. [Fact]
  152. public void ContentTag_should_not_render_IFrame_if_ContentUrl_is_null()
  153. {
  154. IHtmlNode content = renderer.ContentTag();
  155. Assert.Equal(0, content.Children.Count);
  156. }
  157. [Fact]
  158. public void ContentTag_should_not_render_IFrame_if_ContentUrl_is_local()
  159. {
  160. window.ContentUrl = "/aspnet-mvc-beta/Window/Content";
  161. IHtmlNode content = renderer.ContentTag();
  162. Assert.Equal(0, content.Children.Count);
  163. }
  164. }
  165. }