commit 9e2b0a454e46e5acbf1fc5a92dafd8eaf287c517
parent 5b7326e69b1e2a5655e7dc4e8209e69bfb8fd997
Author: ms <ms@taler.net>
Date: Tue, 11 Jan 2022 18:26:43 +0100
test history pagination
Diffstat:
2 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/packages/bank/src/pages/home/index.tsx b/packages/bank/src/pages/home/index.tsx
@@ -488,7 +488,7 @@ async function registrationCall(
*************************/
/**
- * Show list of transactions.
+ * Show one page of transactions.
*/
function Transactions(Props: any): VNode {
@@ -513,7 +513,18 @@ function Transactions(Props: any): VNode {
var txsPages = <p>"loading..."</p>
if (data) {
- txsPages = data.map((item: any) => <div>Result</div>)
+ console.log("History data", data);
+ txsPages = <div>{
+ data.transactions.map(function(item: any) {
+ const sign = item.direction == "DBIT" ? "-" : "";
+ const counterpart = item.direction == "DBIT" ? item.creditorIban : item.debtorIban;
+ const amount = item.amount.split(":") // assume well-formed.
+ // Pattern:
+ //
+ // DD-MM-YYYY subject -5 EUR
+ // DD-MM-YYYY subject 5 EUR
+ return <span>{item.date} {item.subject} {sign}{amount[1]} {amount[0]}</span>
+ })}</div>
}
return txsPages;
}
@@ -530,7 +541,7 @@ function Account(Props: any): VNode {
* This part shows a list of transactions: with 5 elements by
* default and offers a "load more" button.
*/
- var [txPageNumber, setTxPageNumber] = useTransactionPageNumber() // Buggy.
+ var [txPageNumber, setTxPageNumber] = useTransactionPageNumber()
var txsPages = []
for (let i = 0; i <= txPageNumber; i++) {
txsPages.push(<Transactions accountLabel={Props.accountLabel} pageNumber={txPageNumber} />)
diff --git a/packages/bank/tests/__tests__/homepage.js b/packages/bank/tests/__tests__/homepage.js
@@ -237,15 +237,46 @@ describe("home page", () => {
fireEvent.click(signinButton);
await screen.findByText("wrong credentials given", {exact: false})
})
+
+ /**
+ * Test that balance and last transactions get shown
+ * after a successful login.
+ */
test("login success", async () => {
render(<BankHome />);
const { username, signinButton } = fillCredentialsForm();
+
+ // Response to balance request.
fetch.once(JSON.stringify({
balance: {
amount: "EUR:10",
credit_debit_indicator: "credit"
},
paytoUri: "payto://iban/123/ABC"
+ })).once(JSON.stringify({ // Response to history request.
+ transactions: [{
+ debtorIban: "XXX",
+ debtorBic: "YYY",
+ debtorName: "Foo",
+ creditorIban: "AAA",
+ creditorBic: "BBB",
+ creditorName: "Bar",
+ direction: "DBIT",
+ amount: "EUR:5",
+ subject: "Donation",
+ date: "01-01-1970"
+ }, {
+ debtorIban: "XXX",
+ debtorBic: "YYY",
+ debtorName: "Foo",
+ creditorIban: "AAA",
+ creditorBic: "BBB",
+ creditorName: "Bar",
+ direction: "CRDT",
+ amount: "EUR:5",
+ subject: "Refund",
+ date: "01-01-2000"
+ }]
}))
fireEvent.click(signinButton);
expect(fetch).toHaveBeenCalledWith(
@@ -253,6 +284,13 @@ describe("home page", () => {
expect.anything()
)
await screen.findByText("balance is EUR:10", {exact: false})
+ // The two transactions in the history mocked above.
+ await screen.findByText("refund", {exact: false})
+ await screen.findByText("donation", {exact: false})
+ expect(fetch).toHaveBeenCalledWith(
+ `http://localhost/demobanks/default/access-api/accounts/${username}/transactions?page=0`,
+ expect.anything()
+ )
})
test("registration success", async () => {