Convert remaining feature tests to use page modules

Remove catchall contributor browsing test
pull/199/head
Tim Mecklem 7 years ago
parent 2e058cf94c
commit 69d5fd8901
  1. 4
      apps/explorer_web/lib/explorer_web/templates/block/index.html.eex
  2. 2
      apps/explorer_web/lib/explorer_web/templates/chain/_blocks.html.eex
  3. 196
      apps/explorer_web/test/explorer_web/features/contributor_browsing_test.exs
  4. 17
      apps/explorer_web/test/explorer_web/features/pages/block_list_page.ex
  5. 4
      apps/explorer_web/test/explorer_web/features/pages/home_page.ex
  6. 2
      apps/explorer_web/test/explorer_web/features/viewing_addresses_test.exs
  7. 34
      apps/explorer_web/test/explorer_web/features/viewing_blocks_test.exs

@ -31,7 +31,9 @@
<%= link(
block,
class: "blocks__link",
to: block_path(@conn, :show, @conn.assigns.locale, block)
to: block_path(@conn, :show, @conn.assigns.locale, block),
"data-test": "block_number",
"data-block-number": to_string(block.number)
) %>
</td>
<td><%= block.timestamp |> Timex.from_now %></td>

@ -13,7 +13,7 @@
</thead>
<tbody>
<%= for block <- @chain.blocks do %>
<tr>
<tr data-test="chain_block">
<td>
<img src="<%= static_path(@conn, "/images/block.svg") %>" />
<%= link(block, to: block_path(@conn, :show, @conn.assigns.locale, block)) %>

@ -1,196 +0,0 @@
defmodule ExplorerWeb.ContributorBrowsingTest do
use ExplorerWeb.FeatureCase, async: true
import Wallaby.Query, only: [css: 1, css: 2, link: 1]
alias Explorer.Chain.{Credit, Debit}
alias ExplorerWeb.{AddressPage, BlockPage, HomePage, TransactionPage}
@logo css("[data-test='header_logo']")
test "search for blocks", %{session: session} do
block = insert(:block, number: 42)
session
|> HomePage.visit_page()
|> HomePage.search(to_string(block.number))
|> assert_has(BlockPage.detail_number(block))
end
test "search for transactions", %{session: session} do
transaction = insert(:transaction, input: "0x736f636b73")
session
|> HomePage.visit_page()
|> HomePage.search(to_string(transaction.hash))
|> assert_has(TransactionPage.detail_hash(transaction))
end
test "search for address", %{session: session} do
address = insert(:address)
session
|> HomePage.visit_page()
|> HomePage.search(to_string(address.hash))
|> assert_has(AddressPage.detail_hash(address))
end
test "views blocks", %{session: session} do
timestamp = Timex.now() |> Timex.shift(hours: -1)
Enum.map(307..310, &insert(:block, number: &1, timestamp: timestamp, gas_used: 10))
fifth_block =
insert(:block, %{
gas_limit: 5_030_101,
gas_used: 1_010_101,
nonce: 123_456_789,
number: 311,
size: 9_999_999,
timestamp: timestamp
})
transaction = insert(:transaction, block_hash: fifth_block.hash, index: 0)
insert(:transaction, block_hash: fifth_block.hash, index: 1)
insert(:transaction, block_hash: fifth_block.hash, index: 2)
insert(:receipt, transaction_hash: transaction.hash, transaction_index: transaction.index)
Credit.refresh()
Debit.refresh()
session
|> visit("/en")
|> assert_has(css(".blocks__title", text: "Blocks"))
|> assert_has(css(".blocks__column--height", count: 2, text: "1"))
|> assert_has(css(".blocks__column--transactions-count", count: 5))
|> assert_has(css(".blocks__column--transactions-count", count: 1, text: "3"))
|> assert_has(css(".blocks__column--age", count: 5, text: "1 hour ago"))
|> assert_has(css(".blocks__column--gas-used", count: 5, text: "10"))
session
|> click(link("Blocks"))
|> assert_has(css(".blocks__column--height", text: "311"))
|> click(link("311"))
|> assert_has(css(".block__item", text: to_string(fifth_block.hash)))
|> assert_has(css(".block__item", text: to_string(fifth_block.miner_hash)))
|> assert_has(css(".block__item", text: "9,999,999"))
|> assert_has(css(".block__item", text: "1 hour ago"))
|> assert_has(css(".block__item", text: "5,030,101"))
|> assert_has(css(".block__item", text: to_string(fifth_block.nonce)))
|> assert_has(css(".block__item", text: "1,010,101"))
|> click(css(".block__link", text: "Transactions"))
|> assert_has(css(".transactions__link--long-hash", text: to_string(transaction.hash)))
end
describe "transactions and address pages" do
setup do
block =
insert(:block, %{
number: 555,
timestamp: Timex.now() |> Timex.shift(hours: -2),
gas_used: 123_987
})
for index <- 0..3, do: insert(:transaction, block_hash: block.hash, index: index)
pending = insert(:transaction, block_hash: nil, gas: 5891, index: nil)
lincoln = insert(:address)
taft = insert(:address)
transaction =
insert(
:transaction,
block_hash: block.hash,
value: Explorer.Chain.Wei.from(Decimal.new(5656), :ether),
gas: Decimal.new(1_230_000_000_000_123_123),
gas_price: Decimal.new(7_890_000_000_898_912_300_045),
index: 4,
input: "0x000012",
nonce: 99045,
inserted_at: Timex.parse!("1970-01-01T00:00:18-00:00", "{ISO:Extended}"),
updated_at: Timex.parse!("1980-01-01T00:00:18-00:00", "{ISO:Extended}"),
from_address_hash: taft.hash,
to_address_hash: lincoln.hash
)
receipt = insert(:receipt, status: :ok, transaction_hash: transaction.hash, transaction_index: transaction.index)
insert(:log, address_hash: lincoln.hash, index: 0, transaction_hash: receipt.transaction_hash)
# From Lincoln to Taft.
txn_from_lincoln =
insert(
:transaction,
block_hash: block.hash,
index: 5,
from_address_hash: lincoln.hash,
to_address_hash: taft.hash
)
internal_receipt =
insert(:receipt, transaction_hash: txn_from_lincoln.hash, transaction_index: txn_from_lincoln.index)
internal = insert(:internal_transaction, transaction_hash: internal_receipt.transaction_hash)
Credit.refresh()
Debit.refresh()
{:ok,
%{
pending: pending,
internal: internal,
lincoln: lincoln,
taft: taft,
transaction: transaction,
txn_from_lincoln: txn_from_lincoln
}}
end
test "see's all addresses transactions by default", %{
lincoln: lincoln,
session: session,
transaction: transaction,
txn_from_lincoln: txn_from_lincoln
} do
session
|> visit("/en/addresses/#{Phoenix.Param.to_param(lincoln)}")
|> assert_has(css(".transactions__link--long-hash", text: to_string(transaction.hash)))
|> assert_has(css(".transactions__link--long-hash", text: to_string(txn_from_lincoln.hash)))
end
test "can filter to only see transactions to an address", %{
lincoln: lincoln,
session: session,
transaction: transaction,
txn_from_lincoln: txn_from_lincoln
} do
session
|> visit("/en/addresses/#{Phoenix.Param.to_param(lincoln)}")
|> click(css("[data-test='filter_dropdown']", text: "Filter: All"))
|> click(css(".address__link", text: "To"))
|> assert_has(css(".transactions__link--long-hash", text: to_string(transaction.hash)))
|> refute_has(css(".transactions__link--long-hash", text: to_string(txn_from_lincoln.hash)))
end
test "can filter to only see transactions from an address", %{
lincoln: lincoln,
session: session,
transaction: transaction,
txn_from_lincoln: txn_from_lincoln
} do
session
|> visit("/en/addresses/#{Phoenix.Param.to_param(lincoln)}")
|> click(css("[data-test='filter_dropdown']", text: "Filter: All"))
|> click(css(".address__link", text: "From"))
|> assert_has(css(".transactions__link--long-hash", text: to_string(txn_from_lincoln.hash)))
|> refute_has(css(".transactions__link--long-hash", text: to_string(transaction.hash)))
end
end
test "views addresses", %{session: session} do
address = insert(:address, fetched_balance: 500)
session
|> visit("/en/addresses/#{Phoenix.Param.to_param(address)}")
|> assert_has(css(".address__balance", text: "0.000,000,000,000,000,500 POA"))
end
end

