1 import TaxReturn from './TaxReturn';
2 import Person from './Person';
3 import Form from './Form';
4 import { NotFoundError, InconsistencyError } from './Errors';
6 class TestTaxReturn extends TaxReturn {
7 get year() { return 2019; }
9 includeJointPersonForms = false;
12 test('does not support Dependents', () => {
13 const tr = new TestTaxReturn();
14 const p = Person.dependent('Baby');
15 expect(() => tr.addPerson(p)).toThrow('Dependents are not supported');
18 test('add more than one Self', () => {
19 const tr = new TestTaxReturn();
20 const p1 = Person.self('A');
22 const p2 = Person.self('B');
23 expect(() => tr.addPerson(p2)).toThrow('Cannot have more than one Self or Spouse');
26 test('add more than one Spouse', () => {
27 const tr = new TestTaxReturn();
28 const p1 = Person.spouse('A');
30 const p2 = Person.spouse('B');
31 expect(() => tr.addPerson(p2)).toThrow('Cannot have more than one Self or Spouse');
34 test('add Self and Spouse', () => {
35 const tr = new TestTaxReturn();
36 const self = Person.self('Billy Bob');
37 const spouse = Person.spouse('Jilly Bob');
41 expect(tr.getPerson('Billy')).toBe(self);
42 expect(tr.getPerson('Jilly')).toBe(spouse);
44 expect(() => tr.getPerson('Bob')).toThrow('too imprecise');
47 test('get non-existent person', () => {
48 const tr = new TestTaxReturn();
49 const self = Person.self('Billy Bob');
52 expect(tr.getPerson('Billy Bob')).toBe(self);
53 expect(() => tr.getPerson('Jilly')).toThrow('not found');
56 test('single-copy forms', () => {
57 class TestForm extends Form<null> {
58 readonly name = 'Test Form';
59 protected readonly _lines = null;
62 const tr = new TestTaxReturn();
63 const f = new TestForm();
65 expect(() => tr.addForm(new TestForm)).toThrow(InconsistencyError);
66 expect(tr.getForm(TestForm)).toBe(f);
67 expect(tr.findForm(TestForm)).toBe(f);
70 test('multiple-copy forms', () => {
71 class TestForm extends Form<null> {
72 readonly name = 'Test Form';
73 readonly supportsMultipleCopies = true;
74 protected readonly _lines = null;
77 const tr = new TestTaxReturn();
78 const f1 = new TestForm();
79 const f2 = new TestForm();
80 const f3 = new TestForm();
84 expect(() => tr.getForm(TestForm)).toThrow(InconsistencyError);
85 expect(() => tr.findForm(TestForm)).toThrow(InconsistencyError);
87 const forms = tr.findForms(TestForm);
88 expect(forms.length).toBe(2);
89 expect(forms).toContain(f1);
90 expect(forms).toContain(f2);
91 expect(forms).not.toContain(f3);
94 test('get non-existent form', () => {
95 class TestForm extends Form<null> {
96 readonly name = 'Test Form';
97 protected readonly _lines = null;
99 const tr = new TestTaxReturn();
100 expect(() => tr.getForm(TestForm)).toThrow(NotFoundError);
101 expect(tr.findForm(TestForm)).toBeNull();
102 expect(tr.findForms(TestForm)).toEqual([]);
105 class PerPersonForm extends Form<PerPersonForm['_lines']> {
106 private _person?: Person;
108 readonly name = 'Per Person';
110 readonly supportsMultipleCopies = true;
112 protected readonly _lines = {};
114 constructor(person?: Person) {
116 this._person = person;
119 person() { return this._person; }
122 test('find forms for person', () => {
123 const p1 = Person.self('1');
124 const p2 = Person.spouse('2');
126 const addFormsToTaxReturn = (tr) => {
127 tr.addForm(new PerPersonForm(undefined));
128 tr.addForm(new PerPersonForm(undefined));
129 tr.addForm(new PerPersonForm(p1));
130 tr.addForm(new PerPersonForm(p2));
131 tr.addForm(new PerPersonForm(p2));
132 tr.addForm(new PerPersonForm(Person.joint));
135 const mfsp1 = new TestTaxReturn();
136 mfsp1.includeJointPersonForms = false;
138 addFormsToTaxReturn(mfsp1);
139 expect(mfsp1.findForms(PerPersonForm).length).toBe(3);
141 const mfsp2 = new TestTaxReturn();
142 mfsp2.includeJointPersonForms = false;
144 addFormsToTaxReturn(mfsp2);
145 expect(mfsp2.findForms(PerPersonForm).length).toBe(4);
147 const mfj = new TestTaxReturn();
148 mfj.includeJointPersonForms = true;
151 addFormsToTaxReturn(mfj);
152 expect(mfj.findForms(PerPersonForm).length).toBe(6);