From 56d9915eaf4af3b2d0e9c4e929ea1d704a87e62f Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 19 Feb 2020 23:53:02 -0500 Subject: [PATCH] Add Form.getValue() --- src/Form.test.ts | 14 ++++++++++++++ src/Form.ts | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/src/Form.test.ts b/src/Form.test.ts index b7c3d0e..55078a7 100644 --- a/src/Form.test.ts +++ b/src/Form.test.ts @@ -84,3 +84,17 @@ test('input', () => { const f = new TestForm({ filingStatus: 'S', money: 100.0 }); expect(f.getInput('filingStatus')).toBe('S'); }); + +test('get value', () => { + class TestForm extends Form { + get name() { return 'Form'; } + + protected getLines() { + return [ new ComputedLine('line', () => 42) ]; + } + }; + + const f = new TestForm(); + const tr = new TaxReturn(2019); + expect(f.getValue(tr, 'line')).toBe(42); +}); diff --git a/src/Form.ts b/src/Form.ts index 07e9ccc..e3d6c4e 100644 --- a/src/Form.ts +++ b/src/Form.ts @@ -1,3 +1,4 @@ +import TaxReturn from './TaxReturn'; import { Line } from './Line'; import { InconsistencyError, NotFoundError } from './Errors'; @@ -36,6 +37,11 @@ export default abstract class Form { return lines[0]; } + getValue(tr: TaxReturn, id: string): T { + const line: Line = this.getLine(id); + return line.value(tr); + } + getInput(name: K): I[K] { if (!(name in this._input)) { throw new NotFoundError(`No input with key ${name} on form ${this.name}`); -- 2.43.5