[test-charts] add daily txns and test range

This test (for net-worth-barchart only) adds daily transactions from
1/1/70 for 100 days, and aims to test the date ranges for net-charts
is accurate.
This commit is contained in:
Christopher Lam 2018-09-12 18:19:43 +08:00
parent 3e9cd1fc11
commit 9bba9474cb

View File

@ -116,7 +116,33 @@
(let* ((options (default-testing-options)))
(test-assert (format #f "basic report exists: ~a" variant)
(options->render uuid options (format #f "net-charts-test ~a default options" variant))))
(options->render uuid options (format #f "test-null ~a default options" variant))))
;; test net worth barchart amounts
(when (eq? variant 'net-worth-barchart)
;; create 100 daily transactions from 1/1/70. this is meant to
;; test chart date ranges. day 0 = $0, day 1 = $1, etc
(let loop ((date (gnc-dmy2time64 1 1 1970)) (idx 0))
(when (<= idx 100)
(env-create-transaction env date bank income idx)
(loop (incdate date DayDelta) (1+ idx))))
(let* ((options (default-testing-options)))
(set-option! options "General" "Start Date" (cons 'absolute (gnc-dmy2time64 15 1 1970)))
(set-option! options "General" "End Date" (cons 'absolute (gnc-dmy2time64 15 3 1970)))
(set-option! options "General" "Step Size" 'DayDelta)
(set-option! options "Display" "Show table" #t)
(let ((sxml (gnc:options->sxml uuid options (format #f "test-net-charts ~a 2 months" variant)
"test-table" #:strip-tag "script")))
(test-equal "net-worth-barchart: first row"
'("Date" "Assets" "Liabilities" "Net Worth")
(sxml->table-row-col sxml 1 0 #f))
(test-equal "net-worth-barchart: first data row"
'("01/15/70" "$105.00" "$0.00" "$105.00")
(sxml->table-row-col sxml 1 1 #f))
(test-equal "net-worth-barchart: last data row"
'("03/15/70" "$2,701.00" "$0.00" "$2,701.00")
(sxml->table-row-col sxml 1 -1 #f))
)))
(case variant
((liability-piechart stock-piechart asset-piechart expense-piechart income-piechart)