Permalink
Browse files

Consolidate header and footer templates

  • Loading branch information...
testinfected committed Sep 4, 2012
1 parent 6be8436 commit 3116c8d39de16f16078b4f6d071ec4a7c65db696
View
@@ -1,5 +1,4 @@
o Rename infra to persistence
-o Have header and footer templates instead of fragments
o Replace Velocity with StringTemplate or Mustache
o Fix layout of header
o Use wildcard matchers in windowlicker to get rid of being() sugar ?
@@ -62,7 +62,7 @@
</bean>
<bean class="com.pyxis.petstore.util.FileSystemPhotoStore">
- <constructor-arg value="attachments/products"/>
+ <constructor-arg value="/attachments/products"/>
</bean>
<context:component-scan base-package="com.pyxis.petstore.domain"/>
@@ -0,0 +1,8 @@
+<hr/>
+<div id="logout-box">
+ <form action="$base/logout" method="post">
+ <input type="hidden" name="_method" value="delete"/>
+ <button id="logout"></button>
+ </form></div>
+<a href="http://www.pyxis-tech.com/en/home"><img src="$base/images/pyxis.png"/></a>
+<span>jPetStore &copy; 2010 - PSD @</span>
@@ -0,0 +1,37 @@
+<div class="content">
+ <div id="logo">
+ <a href="$base/">
+ <img src="$base/images/logo.png"/>
+ </a>
+ </div>
+
+ <div id="search-box">
+ <form action="$base/products" method="get">
+ <input id="keyword" name="keyword" type="text" size="20"/>
+ <button id="search">
+ <img src="$base/images/magnifier.png"/>
+ </button>
+ </form>
+ </div>
+
+ <div id="menu">
+ <ul>
+ #set ($section = $page.getProperty("meta.section"))
+ <li id="home" #if (!$section) class="overline" #end>
+ <a href="$base/">Home</a></li>
+
+ ## Spring aop proxy prefix bean names with scopedTarget
+ #set( $cart = $session.getAttribute('scopedTarget.cart') )
+ <li id="shopping-cart" #if($section == 'cart') class="overline" #end>
+ #if ($cart && !$cart.empty)
+ <a href="$base/cart" id="view_cart">Cart ($cart.totalQuantity)</a>
+ #else
+ Cart (0)
+ #end
+ </li>
+ </ul>
+ <div #if(!$section) id="home-tab" #else id="cart-tab" #end>
+ <img src="$base/images/tab.png"/>
+ </div>
+ </div>
+</div>
@@ -1,3 +0,0 @@
-<a href="$base/">
- <img src="$base/images/logo.png"/>
-</a>
@@ -1,4 +0,0 @@
-<form action="$base/logout" method="post">
- <input type="hidden" name="_method" value="delete"/>
- <button id="logout"></button>
-</form>
@@ -1,18 +0,0 @@
-<ul>
- #set ($section = $page.getProperty("meta.section"))
- <li id="home" #if (!$section) class="overline" #end>
- <a href="$base/">Home</a></li>
-
- ## Spring aop proxy prefix bean names with scopedTarget
- #set( $cart = $session.getAttribute('scopedTarget.cart') )
- <li id="shopping-cart" #if($section == 'cart') class="overline" #end>
- #if ($cart && !$cart.empty)
- <a href="$base/cart" id="view_cart">Cart ($cart.totalQuantity)</a>
- #else
- Cart (0)
- #end
- </li>
-</ul>
-<div #if(!$section) id="home-tab" #else id="cart-tab" #end>
- <img src="$base/images/tab.png"/>
-</div>
@@ -1,6 +0,0 @@
-<form action="$base/products" method="get">
- <input id="keyword" name="keyword" type="text" size="20"/>
- <button id="search">
- <img src="$base/images/magnifier.png"/>
- </button>
-</form>
@@ -12,18 +12,7 @@
<div id="wrapper">
<div id="header">
- <div class="content">
- <div id="logo">
- #parse("_logo.vm")
- </div>
-
- <div id="search-box">
- #parse("_search.vm")
- </div>
- <div id="menu">
- #parse("_menu.vm")
- </div>
- </div>
+#parse("_header.vm")
</div>
<div class="content">
@@ -34,12 +23,7 @@
</div>
<div id="footer">
- <hr/>
- <div id="logout-box">
- #parse("_logout.vm")
- </div>
- <a href="http://www.pyxis-tech.com/en/home"><img src="$base/images/pyxis.png"/></a>
- <span>jPetStore &copy; 2010 - PSD @</span>
+#parse("_footer.vm")
</div>
</body>
@@ -16,7 +16,7 @@
#foreach ($product in $productList)
<li id="product-$product.number">
<a class="product-link" href="$base/products/$product.number/items">
- <img src="$base/$product.getPhotoLocation($attachments)"/></a>
+ <img src="$base$product.getPhotoLocation($attachments)"/></a>
<div class='product-details'>
<a href="$base/products/$product.number/items"><span class="product-name">$product.name</span></a>
@@ -0,0 +1,39 @@
+package test.com.pyxis.petstore.view;
+
+import org.hamcrest.Matcher;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Element;
+import test.support.com.pyxis.petstore.views.Routes;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.testinfected.hamcrest.dom.DomMatchers.anElement;
+import static org.testinfected.hamcrest.dom.DomMatchers.hasAttribute;
+import static org.testinfected.hamcrest.dom.DomMatchers.hasChildren;
+import static org.testinfected.hamcrest.dom.DomMatchers.hasSelector;
+import static org.testinfected.hamcrest.dom.DomMatchers.hasTag;
+import static test.support.com.pyxis.petstore.views.VelocityRendering.render;
+
+public class FooterTest {
+
+ String FOOTER_PARTIAL = "decorators/_footer";
+ Routes routes = Routes.to("/petstore");
+ Element footer;
+
+ @Before public void
+ renderFooter() {
+ footer = render(FOOTER_PARTIAL).using(routes).asDom();
+ }
+
+ @SuppressWarnings("unchecked") @Test public void
+ containsLogoutButtonThatSubmitsADeleteRequest() {
+ assertThat("footer", footer, hasLogoutForm(hasAttribute("action", routes.logoutPath()), hasAttribute("method", "post")));
+ assertThat("footer", footer, hasLogoutForm(hasChildren(
+ anElement(hasTag("input"), hasAttribute("type", "hidden"), hasAttribute("name", "_method"), hasAttribute("value", "delete")),
+ anElement(hasTag("button")))));
+ }
+
+ private Matcher<Element> hasLogoutForm(Matcher<Element>... formMatchers) {
+ return hasSelector("#logout-box form", formMatchers);
+ }
+}
@@ -0,0 +1,83 @@
+package test.com.pyxis.petstore.view;
+
+import org.hamcrest.Matcher;
+import org.junit.Test;
+import org.w3c.dom.Element;
+import test.support.com.pyxis.petstore.views.Routes;
+import test.support.com.pyxis.petstore.views.VelocityRendering;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.equalToIgnoringCase;
+import static org.testinfected.hamcrest.dom.DomMatchers.anElement;
+import static org.testinfected.hamcrest.dom.DomMatchers.hasAttribute;
+import static org.testinfected.hamcrest.dom.DomMatchers.hasChildren;
+import static org.testinfected.hamcrest.dom.DomMatchers.hasId;
+import static org.testinfected.hamcrest.dom.DomMatchers.hasNoSelector;
+import static org.testinfected.hamcrest.dom.DomMatchers.hasTag;
+import static org.testinfected.hamcrest.dom.DomMatchers.hasText;
+import static org.testinfected.hamcrest.dom.DomMatchers.hasUniqueSelector;
+import static test.support.com.pyxis.petstore.builders.CartBuilder.aCart;
+import static test.support.com.pyxis.petstore.builders.ItemBuilder.anItem;
+import static test.support.com.pyxis.petstore.views.ModelBuilder.aModel;
+import static test.support.com.pyxis.petstore.views.VelocityRendering.render;
+
+public class HeaderTest {
+
+ String HEADER_TEMPLATE = "decorators/_header";
+ Routes routes = Routes.to("/petstore");
+ Element header;
+
+ @Test public void
+ linkToCartIsInactiveWhenCartIsEmpty() {
+ header = renderHeader().using(aModel().with(aCart())).asDom();
+ assertThat("header", header, hasNoSelector("#shopping-cart a"));
+ assertThat("header", header, hasText(containsString("0")));
+ }
+
+ @SuppressWarnings("unchecked") @Test public void
+ linkToCartDisplaysCartItemsCount() throws Exception {
+ header = renderHeader().using(aModel().with(aCart().containing(anItem(), anItem()))).asDom();
+ assertThat("header", header,
+ hasUniqueSelector("#shopping-cart a",
+ hasAttribute("href", routes.cartPath()),
+ hasText(containsString("2"))));
+ }
+
+ @Test public void
+ linkToHomeReturnsToToHomePage() {
+ header = renderHeader().asDom();
+ assertThat("header", header, hasUniqueSelector("#home a", hasAttribute("href", routes.homePath())));
+ }
+
+ @Test public void
+ logoLinksToHomePage() {
+ header = renderHeader().asDom();
+ assertThat("content", header, hasUniqueSelector("#logo a", hasAttribute("href", routes.homePath())));
+ }
+
+ @SuppressWarnings("unchecked") @Test public void
+ containsASearchBoxToQueryTheProductCatalog() {
+ header = renderHeader().asDom();
+ assertThat("header", header,
+ hasUniqueSelector("#search-box form",
+ hasAttribute("action", routes.productsPath()),
+ hasAttribute("method", equalToIgnoringCase("GET"))));
+ assertThat("header", header,
+ hasUniqueSelector("#search-box form", hasChildren(keywordInputField(), searchButton())));
+ }
+
+ @SuppressWarnings("unchecked")
+ private Matcher<Element> keywordInputField() {
+ return anElement(hasTag("input"), hasId("keyword"), hasAttribute("type", "text"), hasAttribute("name", "keyword"));
+ }
+
+ @SuppressWarnings("unchecked")
+ private Matcher<Element> searchButton() {
+ return anElement(hasTag("button"), hasId("search"));
+ }
+
+ private VelocityRendering renderHeader() {
+ return render(HEADER_TEMPLATE).using(routes);
+ }
+}
@@ -1,28 +0,0 @@
-package test.com.pyxis.petstore.view;
-
-import org.junit.Test;
-import org.w3c.dom.Element;
-import test.support.com.pyxis.petstore.views.Routes;
-import test.support.com.pyxis.petstore.views.VelocityRendering;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.testinfected.hamcrest.dom.DomMatchers.hasAttribute;
-import static org.testinfected.hamcrest.dom.DomMatchers.hasUniqueSelector;
-import static test.support.com.pyxis.petstore.views.VelocityRendering.render;
-
-public class LogoPartialTest {
-
- Routes routes = Routes.toPetstore();
- String LOGO_PARTIAL_NAME = "decorators/_logo";
- Element partial;
-
- @Test public void
- linksToHomePage() {
- partial = renderLogoPartial().asDom();
- assertThat("partial", partial, hasUniqueSelector("a", hasAttribute("href", routes.homePath())));
- }
-
- private VelocityRendering renderLogoPartial() {
- return render(LOGO_PARTIAL_NAME).using(routes);
- }
-}
@@ -1,54 +0,0 @@
-package test.com.pyxis.petstore.view;
-
-import org.junit.Test;
-import org.w3c.dom.Element;
-import test.support.com.pyxis.petstore.views.Routes;
-import test.support.com.pyxis.petstore.views.VelocityRendering;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsString;
-import static org.testinfected.hamcrest.dom.DomMatchers.hasAttribute;
-import static org.testinfected.hamcrest.dom.DomMatchers.hasNoSelector;
-import static org.testinfected.hamcrest.dom.DomMatchers.hasText;
-import static org.testinfected.hamcrest.dom.DomMatchers.hasUniqueSelector;
-import static test.support.com.pyxis.petstore.builders.CartBuilder.aCart;
-import static test.support.com.pyxis.petstore.builders.ItemBuilder.anItem;
-import static test.support.com.pyxis.petstore.views.ModelBuilder.aModel;
-import static test.support.com.pyxis.petstore.views.VelocityRendering.render;
-
-public class MenuPartialTest {
-
- Routes routes =Routes.toPetstore();
- String MENU_PARTIAL_NAME = "decorators/_menu";
- Element menuPartial;
-
- @Test public void
- linkIsInactiveWhenCartIsEmpty() {
- menuPartial = renderMenuPartial().using(aModel().with(aCart())).asDom();
- assertThat("partial", menuPartial, hasNoSelector("#shopping-cart a"));
- assertThat("partial", menuPartial, hasText(containsString("0")));
- }
-
- @Test public void
- linksToHomePage() {
- menuPartial = renderMenuPartial().asDom();
- assertThat("partial", menuPartial, hasUniqueSelector("#home a",
- hasAttribute("href", routes.homePath())));
- }
-
- @SuppressWarnings("unchecked")
- @Test public void
- displaysTotalItemsInCartAndLinksToCart() throws Exception {
- menuPartial = renderMenuPartial().using(aModel().with(
- aCart().containing(anItem(), anItem()))
- ).asDom();
- assertThat("partial", menuPartial,
- hasUniqueSelector("#shopping-cart a",
- hasAttribute("href", routes.cartPath()),
- hasText(containsString("2"))));
- }
-
- private VelocityRendering renderMenuPartial() {
- return render(MENU_PARTIAL_NAME).using(routes);
- }
-}
@@ -70,7 +70,7 @@
named("Labrador").
describedAs("Friendly").
withPhoto("labrador.png"));
- final String photoUrl = "path/to/attachment/labrador.png";
+ final String photoUrl = "/path/to/attachment/labrador.png";
context.checking(new Expectations() {{
allowing(attachmentStorage).getLocation(with("labrador.png")); will(returnValue(photoUrl));
}});
Oops, something went wrong.

0 comments on commit 3116c8d

Please sign in to comment.