Simplify core imports.
[ustaxlib.git] / src / fed2019 / Form1116.test.ts
1 import { Person, TaxReturn } from '../core';
2 import { UnsupportedFeatureError } from '../core/Errors';
3
4 import Form1040, { FilingStatus } from './Form1040';
5 import Form1116, { ForeignIncomeCategory } from './Form1116';
6 import Form1099B, { GainType } from './Form1099B';
7 import Form1099DIV from './Form1099DIV';
8 import Form8949 from './Form8949';
9 import FormW2 from './FormW2';
10 import ScheduleD from './ScheduleD';
11
12 test('supported income category', () => {
13 const p = Person.self('A');
14 const tr = new TaxReturn(2019);
15 const f = new Form1116({
16 person: p,
17 incomeCategory: ForeignIncomeCategory.C,
18 posessionName: "RIC",
19 grossForeignIncome: 100,
20 totalForeignTaxesPaidOrAccrued: 0
21 });
22 tr.addForm(f);
23 expect(f.getValue(tr, 'category')).toBe(ForeignIncomeCategory.C);
24 });
25
26 test('unsupported income categories', () => {
27 for (const category of Object.values(ForeignIncomeCategory)) {
28 if (category == ForeignIncomeCategory.C)
29 continue;
30
31 const p = Person.self('B');
32 const tr = new TaxReturn(2019);
33 const f = new Form1116({
34 person: p,
35 incomeCategory: category,
36 posessionName: "RIC",
37 grossForeignIncome: 100,
38 totalForeignTaxesPaidOrAccrued: 0
39 });
40 tr.addForm(f);
41 expect(() => f.getValue(tr, 'category')).toThrow(UnsupportedFeatureError);
42 }
43 });
44
45 test('foreign tax credit', () => {
46 const p = Person.self('A');
47 const tr = new TaxReturn(2019);
48 tr.addForm(new Form1040({
49 filingStatus: FilingStatus.MarriedFilingJoint
50 }));
51 tr.addForm(new FormW2({
52 employer: 'ACME',
53 employee: p,
54 wages: 697000,
55 }));
56
57 const f = new Form1116({
58 person: p,
59 incomeCategory: ForeignIncomeCategory.C,
60 posessionName: "RIC",
61 grossForeignIncome: 99,
62 totalForeignTaxesPaidOrAccrued: 14
63 });
64 tr.addForm(f);
65
66 expect(f.getValue(tr, '1a')).toBe(99);
67 expect(f.getValue(tr, '3a')).toBe(24400);
68 expect(f.getValue(tr, '3c')).toBe(24400);
69 expect(f.getValue(tr, '3d')).toBe(99);
70 expect(f.getValue(tr, '3e')).toBe(697000);
71 expect(f.getValue(tr, '3f')).toBe(0.0001);
72 expect(f.getValue(tr, '3g')).toBeCloseTo(2.44);
73 expect(f.getValue(tr, '6')).toBeCloseTo(2.44);
74 expect(f.getValue(tr, '7')).toBeCloseTo(96.56);
75 expect(f.getValue(tr, '8')).toBe(14);
76 expect(f.getValue(tr, '9')).toBe(14);
77 expect(f.getValue(tr, '14')).toBe(14);
78 expect(f.getValue(tr, '20')).toBe(((697000-24400) * 0.37) - 61860);
79 expect(f.getValue(tr, '21')).toBeCloseTo(26.846);
80 expect(f.getValue(tr, '22')).toBe(14);
81 expect(f.getValue(tr, '31')).toBe(14);
82 expect(f.getValue(tr, '33')).toBe(14);
83 });
84
85 test('no net capital losses in total income', () => {
86 const p = Person.self('A');
87 const tr = new TaxReturn(2019);
88 tr.addForm(new Form1040({
89 filingStatus: FilingStatus.MarriedFilingJoint
90 }));
91 tr.addForm(new FormW2({
92 employer: 'Megacorp',
93 employee: p,
94 wages: 200000
95 }));
96 tr.addForm(new Form1099B({
97 payer: 'Brokerage',
98 payee: p,
99 description: 'SCHF',
100 proceeds: 100,
101 costBasis: 50,
102 gainType: GainType.LongTerm,
103 basisReportedToIRS: true
104 }));
105 tr.addForm(new Form1099B({
106 payer: 'Brokerage',
107 payee: p,
108 description: 'SCHE',
109 proceeds: 60,
110 costBasis: 100,
111 gainType: GainType.ShortTerm,
112 basisReportedToIRS: true
113 }));
114 tr.addForm(new Form8949);
115 tr.addForm(new ScheduleD);
116
117 const f = new Form1116({
118 person: p,
119 incomeCategory: ForeignIncomeCategory.C,
120 posessionName: 'RIC',
121 grossForeignIncome: 200,
122 totalForeignTaxesPaidOrAccrued: 65
123 });
124
125 expect(tr.getForm(Form8949).getValue(tr, 'boxA').gainOrLoss).toBe(-40);
126 expect(tr.getForm(Form8949).getValue(tr, 'boxD').gainOrLoss).toBe(50);
127 expect(f.getValue(tr, '3e')).toBe(200050);
128 });