Browse Source

Merge branch 'raw-instead-of-label' into 'master'

Get RAW if LABEL is not present

See merge request nico/elbank!11
custom-labels
Nicolas Petton 3 years ago
parent
commit
89dc59207c
4 changed files with 30 additions and 2 deletions
  1. +8
    -0
      elbank-common.el
  2. +1
    -1
      elbank-report.el
  3. +18
    -1
      test/elbank-common-test.el
  4. +3
    -0
      test/elbank-report-test.el

+ 8
- 0
elbank-common.el View File

@ -126,6 +126,14 @@ Data is cached to `elbank-data'."
If the result is nil, return DEFAULT."
(map-elt transaction key default))
(cl-defmethod elbank-transaction-elt (transaction (_key (eql label)) &optional default)
"Return the label of TRANSACTION.
The label is defined as the value at symbol `label' if present,
the value at symbol `raw' if not. If both are nil, return DEFAULT."
(or (map-elt transaction 'label nil)
(map-elt transaction 'raw default)))
(cl-defmethod elbank-transaction-elt (transaction (_key (eql category)) &optional default)
"Return the category of TRANSACTION.


+ 1
- 1
elbank-report.el View File

@ -459,7 +459,7 @@ Signal an error if there is no transaction at point."
"Return a button text with the label of TRANSACTION.
When clicking the button, jump to the transaction."
(with-temp-buffer
(insert (elbank-transaction-elt transaction 'label))
(insert (elbank-transaction-elt transaction 'label ""))
(make-text-button (point-at-bol) (point)
'follow-link t
'action


+ 18
- 1
test/elbank-common-test.el View File

@ -60,7 +60,24 @@
(let ((tr1 '((category . (("foo" . 20) ("bar" . 10)))))
(tr2 '((category . "foo"))))
(expect (elbank-transaction-split-p tr1) :to-be-truthy)
(expect (elbank-transaction-split-p tr2) :to-be nil))))
(expect (elbank-transaction-split-p tr2) :to-be nil)))
(describe "when asked for label"
(it "returns label if present"
(let ((tr '((label . "foo"))))
(expect (elbank-transaction-elt tr 'label) :to-equal "foo")))
(it "prefers label over raw"
(let ((tr '((label . "foo") (raw . "bar"))))
(expect (elbank-transaction-elt tr 'label) :to-equal "foo")))
(it "returns raw if present and label is not"
(let ((tr '((raw . "foo"))))
(expect (elbank-transaction-elt tr 'label) :to-equal "foo")))
(it "returns default if neither label nor raw are present"
(let ((tr '((something-else . "bar"))))
(expect (elbank-transaction-elt tr 'label "foo") :to-equal "foo")))))
(provide 'elbank-common-test)
;;; elbank-common-test.el ends here

+ 3
- 0
test/elbank-report-test.el View File

@ -68,6 +68,9 @@
:to-have-been-called-with '(("cat1" . "2000")
("foo" . "1500")
("bar" . "500")) main-transaction))))
(describe "Representing transaction"
(it "with a nil label"
(expect (elbank-report--cell '((label)) 'label) :to-equal "")))
(provide 'elbank-report-test)
;;; elbank-report-test.el ends here

Loading…
Cancel
Save