Skip to content

Instantly share code, notes, and snippets.

@shankardevy
Last active August 18, 2017 12:52
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/1186e4da8632dd1fa93a5149cc767188 to your computer and use it in GitHub Desktop.
Save shankardevy/1186e4da8632dd1fa93a5149cc767188 to your computer and use it in GitHub Desktop.
defmodule MangoWeb.Acceptance.SessionTest do
use Mango.DataCase
use Hound.Helpers
hound_session()
setup do
## GIVEN ##
# There is a valid registered user
alias Mango.CRM
valid_attrs = %{
"name" => "John",
"email" => "john@example.com",
"password" => "secret",
"residence_area" => "Area 1",
"phone" => "1111"
}
{:ok, _} = CRM.create_customer(valid_attrs)
:ok
end
test "successful login for valid credential" do
## When ##
navigate_to("/login")
form = find_element(:id, "session-form")
find_within_element(form, :name, "session[email]")
|> fill_field("john@example.com")
find_within_element(form, :name, "session[password]")
|> fill_field("secret")
find_within_element(form, :tag, "button")
|> click
## THEN ##
assert current_path() == "/"
message = find_element(:class, "alert-info")
|> visible_text()
assert message == "Login successful"
end
test "shows error message for invalid credentials" do
## WHEN ##
navigate_to("/login")
form = find_element(:id, "session-form")
find_within_element(form, :tag, "button")
|> click
## THEN ##
assert current_path() == "/login"
message = find_element(:class, "alert-danger") |> visible_text()
assert message == "Invalid username/password combination"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment