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 get year() { return 2019; }
14 get includeJointPersonForms() { return false; }
22 class TestForm extends Form<Input> {
26 'i1': new InputLine<Input>('name'),
27 'i2': new InputLine<Input>('value'),
28 'c1': new ComputedLine((tr): string => {
29 return `Hello ${this.getInput('name')}`;
31 'c2': new ComputedLine((tr): number => {
32 return this.getValue(tr, 'i2') * 0.20;
34 'r2': new ReferenceLine(TestForm as any, 'c2'),
38 describe('tracing', () => {
39 const tr = new TestTaxReturn();
40 const f = new TestForm({
46 test('input line', () => {
48 const trace = getLastTraceList();
49 expect(trace).toStrictEqual([ [ 'TF@i1 (Input from name)', 'TF input: name' ] ]);
52 test('computed line via input', () => {
54 const trace = getLastTraceList();
55 expect(trace).toStrictEqual([ [ 'TF@c1', 'TF input: name' ] ]);
58 test('computed line via input line', () => {
60 const trace = getLastTraceList();
61 expect(trace).toStrictEqual([
62 [ 'TF@c2', 'TF@i2 (Input from value)' ],
63 [ 'TF@i2 (Input from value)', 'TF input: value' ]
67 test('reference line', () => {
69 const trace = getLastTraceList();
70 expect(trace).toStrictEqual([
71 [ 'TF@r2 (Reference TestForm@c2)', 'TF@c2' ],
72 [ 'TF@c2', 'TF@i2 (Input from value)' ],
73 [ 'TF@i2 (Input from value)', 'TF input: value' ]