@ -0,0 +1,17 @@
defmodule ExplorerWeb.BlockListPage do
@moduledoc false
use Wallaby.DSL
import Wallaby.Query, only: [css: 1]
alias Explorer.Chain.Block
def visit_page(session) do
visit(session, "/en/blocks")
end
def block(%Block{number: block_number}) do
css("[data-test='block_number'][data-block-number='#{block_number}']")
end
end

@ -5,6 +5,10 @@ defmodule ExplorerWeb.HomePage do
import Wallaby.Query, only: [css: 1, css: 2]
def blocks(count: count) do
css("[data-test='chain_block']", count: count)
end
def search(session, text) do
session
|> fill_in(css("[data-test='search_input']"), with: text)

@ -1,4 +1,4 @@
defmodule ExplorerWeb.AddressPageTest do
defmodule ExplorerWeb.ViewingAddressesTest do
use ExplorerWeb.FeatureCase, async: true
alias ExplorerWeb.AddressPage

@ -0,0 +1,34 @@
defmodule ExplorerWeb.ViewingBlocksTest do
use ExplorerWeb.FeatureCase, async: true
alias ExplorerWeb.{BlockListPage, HomePage}
setup do
timestamp = Timex.now() |> Timex.shift(hours: -1)
Enum.map(307..310, &insert(:block, number: &1, timestamp: timestamp, gas_used: 10))
block =
insert(:block, %{
gas_limit: 5_030_101,
gas_used: 1_010_101,
nonce: 123_456_789,
number: 311,
size: 9_999_999,
timestamp: timestamp
})
{:ok, block: block}
end
test "viewing blocks on the home page", %{session: session} do
session
|> HomePage.visit_page()
|> assert_has(HomePage.blocks(count: 5))
end
test "viewing the blocks index page", %{block: block, session: session} do
session
|> BlockListPage.visit_page()
|> assert_has(BlockListPage.block(block))
end
end
Loading…
Cancel
Save