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<TestForm['_lines']> {
20 readonly name = 'Test Form';
22 protected 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<TestForm['_lines']> {
31 readonly name = 'Test';
32 protected readonly _lines = {};
35 const f = new TestForm();
36 const fAsAny: Form<any> = f;
37 expect(() => fAsAny.getLine('line')).toThrow(NotFoundError);
40 //expect(() => f.getLine('line')).toThrow(NotFoundError);
48 class TestForm extends Form<any, TestInput> {
49 readonly name = '1040';
51 protected 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<TestForm['_lines']> {
60 readonly name = 'Form';
62 protected readonly _lines = {
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<any> = 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<any> {
83 protected readonly _lines = {};
85 class FormB extends Form<any> {
87 protected readonly _lines = {};
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);