1 // Copyright 2020 Blue Static <https://www.bluestatic.org>
2 // This program is free software licensed under the GNU General Public License,
3 // version 3.0. The full text of the license can be found in LICENSE.txt.
4 // SPDX-License-Identifier: GPL-3.0-only
6 import { ComputedLine, Line } from './Line';
7 import TaxReturn from './TaxReturn';
8 import Form, { isFormT } from './Form';
9 import { InconsistencyError, NotFoundError } from './Errors';
11 class TestTaxReturn extends TaxReturn {
12 readonly constants = undefined;
13 get year() { return 2019; }
14 get includeJointPersonForms() { return true; }
17 test('add and get line', () => {
18 const l = new ComputedLine<number>(() => 42);
20 class TestForm extends Form {
21 readonly name = 'Test Form';
23 readonly lines = { '1': l };
26 const f = new TestForm();
27 expect(f.getLine('1')).toBe(l);
30 test('get non-existent line', () => {
31 class TestForm extends Form {
32 readonly name = 'Test';
36 const f = new TestForm();
37 const fAsAny: Form = f;
38 expect(() => fAsAny.getLine('line')).toThrow(NotFoundError);
41 //expect(() => f.getLine('line')).toThrow(NotFoundError);
49 class TestForm extends Form<TestInput> {
50 readonly name = '1040';
52 readonly lines = null;
55 const f = new TestForm({ filingStatus: 'S', money: 100.0 });
56 expect(f.getInput('filingStatus')).toBe('S');
59 test('get value', () => {
60 class TestForm extends Form {
61 readonly name = 'Form';
64 line: new ComputedLine<number>(() => 42),
68 const f = new TestForm();
69 const tr = new TestTaxReturn();
70 expect(f.getValue(tr, 'line')).toBe(42);
73 //let s: string = f.getValue(tr, 'line');
75 const fAsAny: Form = f;
76 expect(() => fAsAny.getValue(tr, 'other')).toThrow(NotFoundError);
78 //expect(() => f.getValue(tr, 'other')).toThrow(NotFoundError);
81 test('form types', () => {
82 class FormA extends Form {
86 class FormB extends Form {
91 expect(isFormT(new FormA(), FormA)).toBe(true);
92 expect(isFormT(new FormB(), FormA)).toBe(false);
93 expect(isFormT(new FormA(), FormB)).toBe(false);
94 expect(isFormT(new FormB(), FormB)).toBe(true);
97 test('derived form types', () => {
98 class Base extends Form<any> {
99 readonly name = 'Base';
102 class Derived extends Base {};
103 class SecondDerived extends Derived {};
105 expect(isFormT(new Base(), Base)).toBe(true);
106 expect(isFormT(new Derived(), Derived)).toBe(true);
108 expect(isFormT(new Derived(), Base)).toBe(true);
109 expect(isFormT(new Base(), Derived)).toBe(false);
111 expect(isFormT(new SecondDerived(), SecondDerived)).toBe(true);
112 expect(isFormT(new SecondDerived(), Derived)).toBe(true);
113 expect(isFormT(new SecondDerived(), Base)).toBe(true);