Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Motivation: - The admin generates a lot of custom html, forms and user interactions. Setup end to end integration tests to make sure that the user's experience is working as expected. - /issues/11 Changes: - Setup Hound - Setup Travis to work with phantomjs - Turn on the server for the test environment and ensure cowboy is running. - Add new integration tests and required support files. - As a first test just test the edit page and dashboard for an example.
- Loading branch information
Showing
14 changed files
with
218 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
defmodule ExAdmin do | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
defmodule TestExAdmin.CreateTest do | ||
use TestExAdmin.AcceptanceCase | ||
alias TestExAdmin.{Noid, User, Product, Simple} | ||
alias Hound.Element | ||
|
||
hound_session | ||
# Start hound session and destroy when tests are run | ||
setup do | ||
user = insert_user() | ||
current_window_handle |> maximize_window | ||
{:ok, user: user} | ||
end | ||
|
||
@tag :integration | ||
test "create a product", %{ user: user } do | ||
navigate_to admin_resource_path(Product, :new) | ||
|
||
title_field = find_element(:name, "product[title]") | ||
price_field = find_element(:name, "product[price]") | ||
user_field = find_element(:name, "product[user_id]") | ||
|
||
fill_field title_field, "Test Create" | ||
fill_field price_field, ".99" | ||
find_element(:css, "select[name*='product[user_id]']") | ||
|> find_all_within_element(:css, "option") | ||
|> Enum.find(fn(x) -> attribute_value(x, "value") == "#{user.id}" end) | ||
|> click | ||
|
||
click(find_element(:name, "commit")) | ||
|
||
assert visible_text(find_element(:class, "td-title")) == "Test Create" | ||
assert visible_text(find_element(:class, "td-price")) == "0.99" | ||
assert visible_text(find_element(:class, "td-user")) == user.name | ||
end | ||
|
||
@tag :integration | ||
test "validate product creation" do | ||
navigate_to admin_resource_path(Product, :new) | ||
click(find_element(:name, "commit")) | ||
|
||
title_wrapper = find_element(:css, "#product_title_input") | ||
price_wrapper = find_element(:css, "#product_price_input") | ||
assert visible_text(title_wrapper) == "Title*\ncan't be blank" | ||
assert visible_text(price_wrapper) == "Price*\ncan't be blank" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule TestExAdmin.DashboardIntegrationTest do | ||
use TestExAdmin.AcceptanceCase | ||
alias TestExAdmin.{Noid, User, Product, Simple} | ||
alias Hound.Element | ||
|
||
hound_session | ||
|
||
@tag :integration | ||
test "gets dashboard" do | ||
navigate_to "/admin" | ||
assert(String.contains? visible_page_text, "dashboard") | ||
end | ||
|
||
@tag :integration | ||
test "dashboard shows sidebar" do | ||
navigate_to "/admin" | ||
assert(String.contains? visible_page_text, "Test Sidebar") | ||
assert(String.contains? visible_page_text, "This is a test.") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
defmodule TestExAdmin.DeleteTest do | ||
use TestExAdmin.AcceptanceCase | ||
alias TestExAdmin.{Noid, User, Product, Simple} | ||
alias Hound.Element | ||
|
||
hound_session | ||
# Start hound session and destroy when tests are run | ||
setup do | ||
user = insert_user() | ||
{:ok, user: user} | ||
end | ||
|
||
# | ||
# This test is pending PhantomJS dialog support | ||
# https://github.com/detro/ghostdriver/issues/20 | ||
# | ||
@tag :pending | ||
test "delete a noid", %{user: user} do | ||
noid = insert_noid(user_id: user.id, name: "controller 1") | ||
user2 = insert_user() | ||
current_window_handle |> maximize_window | ||
navigate_to admin_resource_path(Noid, :index) | ||
|
||
assert page_source =~ noid.name | ||
click(find_element(:class, "delete_link")) | ||
|
||
assert dialog_text() == "Are you sure you want to delete this?" | ||
accept_dialog() | ||
|
||
assert current_url == admin_resource_path(Noid, :index) | ||
refute page_source =~ noid.name | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
defmodule TestExAdmin.UpdateTest do | ||
use TestExAdmin.AcceptanceCase | ||
alias TestExAdmin.{Noid, User, Product, Simple} | ||
alias Hound.Element | ||
|
||
hound_session | ||
# Start hound session and destroy when tests are run | ||
setup do | ||
user = insert_user() | ||
{:ok, user: user} | ||
end | ||
|
||
@tag :integration | ||
test "edit a noid updates correct data", %{user: user} do | ||
noid = insert_noid(user_id: user.id, name: "controller 1") | ||
user2 = insert_user() | ||
current_window_handle |> maximize_window | ||
navigate_to admin_resource_path(Noid, :index) | ||
click(find_element(:class, "edit_link")) | ||
|
||
name_field = find_element(:name, "noid[name]") | ||
description_field = find_element(:name, "noid[description]") | ||
company_field = find_element(:name, "noid[company]") | ||
user_field = find_element(:name, "noid[user_id]") | ||
|
||
assert attribute_value(name_field, "value") == noid.name | ||
assert attribute_value(description_field, "value") == noid.description | ||
assert attribute_value(company_field, "value") == noid.company | ||
assert attribute_value(user_field, "value") == "#{noid.user_id}" | ||
|
||
fill_field name_field, "Cory" | ||
fill_field description_field, "Updated" | ||
fill_field company_field, "This" | ||
|
||
click(find_element(:name, "commit")) | ||
|
||
assert visible_text(find_element(:class, "td-name")) == "Cory" | ||
assert visible_text(find_element(:class, "td-description")) == "Updated" | ||
assert visible_text(find_element(:class, "td-company")) == "This" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
defmodule TestExAdmin.AcceptanceCase do | ||
use ExUnit.CaseTemplate | ||
|
||
using do | ||
quote do | ||
use Hound.Helpers | ||
|
||
import Ecto.Model | ||
import Ecto.Query, only: [from: 2] | ||
|
||
alias TestExAdmin.Repo | ||
import TestExAdmin.Router.Helpers | ||
import TestExAdmin.TestHelpers | ||
import TestExAdmin.ErrorView | ||
import ExAdmin.Utils | ||
import TestExAdmin.TestHelpers | ||
@endpoint TestExAdmin.Endpoint | ||
end | ||
end | ||
|
||
setup tags do | ||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(TestExAdmin.Repo) | ||
metadata = Phoenix.Ecto.SQL.Sandbox.metadata_for(TestExAdmin.Repo, self()) | ||
Hound.start_session(metadata: metadata) | ||
unless tags[:async] do | ||
Ecto.Adapters.SQL.Sandbox.mode(TestExAdmin.Repo, {:shared, self()}) | ||
end | ||
:ok | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule TestExAdmin.Web do | ||
|
||
def view do | ||
quote do | ||
use Phoenix.View, root: "test/support/templates" | ||
# Import convenience functions from controllers | ||
import Phoenix.Controller, only: [get_csrf_token: 0, get_flash: 2, view_module: 1] | ||
|
||
# Use all HTML functionality (forms, tags, etc) | ||
use Phoenix.HTML | ||
|
||
end | ||
end | ||
defmacro __using__(which) when is_atom(which) do | ||
apply(__MODULE__, which, []) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters