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 TaxReturn from './TaxReturn';
7 import Person from './Person';
8 import Form from './Form';
9 import { NotFoundError, InconsistencyError } from './Errors';
11 class TestTaxReturn extends TaxReturn {
12 get year() { return 2019; }
14 readonly constants = {};
16 includeJointPersonForms = false;
19 test('does not support Dependents', () => {
20 const tr = new TestTaxReturn();
21 const p = Person.dependent('Baby');
22 expect(() => tr.addPerson(p)).toThrow('Dependents are not supported');
25 test('add more than one Self', () => {
26 const tr = new TestTaxReturn();
27 const p1 = Person.self('A');
29 const p2 = Person.self('B');
30 expect(() => tr.addPerson(p2)).toThrow('Cannot have more than one Self or Spouse');
33 test('add more than one Spouse', () => {
34 const tr = new TestTaxReturn();
35 const p1 = Person.spouse('A');
37 const p2 = Person.spouse('B');
38 expect(() => tr.addPerson(p2)).toThrow('Cannot have more than one Self or Spouse');
41 test('add Self and Spouse', () => {
42 const tr = new TestTaxReturn();
43 const self = Person.self('Billy Bob');
44 const spouse = Person.spouse('Jilly Bob');
48 expect(tr.getPerson('Billy')).toBe(self);
49 expect(tr.getPerson('Jilly')).toBe(spouse);
51 expect(() => tr.getPerson('Bob')).toThrow('too imprecise');
54 test('get non-existent person', () => {
55 const tr = new TestTaxReturn();
56 const self = Person.self('Billy Bob');
59 expect(tr.getPerson('Billy Bob')).toBe(self);
60 expect(() => tr.getPerson('Jilly')).toThrow('not found');
63 test('single-copy forms', () => {
64 class TestForm extends Form {
65 readonly name = 'Test Form';
66 readonly lines = null;
69 const tr = new TestTaxReturn();
70 const f = new TestForm();
72 expect(() => tr.addForm(new TestForm)).toThrow(InconsistencyError);
73 expect(tr.getForm(TestForm)).toBe(f);
74 expect(tr.findForm(TestForm)).toBe(f);
77 test('multiple-copy forms', () => {
78 class TestForm extends Form {
79 readonly name = 'Test Form';
80 readonly supportsMultipleCopies = true;
81 readonly lines = null;
84 const tr = new TestTaxReturn();
85 const f1 = new TestForm();
86 const f2 = new TestForm();
87 const f3 = new TestForm();
91 expect(() => tr.getForm(TestForm)).toThrow(InconsistencyError);
92 expect(() => tr.findForm(TestForm)).toThrow(InconsistencyError);
94 const forms = tr.findForms(TestForm);
95 expect(forms.length).toBe(2);
96 expect(forms).toContain(f1);
97 expect(forms).toContain(f2);
98 expect(forms).not.toContain(f3);
101 test('get non-existent form', () => {
102 class TestForm extends Form {
103 readonly name = 'Test Form';
104 readonly lines = null;
106 const tr = new TestTaxReturn();
107 expect(() => tr.getForm(TestForm)).toThrow(NotFoundError);
108 expect(tr.findForm(TestForm)).toBeNull();
109 expect(tr.findForms(TestForm)).toEqual([]);
112 class PerPersonForm extends Form {
113 private _person?: Person;
115 readonly name = 'Per Person';
117 readonly supportsMultipleCopies = true;
121 constructor(person?: Person) {
123 this._person = person;
126 person() { return this._person; }
129 test('find forms for person', () => {
130 const p1 = Person.self('1');
131 const p2 = Person.spouse('2');
133 const addFormsToTaxReturn = (tr) => {
134 tr.addForm(new PerPersonForm(undefined));
135 tr.addForm(new PerPersonForm(undefined));
136 tr.addForm(new PerPersonForm(p1));
137 tr.addForm(new PerPersonForm(p2));
138 tr.addForm(new PerPersonForm(p2));
139 tr.addForm(new PerPersonForm(Person.joint));
142 const mfsp1 = new TestTaxReturn();
143 mfsp1.includeJointPersonForms = false;
145 addFormsToTaxReturn(mfsp1);
146 expect(mfsp1.findForms(PerPersonForm).length).toBe(3);
148 const mfsp2 = new TestTaxReturn();
149 mfsp2.includeJointPersonForms = false;
151 addFormsToTaxReturn(mfsp2);
152 expect(mfsp2.findForms(PerPersonForm).length).toBe(4);
154 const mfj = new TestTaxReturn();
155 mfj.includeJointPersonForms = true;
158 addFormsToTaxReturn(mfj);
159 expect(mfj.findForms(PerPersonForm).length).toBe(6);