}
private Matcher withEmptyText() {
return withText("");
}
@Test
<<<<<<< HEAD
public void displaysAListOfProductsFound() {
assertThat(dom(productsPage),
hasSelector("#products td",
inOrder(hasChild(hasAttribute("src", equalTo("photos/"))),
withText("Dalmatian"),
withText(""),
hasChild(hasAttribute("src", equalTo("photos/labrador"))),
withText("Labrador"),
withText("Friendly"))));
}
=======
public void displaysNameDescriptionAndPhotoOfProductsFoundInDifferentColumns() {
productsPage = renderProductsPageUsing(aModelWith(
aProduct().withName("Labrador").describedAs("Friendly").withPhoto("labrador")));
assertThat(dom(productsPage),
hasSelector("#products td",
inOrder(image("photos/labrador"),
productName("Labrador"),
description("Friendly"))));
}
@Test
public void displaysNothingInDescriptionColumnForAProductWithNoDescription() {
productsPage = renderProductsPageUsing(aModelWith(
aProduct().withName("Labrador").withPhoto("labrador")));
assertThat(dom(productsPage),
hasSelector("#products td:nth-child(3)",
contains(anEmptyDescription())));
}
@Test
public void displaysDefaultPhotoForAProductWithNoPhoto() {
productsPage = renderProductsPageUsing(aModelWith(
aProduct().withName("Labrador").describedAs("Friendly")));
assertThat(dom(productsPage),
hasSelector("#products td:nth-child(1)",
contains(image("photos/"))));
}
private String renderProductsPageUsing(Map model) {
return render(PRODUCTS_VIEW).using(model);
}
private Matcher anEmptyDescription() {
return description("");
}
private Matcher image(String imageUrl) {
return hasChild(hasAttribute("src", equalTo(imageUrl)));
}
private Matcher description(String description) {
return withText(description);
}
private Matcher productName(String name) {
return withText(name);
}
>>>>>>> 9e0e34bef28cdea19cce11be3b726370d7e48155
private Matcher> inOrder(Matcher... elementMatchers) {
return contains(elementMatchers);
} |