Skip to content

Instantly share code, notes, and snippets.

@shankardevy
Last active February 7, 2018 03:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shankardevy/0e56a6b9f987ae79e9e62fd09bb16afb to your computer and use it in GitHub Desktop.
Save shankardevy/0e56a6b9f987ae79e9e62fd09bb16afb to your computer and use it in GitHub Desktop.
defmodule MangoWeb.Acceptance.CategoryPageTest do
use ExUnit.Case
use Hound.Helpers
hound_session()
setup do
## GIVEN ##
# There are two products Apple and Tomato priced 100 and 50
# categorized under `fruits` and `vegetables` respectively
:ok
end
test "shows fruits" do
## WHEN ##
# I navigate to fruits page
navigate_to("/categories/fruits")
## THEN ##
# I expect the page title to be "Fruits"
page_title = find_element(:css, ".page-title") |> visible_text()
assert page_title == "Fruits"
# And I expect Tomato in the product displayed
product = find_element(:css, ".product")
product_name = find_within_element(product, :css, ".product-name") |> visible_text()
product_price = find_within_element(product, :css, ".product-price") |> visible_text()
assert product_name == "Apple"
# And I expect its price to be displayed on screen
assert product_price == "100"
# And I expect that Tomato is not present on screen.
refute page_source() =~ "Tomato"
end
test "shows vegetables" do
## WHEN ##
# I navigate to vegetables page
navigate_to("/categories/vegetables")
## THEN ##
# I expect the page title to be "Vegetables"
page_title = find_element(:css, ".page-title") |> visible_text()
assert page_title == "Vegetables"
# And I expect Tomato in the product displayed
product = find_element(:css, ".product")
product_name = find_within_element(product, :css, ".product-name") |> visible_text()
product_price = find_within_element(product, :css, ".product-price") |> visible_text()
assert product_name == "Tomato"
# And I expect its price to be displayed on screen
assert product_price == "50"
# And I expect that Apple is not present on screen.
refute page_source() =~ "Apple"
end
end
@matthamil
Copy link

The comments on lines 20 and 43 don't match with what the tests expect. :)

@shankardevy
Copy link
Author

@matthamil that's a good catch. Corrected the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment