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 Form from './Form';
7 import TaxReturn from './TaxReturn';
8 import { ComputedLine, InputLine, ReferenceLine } from './Line';
9 import { Edge, getLastTraceList } from './Trace';
11 class TestTaxReturn extends TaxReturn {
12 readonly constants = undefined;
14 get year() { return 2019; }
16 get includeJointPersonForms() { return false; }
24 class TestForm extends Form<Input> {
28 'i1': new InputLine<Input>('name'),
29 'i2': new InputLine<Input>('value'),
30 'c1': new ComputedLine((tr): string => {
31 return `Hello ${this.getInput('name')}`;
33 'c2': new ComputedLine((tr): number => {
34 return this.getValue(tr, 'i2') * 0.20;
36 'r2': new ReferenceLine(TestForm as any, 'c2'),
40 describe('tracing', () => {
41 const tr = new TestTaxReturn();
42 const f = new TestForm({
48 test('input line', () => {
50 const trace = getLastTraceList();
51 expect(trace).toStrictEqual([ [ 'TF@i1 (Input from name)', 'TF input: name' ] ]);
54 test('computed line via input', () => {
56 const trace = getLastTraceList();
57 expect(trace).toStrictEqual([ [ 'TF@c1', 'TF input: name' ] ]);
60 test('computed line via input line', () => {
62 const trace = getLastTraceList();
63 expect(trace).toStrictEqual([
64 [ 'TF@c2', 'TF@i2 (Input from value)' ],
65 [ 'TF@i2 (Input from value)', 'TF input: value' ]
69 test('reference line', () => {
71 const trace = getLastTraceList();
72 expect(trace).toStrictEqual([
73 [ 'TF@r2 (Reference TestForm@c2)', 'TF@c2' ],
74 [ 'TF@c2', 'TF@i2 (Input from value)' ],
75 [ 'TF@i2 (Input from value)', 'TF input: value' ]