From 2f8f38fbb01c7bbbf4ecbdf7c0a6e34a2f868c5e Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 17 Feb 2020 23:28:34 -0500 Subject: [PATCH] Add Line.test.ts. --- src/Line.test.ts | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/Line.test.ts diff --git a/src/Line.test.ts b/src/Line.test.ts new file mode 100644 index 0000000..4dc6f80 --- /dev/null +++ b/src/Line.test.ts @@ -0,0 +1,53 @@ +import { Line, ReferenceLine, ComputedLine } from './Line'; +import Form from './Form'; +import TaxReturn from './TaxReturn'; +import { NotFoundError } from './Errors'; + +class ConstantLine extends Line { + private _k: T; + + constructor(id: string, k: T) { + super(id, `Constant ${k}`); + this._k = k; + } + + value(tr: TaxReturn): T { + return this._k; + } +}; + +test('computed line', () => { + const tr = new TaxReturn(2019); + const l = new ComputedLine('A', + (taxReturn: TaxReturn, line: ComputedLine): number => { + expect(taxReturn).toBe(tr); + expect(line).toBe(l); + return 42; + }, + 'Computed Line A'); + expect(l.value(tr)).toBe(42); + expect(l.id).toBe('A'); + expect(l.description).toBe('Computed Line A'); +}); + +test('reference line', () => { + class TestForm extends Form { + get name() { return 'Form 1'; } + + protected getLines() { + return [ new ConstantLine('6b', 12.34) ]; + } + }; + + const tr = new TaxReturn(2019); + tr.addForm(new TestForm()); + + const l1 = new ReferenceLine('C', 'Form 1', '6b'); + expect(l1.value(tr)).toBe(12.34); + + const l2 = new ReferenceLine('x', 'Form 2', '6b'); + expect(() => l2.value(tr)).toThrow(NotFoundError); + + const l3 = new ReferenceLine('y', 'Form 1', '7a'); + expect(() => l3.value(tr)).toThrow(NotFoundError); +}); -- 2.22.5