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
6 import { Person } from '../core';
7 import { UnsupportedFeatureError } from '../core/Errors';
9 import Form1040, { FilingStatus } from './Form1040';
10 import Form1116, { ForeignIncomeCategory } from './Form1116';
11 import Form1099B from './Form1099B';
12 import Form1099DIV from './Form1099DIV';
13 import Form8949 from './Form8949';
14 import W2 from './W2';
15 import TaxReturn from './TaxReturn';
16 import ScheduleD from './ScheduleD';
18 test('supported income category', () => {
19 const p = Person.self('A');
20 const tr = new TaxReturn();
21 const f = new Form1116({
23 incomeCategory: ForeignIncomeCategory.C,
25 grossForeignIncome: 100,
26 totalForeignTaxesPaidOrAccrued: 0
29 expect(f.getValue(tr, 'category')).toBe(ForeignIncomeCategory.C);
32 test('unsupported income categories', () => {
33 for (const category of Object.values(ForeignIncomeCategory)) {
34 if (category == ForeignIncomeCategory.C)
37 const p = Person.self('B');
38 const tr = new TaxReturn();
39 const f = new Form1116({
41 incomeCategory: category,
43 grossForeignIncome: 100,
44 totalForeignTaxesPaidOrAccrued: 0
47 expect(() => f.getValue(tr, 'category')).toThrow(UnsupportedFeatureError);
51 test('foreign tax credit', () => {
52 const tr = new TaxReturn();
53 const p = Person.self('A');
55 tr.addForm(new Form1040({
56 filingStatus: FilingStatus.MarriedFilingJoint
64 const f = new Form1116({
66 incomeCategory: ForeignIncomeCategory.C,
68 grossForeignIncome: 99,
69 totalForeignTaxesPaidOrAccrued: 14
73 expect(f.getValue(tr, '1a')).toBe(99);
74 expect(f.getValue(tr, '3a')).toBe(24400);
75 expect(f.getValue(tr, '3c')).toBe(24400);
76 expect(f.getValue(tr, '3d')).toBe(99);
77 expect(f.getValue(tr, '3e')).toBe(697000);
78 expect(f.getValue(tr, '3f')).toBe(0.0001);
79 expect(f.getValue(tr, '3g')).toBeCloseTo(2.44);
80 expect(f.getValue(tr, '6')).toBeCloseTo(2.44);
81 expect(f.getValue(tr, '7')).toBeCloseTo(96.56);
82 expect(f.getValue(tr, '8')).toBe(14);
83 expect(f.getValue(tr, '9')).toBe(14);
84 expect(f.getValue(tr, '14')).toBe(14);
85 expect(f.getValue(tr, '20')).toBe(((697000-24400) * 0.37) - 61860);
86 expect(f.getValue(tr, '21')).toBeCloseTo(26.846);
87 expect(f.getValue(tr, '22')).toBe(14);
88 expect(f.getValue(tr, '31')).toBe(14);
89 expect(f.getValue(tr, '33')).toBe(14);
92 test('no net capital losses in total income', () => {
93 const p = Person.self('A');
94 const tr = new TaxReturn();
96 tr.addForm(new Form1040({
97 filingStatus: FilingStatus.MarriedFilingJoint
100 employer: 'Megacorp',
104 tr.addForm(new Form1099B({
107 longTermBasisReported: [
114 shortTermBasisReported: [
122 tr.addForm(new Form8949);
123 tr.addForm(new ScheduleD);
125 const f = new Form1116({
127 incomeCategory: ForeignIncomeCategory.C,
128 posessionName: 'RIC',
129 grossForeignIncome: 200,
130 totalForeignTaxesPaidOrAccrued: 65
133 expect(tr.getForm(Form8949).getValue(tr, 'boxA').gainOrLoss).toBe(-40);
134 expect(tr.getForm(Form8949).getValue(tr, 'boxD').gainOrLoss).toBe(50);
135 expect(f.getValue(tr, '3e')).toBe(200050);