]> src.bluestatic.org Git - ustaxlib.git/blob - src/core/Trace.test.ts
Upgrade to Node v16 for Github workflows.
[ustaxlib.git] / src / core / Trace.test.ts
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
5
6 import Form from './Form';
7 import TaxReturn from './TaxReturn';
8 import { ComputedLine, InputLine, ReferenceLine } from './Line';
9 import { Edge, getLastTraceList } from './Trace';
10
11 class TestTaxReturn extends TaxReturn {
12 readonly constants = undefined;
13
14 get year() { return 2019; }
15
16 get includeJointPersonForms() { return false; }
17 };
18
19 interface Input {
20 name: string;
21 value: number;
22 };
23
24 class TestForm extends Form<Input> {
25 readonly name = 'TF';
26
27 readonly lines = {
28 'i1': new InputLine<Input>('name'),
29 'i2': new InputLine<Input>('value'),
30 'c1': new ComputedLine((tr): string => {
31 return `Hello ${this.getInput('name')}`;
32 }),
33 'c2': new ComputedLine((tr): number => {
34 return this.getValue(tr, 'i2') * 0.20;
35 }),
36 'r2': new ReferenceLine(TestForm as any, 'c2'),
37 };
38 };
39
40 describe('tracing', () => {
41 const tr = new TestTaxReturn();
42 const f = new TestForm({
43 name: 'ABC',
44 value: 100
45 });
46 tr.addForm(f);
47
48 test('input line', () => {
49 f.getValue(tr, 'i1');
50 const trace = getLastTraceList();
51 expect(trace).toStrictEqual([ [ 'TF@i1 (Input from name)', 'TF input: name' ] ]);
52 });
53
54 test('computed line via input', () => {
55 f.getValue(tr, 'c1');
56 const trace = getLastTraceList();
57 expect(trace).toStrictEqual([ [ 'TF@c1', 'TF input: name' ] ]);
58 });
59
60 test('computed line via input line', () => {
61 f.getValue(tr, 'c2');
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' ]
66 ]);
67 });
68
69 test('reference line', () => {
70 f.getValue(tr, 'r2');
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' ]
76 ]);
77 });
78 });
79