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 get year() { return 2019; }
13 get includeJointPersonForms() { return true; }
16 test('add and get line', () => {
17 const l = new ComputedLine<number>(() => 42);
19 class TestForm extends Form {
20 readonly name = 'Test Form';
22 readonly lines = { '1': l };
25 const f = new TestForm();
26 expect(f.getLine('1')).toBe(l);
29 test('get non-existent line', () => {
30 class TestForm extends Form {
31 readonly name = 'Test';
35 const f = new TestForm();
36 const fAsAny: Form = f;
37 expect(() => fAsAny.getLine('line')).toThrow(NotFoundError);
40 //expect(() => f.getLine('line')).toThrow(NotFoundError);
48 class TestForm extends Form<TestInput> {
49 readonly name = '1040';
51 readonly lines = null;
54 const f = new TestForm({ filingStatus: 'S', money: 100.0 });
55 expect(f.getInput('filingStatus')).toBe('S');
58 test('get value', () => {
59 class TestForm extends Form {
60 readonly name = 'Form';
63 line: new ComputedLine<number>(() => 42),
67 const f = new TestForm();
68 const tr = new TestTaxReturn();
69 expect(f.getValue(tr, 'line')).toBe(42);
72 //let s: string = f.getValue(tr, 'line');
74 const fAsAny: Form = f;
75 expect(() => fAsAny.getValue(tr, 'other')).toThrow(NotFoundError);
77 //expect(() => f.getValue(tr, 'other')).toThrow(NotFoundError);
80 test('form types', () => {
81 class FormA extends Form {
85 class FormB extends Form {
90 expect(isFormT(new FormA(), FormA)).toBe(true);
91 expect(isFormT(new FormB(), FormA)).toBe(false);
92 expect(isFormT(new FormA(), FormB)).toBe(false);
93 expect(isFormT(new FormB(), FormB)).toBe(true);
96 test('derived form types', () => {
97 class Base extends Form<any> {
98 readonly name = 'Base';
101 class Derived extends Base {};
102 class SecondDerived extends Derived {};
104 expect(isFormT(new Base(), Base)).toBe(true);
105 expect(isFormT(new Derived(), Derived)).toBe(true);
107 expect(isFormT(new Derived(), Base)).toBe(true);
108 expect(isFormT(new Base(), Derived)).toBe(false);
110 expect(isFormT(new SecondDerived(), SecondDerived)).toBe(true);
111 expect(isFormT(new SecondDerived(), Derived)).toBe(true);
112 expect(isFormT(new SecondDerived(), Base)).toBe(true);