-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I was unable to make infinite scrolling work, so I resorted to prev page/next page buttons instead. The `hero-arrow-left-circle-mini` icon would not display correctly, so I submitted [a PR](tailwindlabs/heroicons#1211) upstream and am now using my fork.
- Loading branch information
1 parent
4737c8f
commit 39b2636
Showing
6 changed files
with
143 additions
and
34 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
70 changes: 70 additions & 0 deletions
70
test/freedom_account_web/components/fund_transaction_test.exs
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,70 @@ | ||
defmodule FreedomAccountWeb.FundTransactionTest do | ||
use FreedomAccountWeb.ConnCase, async: true | ||
|
||
alias FreedomAccount.Factory | ||
alias FreedomAccount.MoneyUtils | ||
alias FreedomAccountWeb.FundTransaction | ||
|
||
setup [:create_account, :create_fund] | ||
|
||
describe "Index" do | ||
test "shows message when fund has no transactions", %{conn: conn, fund: fund} do | ||
conn | ||
|> visit(~p"/funds/#{fund}") | ||
|> assert_has("#no-transactions") | ||
end | ||
|
||
test "displays transactions", %{conn: conn, account: account, fund: fund} do | ||
deposit = Factory.deposit(fund) | ||
[deposit_line_item] = deposit.line_items | ||
withdrawal = Factory.withdrawal(account, fund) | ||
[withdrawal_line_item] = withdrawal.line_items | ||
|
||
conn | ||
|> visit(~p"/funds/#{fund}") | ||
|> assert_has(table_cell(), text: "#{deposit.date}") | ||
|> assert_has(table_cell(), text: deposit.memo) | ||
|> assert_has(role("deposit"), text: "#{deposit_line_item.amount}") | ||
|> assert_has(table_cell(), text: "#{withdrawal.date}") | ||
|> assert_has(table_cell(), text: withdrawal.memo) | ||
|> assert_has(role("withdrawal"), text: "#{MoneyUtils.negate(withdrawal_line_item.amount)}") | ||
end | ||
|
||
test "paginates transactions", %{conn: conn, fund: fund} do | ||
page_size = FundTransaction.Index.page_size() | ||
count = round(page_size * 2.5) | ||
|
||
transactions = | ||
for i <- 1..count do | ||
Factory.deposit(fund, date: :local |> Timex.today() |> Timex.shift(days: i * -1)) | ||
end | ||
|
||
[page1, page2, page3] = Enum.chunk_every(transactions, page_size) | ||
|
||
conn | ||
|> visit(~p"/funds/#{fund}") | ||
|> assert_has_all_transactions(page1) | ||
|> assert_has(disabled("button"), text: "Previous Page") | ||
|> assert_has(enabled("button"), text: "Next Page") | ||
|> click_button("Next Page") | ||
|> assert_has_all_transactions(page2) | ||
|> assert_has(enabled("button"), text: "Previous Page") | ||
|> assert_has(enabled("button"), text: "Next Page") | ||
|> click_button("Next Page") | ||
|> assert_has_all_transactions(page3) | ||
|> assert_has(enabled("button"), text: "Previous Page") | ||
|> assert_has(disabled("button"), text: "Next Page") | ||
|> click_button("Previous Page") | ||
|> click_button("Previous Page") | ||
|> assert_has_all_transactions(page1) | ||
|> assert_has(disabled("button"), text: "Previous Page") | ||
|> assert_has(enabled("button"), text: "Next Page") | ||
end | ||
|
||
defp assert_has_all_transactions(session, transactions) do | ||
Enum.reduce(transactions, session, fn txn, session -> | ||
assert_has(session, table_cell(), text: "#{txn.date}") | ||
end) | ||
end | ||
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
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