From c7962dabcb56aef4ac25582b6bd87b0d313052c5 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 17 Feb 2020 23:05:38 -0500 Subject: [PATCH] Restructure adding Lines to Forms. --- src/Form.test.ts | 12 ++++++------ src/Form.ts | 6 +++--- src/TaxReturn.test.ts | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Form.test.ts b/src/Form.test.ts index 24a93e6..d3f2f6f 100644 --- a/src/Form.test.ts +++ b/src/Form.test.ts @@ -11,8 +11,8 @@ test('add and get line', () => { return 'Test Form'; } - protected addLines() { - this.addLine(l); + protected getLines() { + return [l]; } }; @@ -26,7 +26,8 @@ test('get non-existent line', () => { return 'Test Form'; } - protected addLines() { + protected getLines() { + return []; } }; @@ -43,9 +44,8 @@ test('add duplicate line', () => { return 'Test Form'; } - protected addLines() { - this.addLine(l1); - this.addLine(l2); + protected getLines() { + return [l1, l2]; } }; diff --git a/src/Form.ts b/src/Form.ts index fe1493d..7b9bf07 100644 --- a/src/Form.ts +++ b/src/Form.ts @@ -7,16 +7,16 @@ export default abstract class Form { abstract get name(): string; constructor() { - this.addLines(); + this.getLines().map(this.addLine.bind(this)); } - protected abstract addLines(): void; + protected abstract getLines(): Line[]; get allowMultipleCopies(): boolean { return false; } - protected addLine(line: Line) { + private addLine(line: Line) { try { this.getLine(line.id); } catch { diff --git a/src/TaxReturn.test.ts b/src/TaxReturn.test.ts index e6a6165..74c82f4 100644 --- a/src/TaxReturn.test.ts +++ b/src/TaxReturn.test.ts @@ -56,7 +56,7 @@ test('single-copy forms', () => { class TestForm extends Form { get name(): string { return 'Test Form'; } - protected addLines() {} + protected getLines() { return []; } }; const tr = new TaxReturn(2019); @@ -72,7 +72,7 @@ test('multiple-copy forms', () => { get allowMultipleCopies(): boolean { return true; } - protected addLines() {} + protected getLines() { return []; } }; const tr = new TaxReturn(2019); -- 2.22.5