Add tests for expand/collapse of token transfers

Co-authored-by: Stamates <stamates@hotmail.com>
pull/637/head
jimmay5469 6 years ago committed by Luke Imhoff
parent 15180b0049
commit ead309152f
  1. 4
      apps/block_scout_web/lib/block_scout_web/templates/address_transaction/_token_transfer.html.eex
  2. 2
      apps/block_scout_web/lib/block_scout_web/templates/address_transaction/_transaction.html.eex
  3. 8
      apps/block_scout_web/test/block_scout_web/features/pages/address_page.ex
  4. 82
      apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs

@ -2,11 +2,11 @@
<%= token_transfer_amount(@token_transfer) %>
<%= link(token_symbol(@token_transfer.token), to: token_path(BlockScoutWeb.Endpoint, :show, @locale, @token_transfer.token.contract_address_hash)) %>
<span data-test="token_transfer_address_hash">
<span data-test="token_transfer_address_hash" data-address_hash="<%= @token_transfer.from_address_hash %>">
<%= BlockScoutWeb.AddressView.display_address_hash(@address, @token_transfer.from_address, @locale, true) %>
</span>
&rarr;
<span data-test="token_transfer_address_hash">
<span data-test="token_transfer_address_hash" data-address_hash="<%= @token_transfer.to_address_hash %>">
<%= BlockScoutWeb.AddressView.display_address_hash(@address, @token_transfer.to_address, @locale, true) %>
</span>

@ -68,7 +68,7 @@
<%= if length(tail) != 0 do %>
<div class="col-md-3 col-lg-2 d-flex flex-column mt-1 mb-2 float-right">
<%= link to: "##{@transaction.hash}", "data-toggle": "collapse", "data-test": "token_transfers_expansion" do %>
See More
<%= gettext "See More" %>
<% end %>
</div>
<% end %>

@ -81,11 +81,15 @@ defmodule BlockScoutWeb.AddressPage do
css("[data-test='token_transfer']", count: count)
end
def token_transfer(address_hash, count: count) do
css("[data-test='token_transfer_address_hash']", count: count, text: to_string(address_hash))
def token_transfer(%Address{hash: address_hash}, count: count) do
css("[data-test='token_transfer_address_hash'][data-address_hash='#{address_hash}']", count: count)
end
def transaction_type do
css("[data-test='transaction_type']")
end
def token_transfers_expansion(%Transaction{hash: transaction_hash}) do
css("[data-transaction-hash='#{transaction_hash}'] [data-test='token_transfers_expansion']")
end
end

@ -285,8 +285,9 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
session
|> AddressPage.visit_page(lincoln)
|> assert_has(AddressPage.token_transfers(count: 1))
|> assert_has(AddressPage.token_transfer(lincoln.hash, count: 1))
|> assert_has(AddressPage.token_transfer(taft.hash, count: 1))
|> assert_has(AddressPage.token_transfer(lincoln, count: 1))
|> assert_has(AddressPage.token_transfer(taft, count: 1))
|> refute_has(AddressPage.token_transfers_expansion(transaction))
end
test "contributor can see only token transfers related to him", %{
@ -330,9 +331,80 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
session
|> AddressPage.visit_page(morty)
|> assert_has(AddressPage.token_transfers(count: 1))
|> assert_has(AddressPage.token_transfer(lincoln.hash, count: 1))
|> assert_has(AddressPage.token_transfer(morty.hash, count: 1))
|> refute_has(AddressPage.token_transfer(taft.hash, count: 1))
|> assert_has(AddressPage.token_transfer(lincoln, count: 1))
|> assert_has(AddressPage.token_transfer(morty, count: 1))
|> refute_has(AddressPage.token_transfer(taft, count: 1))
end
test "transactions with multiple token transfers shows only the first one by default", %{
addresses: addresses,
block: block,
session: session
} do
lincoln = addresses.lincoln
taft = addresses.taft
contract_token_address =
insert(
:address,
contract_code: Explorer.Factory.data("contract_code")
)
insert(:token, contract_address: contract_token_address)
transaction =
:transaction
|> insert(from_address: lincoln, to_address: contract_token_address)
|> with_block(block)
insert_list(
3,
:token_transfer,
from_address: lincoln,
to_address: taft,
transaction: transaction,
token_contract_address: contract_token_address
)
session
|> AddressPage.visit_page(lincoln)
|> assert_has(AddressPage.token_transfer(lincoln, count: 1))
end
test "transactions with multiple token transfers shows all transferrs if expanded", %{
addresses: addresses,
block: block,
session: session
} do
lincoln = addresses.lincoln
taft = addresses.taft
contract_token_address =
insert(
:address,
contract_code: Explorer.Factory.data("contract_code")
)
insert(:token, contract_address: contract_token_address)
transaction =
:transaction
|> insert(from_address: lincoln, to_address: contract_token_address)
|> with_block(block)
insert_list(
3,
:token_transfer,
from_address: lincoln,
to_address: taft,
transaction: transaction,
token_contract_address: contract_token_address
)
session
|> AddressPage.visit_page(lincoln)
|> click(AddressPage.token_transfers_expansion(transaction))
|> assert_has(AddressPage.token_transfer(lincoln, count: 3))
end
end
end

Loading…
Cancel
Save