Add Form.getValue()
authorRobert Sesek <rsesek@bluestatic.org>
Thu, 20 Feb 2020 04:53:02 +0000 (23:53 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Thu, 20 Feb 2020 05:09:19 +0000 (00:09 -0500)
src/Form.test.ts
src/Form.ts

index b7c3d0eb6703844ed74b162839f00b5a508ef80e..55078a7659cbade5ab7a13d7ea73cbbd5026bfcd 100644 (file)
@@ -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<number>('line', () => 42) ];
+    }
+  };
+
+  const f = new TestForm();
+  const tr = new TaxReturn(2019);
+  expect(f.getValue(tr, 'line')).toBe(42);
+});
index 07e9ccc6c7d0fe8ebcf408116f6c0e6d956dd85a..e3d6c4e7de613ad8bb18eb2d3b7d9d8014284f1a 100644 (file)
@@ -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<I = unknown> {
     return lines[0];
   }
 
+  getValue<T>(tr: TaxReturn, id: string): T {
+    const line: Line<T> = this.getLine(id);
+    return line.value(tr);
+  }
+
   getInput<K extends keyof I>(name: K): I[K] {
     if (!(name in this._input)) {
       throw new NotFoundError(`No input with key ${name} on form ${this.name}`);