mirror of
https://github.com/joinmarket-webui/jam.git
synced 2026-08-16 13:01:05 +02:00
fix: export all earn report rows
This commit is contained in:
parent
c832b80a2f
commit
fdf6e36cd8
2 changed files with 32 additions and 3 deletions
|
|
@ -209,6 +209,35 @@ describe('EarnReportContent', () => {
|
|||
createElement.mockRestore()
|
||||
})
|
||||
|
||||
it('exports all filtered rows regardless of pagination', async () => {
|
||||
mocks.entries = Array.from({ length: 30 }, (_, index) =>
|
||||
entry({
|
||||
notes: `maker note ${index + 1}`,
|
||||
timestamp: new Date(Date.UTC(2026, 0, index + 1, 12)),
|
||||
}),
|
||||
)
|
||||
|
||||
render(<EarnReportContent enabled />)
|
||||
|
||||
expect(screen.getByText('pagination:30')).toBeInTheDocument()
|
||||
expect(screen.getAllByText(/maker note/u)).toHaveLength(25)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'global.download' }))
|
||||
|
||||
const blob = mocks.createObjectURL.mock.calls[0]?.[0]
|
||||
expect(blob).toBeInstanceOf(Blob)
|
||||
if (!blob) {
|
||||
throw new Error('CSV blob was not created')
|
||||
}
|
||||
|
||||
const csv = await blob.text()
|
||||
const lines = csv.trim().split('\n')
|
||||
|
||||
expect(lines).toHaveLength(31)
|
||||
expect(lines[1]).toContain('2026-01-30T12:00:00.000Z')
|
||||
expect(lines.at(-1)).toContain('2026-01-01T12:00:00.000Z')
|
||||
})
|
||||
|
||||
it('adds demo rows in developer mode', () => {
|
||||
mocks.developerMode = true
|
||||
|
||||
|
|
|
|||
|
|
@ -144,11 +144,11 @@ export const EarnReportContent = ({ className, enabled }: EarnReportContentProps
|
|||
}, [isShowAll, allEntries.length, table])
|
||||
|
||||
const visibleRows = table.getRowModel().rows
|
||||
const exportRows = table.getSortedRowModel().rows
|
||||
|
||||
// Export visible entries as CSV
|
||||
const downloadCsv = useCallback(() => {
|
||||
const header = 'timestamp,cj_amount,input_count,input_amount,fee,earned,confirm_minutes,notes'
|
||||
const rows = visibleRows.map((row) =>
|
||||
const rows = exportRows.map((row) =>
|
||||
[
|
||||
row.original.timestamp.toISOString(),
|
||||
row.original.cjTotalAmount ?? '',
|
||||
|
|
@ -170,7 +170,7 @@ export const EarnReportContent = ({ className, enabled }: EarnReportContentProps
|
|||
setTimeout(() => {
|
||||
URL.revokeObjectURL(url)
|
||||
}, 0)
|
||||
}, [visibleRows])
|
||||
}, [exportRows])
|
||||
|
||||
const earnedTotal = useMemo(() => sumEarned(allEntries, BITCOIN_GENESIS_DATE), [allEntries])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue