Test: Component: Transaction History (Table View) Export Flow - #530
Open
Deb-Auth wants to merge 1 commit into
Open
Test: Component: Transaction History (Table View) Export Flow#530Deb-Auth wants to merge 1 commit into
Deb-Auth wants to merge 1 commit into
Conversation
|
@Deb-Auth Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #507
Summary
Adds automated tests verifying that the Transaction History table's "Export to CSV" button downloads the current table data, together with the table view and export pipeline those tests exercise.
There was no transaction history table in the repository at the time of writing —
components/settings/ExportData.tsxcovers a different flow (a GDPR account export as JSON) — so there was no export button to test. This PR adds the table and its CSV export following the project's Component -> Hook -> Service layering, and tests each layer.What was added
lib/csvExport.ts— CSV serialisation and download primitives.escapeCsvValueimplements RFC 4180 escaping: values containing a comma, a quote or a newline are quoted, embedded quotes are doubled, and nullish values become empty cells.toCsvalways writes the header row, so even an empty export is a well-formed file.downloadCsvcreates atext/csvblob, clicks a hidden anchor and revokes the object URL in afinally, so a blocked or throwing click cannot leak a blob or leave an orphan anchor in the document. The payload is prefixed with a UTF-8 BOM so spreadsheet applications do not mangle non-ASCII characters.services/transactionHistoryService.ts— reads the authenticated user's transaction history, with aTransactionRecordshape reusing the existingTransactionStatusfromtypes/transaction.ts. Transport failures are converted into an unsuccessful response rather than thrown, matching the convention inexportDataService.hooks/useTransactionExport.ts— turns the rows the table currently holds into a download.isExporting/error/didExport, and clears a previous error on the next attempt.swiftchain-transactions-YYYY-MM-DD.csv).components/transactions/TransactionHistoryTable.tsx— the table with the export button, a row count, a success confirmation, a dismissible export error, and loading, error and empty states. The export button is disabled when there is nothing to export.Test coverage
components/transactions/__tests__/TransactionHistoryTable.test.tsx(16 tests)hooks/__tests__/useTransactionExport.test.ts(14 tests)Filename stamping, column layout, serialised content including the header and one line per transaction, empty cells for absent optional fields, escaping of a counterparty containing a comma, success flagging, refusal to export an empty table, downloader failure and non-
Errorfailure handling, error clearing on retry and on demand, and the guarantee that only the supplied rows are exported.__tests__/lib/csvExport.test.ts(14 tests)Escaping of plain, nullish, comma-bearing, quote-bearing and newline-bearing values; header-only output for an empty dataset; header escaping; blob type, anchor click, filename, href and URL revocation; the UTF-8 BOM; content round-tripping; and cleanup when the click throws.
services/__tests__/transactionHistoryService.test.ts(4 tests)Endpoint, success payload passthrough, and both transport-failure paths.
Mocking of external dependencies
@/lib/api(the shared axios instance) is mocked in the service tests.downloadCsvis mocked in the hook and component tests so the assertions can inspect the exact CSV payload and filename without depending on jsdom's download behaviour, while__tests__/lib/csvExport.test.tstests the real implementation directly against a stubbedURL.createObjectURLand an anchor-click spy.jest.useFakeTimers().setSystemTime(...)pins the date so filename assertions cannot drift. No real HTTP, wallet or WebSocket call is made anywhere in the suite.Verification
npx jest __tests__/lib/csvExport.test.ts hooks/__tests__/useTransactionExport.test.ts components/transactions/__tests__/TransactionHistoryTable.test.tsx services/__tests__/transactionHistoryService.test.ts— 48 tests pass.pnpm test— the full suite goes from 921 to 969 tests with no change to the set of pre-existing failures.npx eslinton every changed file — no errors.pnpm run type-check— no new errors.Note for the maintainer
CI on
mainis currently red before any of this, and these changes do not fix or worsen it:components/mobile/MobileFooter.tsxhas lost every quote character in the file (line 1 reads`use clientand line 3import React from react). This is a hard parse error that failspnpm run lint,pnpm run type-checkandpnpm run buildonmaintoday.main, largely around the wallet/Freighter mocks (useWallet,useTheme,WalletConnect,MultiSigApprovalsand related).Both look like they need a maintainer decision rather than a drive-by fix from a test PR, so I have deliberately left them untouched to keep this diff scoped to the issue.