merchant-backoffice

ZZZ: Inactive/Deprecated
Log | Files | Refs | Submodules | README

commit 5b7326e69b1e2a5655e7dc4e8209e69bfb8fd997
parent 4d9b35bb4c153b9bf98cd3d8eeccda828d3aea29
Author: ms <ms@taler.net>
Date:   Tue, 11 Jan 2022 09:49:35 +0100

fix hook usage after Sebastian suggestion

Diffstat:
Mpackages/bank/package.json | 1+
Mpackages/bank/src/pages/home/index.tsx | 19+++++++++----------
Mpackages/bank/tests/__tests__/homepage.js | 32+-------------------------------
3 files changed, 11 insertions(+), 41 deletions(-)

diff --git a/packages/bank/package.json b/packages/bank/package.json @@ -66,6 +66,7 @@ "jest-fetch-mock": "^3.0.3", "jest-preset-preact": "^4.0.5", "jest-watch-typeahead": "^1.0.0", + "jest-environment-jsdom": "^27.4.6", "jssha": "^3.2.0", "po2json": "^0.4.5", "preact-cli": "3.0.5", diff --git a/packages/bank/src/pages/home/index.tsx b/packages/bank/src/pages/home/index.tsx @@ -526,6 +526,15 @@ function Account(Props: any): VNode { withdrawalOutcome, talerWithdrawUri, accountLabel } = Props; + /** + * This part shows a list of transactions: with 5 elements by + * default and offers a "load more" button. + */ + var [txPageNumber, setTxPageNumber] = useTransactionPageNumber() // Buggy. + var txsPages = [] + for (let i = 0; i <= txPageNumber; i++) { + txsPages.push(<Transactions accountLabel={Props.accountLabel} pageNumber={txPageNumber} />) + } const i18n = useTranslator(); /** * Getting the bank account balance. @@ -579,16 +588,6 @@ function Account(Props: any): VNode { </Fragment>); } - /** - * This part shows a list of transactions: with 5 elements by - * default and offers a "load more" button. - */ - var [txPageNumber, setTxPageNumber] = useTransactionPageNumber() // Buggy. - var txsPages = [] - for (let i = 0; i <= txPageNumber; i++) { - txsPages.push(<Transactions accountLabel={Props.accountLabel} pageNumber={txPageNumber} />) - } - return (<Fragment> <p>Your balance is {data.balance.amount}.</p> <div> diff --git a/packages/bank/tests/__tests__/homepage.js b/packages/bank/tests/__tests__/homepage.js @@ -16,34 +16,6 @@ jest.mock("../../src/i18n") const i18n = require("../../src/i18n") i18n.useTranslator.mockImplementation(() => function(arg) {return arg}) -/** - * Mocking local storage, see: - * https://stackoverflow.com/questions/32911630/how-do-i-deal-with-localstorage-in-jest-tests - */ -class LocalStorageMock { - constructor() { - this.store = {}; - } - - clear() { - this.store = {}; - } - - getItem(key) { - return this.store[key] || null; - } - - setItem(key, value) { - this.store[key] = String(value); - } - - removeItem(key) { - delete this.store[key]; - } -} - -global.localStotage = new LocalStorageMock(); - beforeAll(() => { Object.defineProperty(window, 'location', { value: { @@ -51,9 +23,7 @@ beforeAll(() => { pathname: "/demobanks/default" } }) -}) -afterAll(() => { - global.localStorage.clear() + global.Storage.prototype.setItem = jest.fn((key, value) => {}) }) /**