示例#1
0
 @Test
 public void linksToHomePage() {
   menuPartial = renderMenuPartial().asDom();
   assertThat(
       "partial",
       menuPartial,
       hasUniqueSelector("#home a", hasAttribute("href", routes.homePath())));
 }
示例#2
0
 @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"))));
 }
示例#3
0
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);
  }
}