1 import { ComputedLine, Line } from './Line';
2 import TaxReturn from './TaxReturn';
3 import Form from './Form';
4 import { InconsistencyError, NotFoundError } from './Errors';
6 test('add and get line', () => {
7 const l = new ComputedLine<number>('1', () => 42);
9 class TestForm extends Form {
14 protected getLines() {
19 const f = new TestForm();
20 expect(f.getLine('1')).toBe(l);
23 test('get non-existent line', () => {
24 class TestForm extends Form {
29 protected getLines() {
34 const f = new TestForm();
35 expect(() => f.getLine('1')).toThrow(NotFoundError);
38 test('add duplicate line', () => {
39 const l1 = new ComputedLine<number>('1', () => 42);
40 const l2 = new ComputedLine<number>('1', () => 36);
42 class TestForm extends Form {
47 protected getLines() {
52 expect(() => new TestForm()).toThrow(InconsistencyError);
55 test('add line to two forms', () => {
56 const l = new ComputedLine<string>('bad', () => 'bad');
58 class TestForm1 extends Form {
59 get name(): string { return '1'; }
61 protected getLines() { return [ l ]; }
63 class TestForm2 extends Form {
64 get name(): string { return '2'; }
66 protected getLines() { return [ l ]; }
69 const f1 = new TestForm1();
70 expect(() => new TestForm2()).toThrow(InconsistencyError);
78 class TestForm extends Form<TestInput> {
79 get name() { return '1040'; }
81 protected getLines() { return []; }
84 const f = new TestForm({ filingStatus: 'S', money: 100.0 });
85 expect(f.getInput('filingStatus')).toBe('S');
88 test('get value', () => {
89 class TestForm extends Form {
90 get name() { return 'Form'; }
92 protected getLines() {
93 return [ new ComputedLine<number>('line', () => 42) ];
97 const f = new TestForm();
98 const tr = new TaxReturn(2019);
99 expect(f.getValue(tr, 'line')).toBe(42);