1 import { ComputedLine, Line } from './Line';
2 import TaxReturn from './TaxReturn';
3 import Form, { isFormT } from './Form';
4 import { InconsistencyError, NotFoundError } from './Errors';
6 class TestTaxReturn extends TaxReturn {
7 get year() { return 2019; }
8 get includeJointPersonForms() { return true; }
11 test('add and get line', () => {
12 const l = new ComputedLine<number>(() => 42);
14 class TestForm extends Form<TestForm['_lines']> {
15 readonly name = 'Test Form';
17 protected readonly _lines = { '1': l };
20 const f = new TestForm();
21 expect(f.getLine('1')).toBe(l);
24 test('get non-existent line', () => {
25 class TestForm extends Form<TestForm['_lines']> {
26 readonly name = 'Test';
27 protected readonly _lines = {};
30 const f = new TestForm();
31 const fAsAny: Form<any> = f;
32 expect(() => fAsAny.getLine('line')).toThrow(NotFoundError);
35 //expect(() => f.getLine('line')).toThrow(NotFoundError);
43 class TestForm extends Form<any, TestInput> {
44 readonly name = '1040';
46 protected readonly _lines = null;
49 const f = new TestForm({ filingStatus: 'S', money: 100.0 });
50 expect(f.getInput('filingStatus')).toBe('S');
53 test('get value', () => {
54 class TestForm extends Form<TestForm['_lines']> {
55 readonly name = 'Form';
57 protected readonly _lines = {
58 line: new ComputedLine<number>(() => 42),
62 const f = new TestForm();
63 const tr = new TestTaxReturn();
64 expect(f.getValue(tr, 'line')).toBe(42);
67 //let s: string = f.getValue(tr, 'line');
69 const fAsAny: Form<any> = f;
70 expect(() => fAsAny.getValue(tr, 'other')).toThrow(NotFoundError);
72 //expect(() => f.getValue(tr, 'other')).toThrow(NotFoundError);
75 test('form types', () => {
76 class FormA extends Form<any> {
78 protected readonly _lines = {};
80 class FormB extends Form<any> {
82 protected readonly _lines = {};
85 expect(isFormT(new FormA(), FormA)).toBe(true);
86 expect(isFormT(new FormB(), FormA)).toBe(false);
87 expect(isFormT(new FormA(), FormB)).toBe(false);
88 expect(isFormT(new FormB(), FormB)).toBe(true);