Start modeling Line, Form and their relation to TaxReturn.
[ustaxlib.git] / src / Form.test.ts
1 import { ComputedLine, Line } from './Line';
2 import TaxReturn from './TaxReturn';
3 import Form from './Form';
4 import { InconsistencyError, NotFoundError } from './Errors';
5
6 test('add and get line', () => {
7 const l = new ComputedLine<number>('1', () => 42);
8
9 class TestForm extends Form {
10 get name(): string {
11 return 'Test Form';
12 }
13
14 protected addLines() {
15 this.addLine(l);
16 }
17 };
18
19 const f = new TestForm();
20 expect(f.getLine('1')).toBe(l);
21 });
22
23 test('get non-existent line', () => {
24 class TestForm extends Form {
25 get name(): string {
26 return 'Test Form';
27 }
28
29 protected addLines() {
30 }
31 };
32
33 const f = new TestForm();
34 expect(() => f.getLine('1')).toThrow(NotFoundError);
35 });
36
37 test('add duplicate line', () => {
38 const l1 = new ComputedLine<number>('1', () => 42);
39 const l2 = new ComputedLine<number>('1', () => 36);
40
41 class TestForm extends Form {
42 get name(): string {
43 return 'Test Form';
44 }
45
46 protected addLines() {
47 this.addLine(l1);
48 this.addLine(l2);
49 }
50 };
51
52 expect(() => new TestForm()).toThrow(InconsistencyError);
53 });