@startsimpli/integrations 0.2.148 → 0.2.150
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -6
- package/src/__tests__/connection-check-reason.test.tsx +85 -0
- package/src/__tests__/focus-history.test.ts +90 -0
- package/src/__tests__/goal-rows.test.ts +51 -0
- package/src/__tests__/goals-page.test.tsx +124 -0
- package/src/__tests__/liabilities.test.ts +224 -0
- package/src/__tests__/liability-plan-page.test.tsx +46 -0
- package/src/__tests__/stated-date-extract.test.ts +119 -0
- package/src/__tests__/stated-date.test.ts +107 -0
- package/src/components/index.ts +2 -0
- package/src/components/pages/LiabilityPlanPage.tsx +203 -0
- package/src/components/pages/PlanningPage.tsx +16 -2
- package/src/components/pages/connections/ConnectionCard.tsx +12 -0
- package/src/components/pages/connections/bound-api.ts +1 -1
- package/src/components/pages/goals/FocusProgressHistory.tsx +77 -0
- package/src/components/pages/goals/GoalsPage.tsx +186 -0
- package/src/components/pages/goals/index.ts +4 -0
- package/src/components/pages/types.ts +2 -2
- package/src/corpus/client.ts +18 -0
- package/src/corpus/commitments.ts +3 -1
- package/src/corpus/extract.ts +8 -6
- package/src/corpus/focus-history.ts +104 -0
- package/src/corpus/goal-rows.ts +29 -0
- package/src/corpus/index.ts +10 -0
- package/src/corpus/liabilities.ts +238 -0
- package/src/corpus/liability-client.ts +101 -0
- package/src/corpus/liability-plan.ts +40 -0
- package/src/corpus/planning.ts +8 -0
- package/src/corpus/spoken-time.ts +4 -4
- package/src/corpus/stated-date.ts +187 -0
- package/src/corpus/types.ts +24 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/integrations",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.150",
|
|
4
4
|
"description": "Provider-agnostic types, API clients, hooks, and UI primitives for email + calendar integrations across StartSimpli apps, plus foundry customer email (subpath ./comms).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://startsimpli.com",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"react-native": ">=0.74.0",
|
|
51
51
|
"@startsimpli/ui-native": ">=0.1.12",
|
|
52
52
|
"react-native-safe-area-context": ">=4.0.0",
|
|
53
|
-
"@startsimpli/
|
|
54
|
-
"@startsimpli/utils": "^0.4.
|
|
55
|
-
"@startsimpli/
|
|
53
|
+
"@startsimpli/ui": "^0.4.172",
|
|
54
|
+
"@startsimpli/utils": "^0.4.18",
|
|
55
|
+
"@startsimpli/auth": "^0.4.50"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"react": {
|
|
@@ -99,10 +99,10 @@
|
|
|
99
99
|
"react-native": "0.85.3",
|
|
100
100
|
"react-native-safe-area-context": "~5.7.0",
|
|
101
101
|
"@startsimpli/llm": "0.4.31",
|
|
102
|
-
"@startsimpli/ui": "0.4.
|
|
102
|
+
"@startsimpli/ui": "0.4.172",
|
|
103
103
|
"@startsimpli/ui-native": "0.1.14",
|
|
104
104
|
"@startsimpli/auth": "0.4.50",
|
|
105
|
-
"@startsimpli/utils": "0.4.
|
|
105
|
+
"@startsimpli/utils": "0.4.18"
|
|
106
106
|
},
|
|
107
107
|
"scripts": {
|
|
108
108
|
"type-check": "tsc --noEmit && tsc --noEmit -p tsconfig.native.json",
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A KEY THAT WORKS BUT SEES NOTHING SAYS WHY (bd startsim-768w.38.16).
|
|
3
|
+
*
|
|
4
|
+
* "0 note(s) visible on the first page" is accurate and useless: the admin reads
|
|
5
|
+
* it as a broken integration. A connector that authenticates but whose grant is
|
|
6
|
+
* empty returns `reason` and `next_step` beside `detail`. This page renders them
|
|
7
|
+
* for ANY connector, naming no vendor, and never hides `detail`.
|
|
8
|
+
*/
|
|
9
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
10
|
+
import { render, screen } from '@testing-library/react';
|
|
11
|
+
import userEvent from '@testing-library/user-event';
|
|
12
|
+
|
|
13
|
+
import { ConnectionsPage } from '../components/pages/ConnectionsPage';
|
|
14
|
+
import type { ConnectionsApi } from '../components/pages/types';
|
|
15
|
+
|
|
16
|
+
const CATALOG = {
|
|
17
|
+
results: [
|
|
18
|
+
{
|
|
19
|
+
key: 'granola', name: 'Granola', description: 'Meeting notes',
|
|
20
|
+
logo_url: '', docs_url: '', capabilities: ['poll'], auth_mode: 'api_key',
|
|
21
|
+
credential_schema: { version: 1, fields: [] },
|
|
22
|
+
config_schema: { version: 1, fields: [] },
|
|
23
|
+
record_types: [], supports_webhooks: false,
|
|
24
|
+
availability: { available: true, reason: '' },
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const CONNECTED = {
|
|
30
|
+
results: [
|
|
31
|
+
{
|
|
32
|
+
id: 'c1', public_id: 'pub1', name: 'Tandem Granola',
|
|
33
|
+
connector_key: 'granola', connector_name: 'Granola',
|
|
34
|
+
external_account_id: '', account_label: 'tandem',
|
|
35
|
+
capabilities_enabled: ['poll'], config: {}, status: 'connected',
|
|
36
|
+
health: 'ok', auth_mode: 'api_key',
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
permissions: { view: true, manage: true, issue_tokens: true },
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function stubApi(check: Record<string, unknown>): ConnectionsApi {
|
|
43
|
+
return {
|
|
44
|
+
connectorCatalog: vi.fn().mockResolvedValue(CATALOG),
|
|
45
|
+
connections: vi.fn().mockResolvedValue(CONNECTED),
|
|
46
|
+
connect: vi.fn(),
|
|
47
|
+
checkConnection: vi.fn().mockResolvedValue(check),
|
|
48
|
+
disconnect: vi.fn(),
|
|
49
|
+
connectionChoices: vi.fn(),
|
|
50
|
+
wireTarget: vi.fn(),
|
|
51
|
+
confirmTarget: vi.fn(),
|
|
52
|
+
connectionActions: vi.fn(),
|
|
53
|
+
invokeConnectionAction: vi.fn(),
|
|
54
|
+
updateConnection: vi.fn(),
|
|
55
|
+
rotateCredential: vi.fn(),
|
|
56
|
+
} as unknown as ConnectionsApi;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function runTest(check: Record<string, unknown>) {
|
|
60
|
+
render(<ConnectionsPage api={stubApi(check)} foundrySlug="tandem" />);
|
|
61
|
+
await userEvent.click(await screen.findByRole('button', { name: /^Test$/i }));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
describe('the Test result on a connection card', () => {
|
|
65
|
+
it('shows the reason and the next step when the grant is empty, and keeps the raw detail', async () => {
|
|
66
|
+
await runTest({
|
|
67
|
+
ok: true, account_label: 'tandem',
|
|
68
|
+
detail: 'scope workspace: 0 note(s) visible on the first page',
|
|
69
|
+
reason: 'No notes are visible to this key.',
|
|
70
|
+
next_step: 'Enable API access for a space, then check again.',
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const reason = await screen.findByText('No notes are visible to this key.');
|
|
74
|
+
expect(reason.closest('[data-check-reason]')).not.toBeNull();
|
|
75
|
+
expect(screen.getByText('Enable API access for a space, then check again.')).toBeInTheDocument();
|
|
76
|
+
expect(screen.getByText(/0 note\(s\) visible on the first page/)).toBeInTheDocument();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('renders no reason block when the connector gave none', async () => {
|
|
80
|
+
await runTest({ ok: true, account_label: 'tandem', detail: 'all good', reason: '', next_step: '' });
|
|
81
|
+
|
|
82
|
+
expect(await screen.findByText('all good')).toBeInTheDocument();
|
|
83
|
+
expect(document.querySelector('[data-check-reason]')).toBeNull();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { currentValueSeries, toFocusRevision, loadCurrentValueRevisions } from '../corpus/focus-history';
|
|
3
|
+
|
|
4
|
+
const rev = (version: number, at: string, before: unknown, after: unknown, key = 'current_value') =>
|
|
5
|
+
toFocusRevision({
|
|
6
|
+
version, created_at: at, actor_label: 'ana@x.test', action: 'updated',
|
|
7
|
+
metadata: { changed: { [key]: { ...(before === undefined ? {} : { before }), after } } },
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe('toFocusRevision', () => {
|
|
11
|
+
it('reads snake and camel spellings of the wire', () => {
|
|
12
|
+
const r = toFocusRevision({ version: 2, createdAt: '2026-11-01T10:00:00Z', actorLabel: 'a', metadata: { changed: { currentValue: { before: 1, after: 2 } } } });
|
|
13
|
+
expect(r).toMatchObject({ version: 2, createdAt: '2026-11-01T10:00:00Z', actor: 'a' });
|
|
14
|
+
expect(r.currentValue).toEqual({ before: 1, after: 2 });
|
|
15
|
+
});
|
|
16
|
+
it('a revision that did not move current_value has none', () => {
|
|
17
|
+
expect(toFocusRevision({ version: 1, created_at: '2026-11-01T00:00:00Z', metadata: { changed: { title: { after: 'x' } } } }).currentValue).toBeUndefined();
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('currentValueSeries', () => {
|
|
22
|
+
it('builds dated points oldest first with the delta as the event', () => {
|
|
23
|
+
const { points } = currentValueSeries([rev(3, '2026-11-05T09:00:00Z', 5, 8), rev(2, '2026-11-01T09:00:00Z', 2, 5)], '2026-11-05');
|
|
24
|
+
expect(points.map((p) => [p.date, p.value])).toEqual([['2026-11-01', 5], ['2026-11-05', 8]]);
|
|
25
|
+
expect(points[1].events?.[0].delta).toBe(3);
|
|
26
|
+
});
|
|
27
|
+
it('two edits in one day: the end-of-day value wins and both events stay', () => {
|
|
28
|
+
const { points } = currentValueSeries([rev(3, '2026-11-01T18:00:00Z', 5, 7), rev(2, '2026-11-01T09:00:00Z', 2, 5)], '2026-11-02');
|
|
29
|
+
expect(points[0]).toMatchObject({ date: '2026-11-01', value: 7 });
|
|
30
|
+
expect(points[0].events).toHaveLength(2);
|
|
31
|
+
});
|
|
32
|
+
it('holds the last value to the anchor day without inventing an event', () => {
|
|
33
|
+
const { points } = currentValueSeries([rev(2, '2026-11-01T09:00:00Z', 2, 5)], '2026-11-05');
|
|
34
|
+
expect(points.at(-1)).toMatchObject({ date: '2026-11-05', value: 5 });
|
|
35
|
+
expect(points.at(-1)?.events ?? []).toEqual([]);
|
|
36
|
+
});
|
|
37
|
+
it('no revisions that moved current_value: no points at all, never a flat line', () => {
|
|
38
|
+
expect(currentValueSeries([], '2026-11-05').points).toEqual([]);
|
|
39
|
+
const other = toFocusRevision({ version: 1, created_at: '2026-11-01T00:00:00Z', metadata: { changed: { title: { after: 'x' } } } });
|
|
40
|
+
expect(currentValueSeries([other], '2026-11-05').points).toEqual([]);
|
|
41
|
+
});
|
|
42
|
+
it('ignores a non-numeric or removed value', () => {
|
|
43
|
+
const gone = toFocusRevision({ version: 2, created_at: '2026-11-02T00:00:00Z', metadata: { changed: { current_value: { before: 5 } } } });
|
|
44
|
+
const text = rev(3, '2026-11-03T00:00:00Z', 5, 'n/a');
|
|
45
|
+
expect(currentValueSeries([text, gone], '2026-11-05').points).toEqual([]);
|
|
46
|
+
});
|
|
47
|
+
it('reports the oldest recorded change, so the chart can say what it covers', () => {
|
|
48
|
+
expect(currentValueSeries([rev(2, '2026-11-01T09:00:00Z', 2, 5)], '2026-11-05').since).toBe('2026-11-01');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('loadCurrentValueRevisions', () => {
|
|
53
|
+
const page = (rows: ReturnType<typeof rev>[], next: boolean) => ({ count: 9, next: next ? 'n' : null, previous: null, results: rows });
|
|
54
|
+
it('pages newest-first until it is past the 90 day window, then stops', async () => {
|
|
55
|
+
const calls: number[] = [];
|
|
56
|
+
const pages = [
|
|
57
|
+
page([rev(9, '2026-11-01T00:00:00Z', 1, 2)], true),
|
|
58
|
+
page([rev(8, '2026-06-01T00:00:00Z', 0, 1)], true),
|
|
59
|
+
page([rev(7, '2026-05-01T00:00:00Z', 0, 0)], false),
|
|
60
|
+
];
|
|
61
|
+
const out = await loadCurrentValueRevisions(async (n) => { calls.push(n); return pages[n - 1]; }, '2026-11-05');
|
|
62
|
+
expect(calls).toEqual([1, 2]);
|
|
63
|
+
expect(out).toHaveLength(2);
|
|
64
|
+
});
|
|
65
|
+
it('stops when there is no next page', async () => {
|
|
66
|
+
const calls: number[] = [];
|
|
67
|
+
await loadCurrentValueRevisions(async (n) => { calls.push(n); return page([rev(1, '2026-11-01T00:00:00Z', 0, 1)], false); }, '2026-11-05');
|
|
68
|
+
expect(calls).toEqual([1]);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
import { createPlanningApi } from '../corpus/client';
|
|
73
|
+
|
|
74
|
+
describe('planning client: listFocusRevisions / endDate order', () => {
|
|
75
|
+
it('reads only current_value saves, server-paginated, and maps them', async () => {
|
|
76
|
+
const gets: Array<{ path: string; params?: Record<string, unknown> }> = [];
|
|
77
|
+
const http = {
|
|
78
|
+
async get(path: string, init?: { params?: Record<string, unknown> }) {
|
|
79
|
+
gets.push({ path, params: init?.params });
|
|
80
|
+
return { count: 1, next: null, previous: null, results: [{ version: 4, created_at: '2026-11-01T00:00:00Z', metadata: { changed: { current_value: { before: 1, after: 2 } } } }] };
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
const api = createPlanningApi({ http: http as never, scope: { orgId: 'o' } });
|
|
84
|
+
const out = await api.listFocusRevisions!('f1', { page: 2, pageSize: 100 });
|
|
85
|
+
expect(gets[0]).toEqual({ path: 'api/v1/entities/f1/revisions/', params: { field: 'current_value', page: 2, page_size: 100 } });
|
|
86
|
+
expect(out.results[0].currentValue).toEqual({ before: 1, after: 2 });
|
|
87
|
+
await api.listFocuses({ orderBy: 'endDate' });
|
|
88
|
+
expect(gets[1].params).toMatchObject({ order: 'attr.end_date' });
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { focusToGoalRow } from '../corpus/goal-rows';
|
|
3
|
+
import type { Focus } from '../corpus/types';
|
|
4
|
+
|
|
5
|
+
const base: Focus = {
|
|
6
|
+
id: 'f1', externalId: 'focus:f1', title: 'Ship v2', detail: '', status: 'active',
|
|
7
|
+
scope: { orgId: 'tandem' },
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
describe('focusToGoalRow', () => {
|
|
11
|
+
it('maps a measurable focus to target / current / unit', () => {
|
|
12
|
+
const row = focusToGoalRow({ ...base, targetValue: 10, currentValue: 4, unit: 'deals' });
|
|
13
|
+
expect(row).toMatchObject({ id: 'f1', title: 'Ship v2', target: 10, current: 4, unit: 'deals' });
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('a focus with no target is qualitative: no target and no current are sent', () => {
|
|
17
|
+
const row = focusToGoalRow({ ...base, currentValue: 3 });
|
|
18
|
+
expect(row.target).toBeUndefined();
|
|
19
|
+
expect(row.current).toBeUndefined();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('a target of 0 or less is qualitative, never a fully-achieved goal', () => {
|
|
23
|
+
expect(focusToGoalRow({ ...base, targetValue: 0, currentValue: 0 }).target).toBeUndefined();
|
|
24
|
+
expect(focusToGoalRow({ ...base, targetValue: -5, currentValue: 1 }).target).toBeUndefined();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('a target with nothing recorded yet is 0 of the target, not "no target"', () => {
|
|
28
|
+
expect(focusToGoalRow({ ...base, targetValue: 10 })).toMatchObject({ target: 10, current: 0 });
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('never invents progress from item counts or the stored progress field', () => {
|
|
32
|
+
const row = focusToGoalRow({ ...base, progress: 0.8 });
|
|
33
|
+
expect(row.target).toBeUndefined();
|
|
34
|
+
expect(row.current).toBeUndefined();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('owner is the display name, else absent; never the raw sub', () => {
|
|
38
|
+
expect(focusToGoalRow({ ...base, ownerName: 'Ana', ownerSub: 'user:1' }).owner).toBe('Ana');
|
|
39
|
+
expect(focusToGoalRow({ ...base, ownerSub: 'user:1' }).owner).toBeUndefined();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('due is the end date cut to a day; subtype falls back to category', () => {
|
|
43
|
+
expect(focusToGoalRow({ ...base, endDate: '2026-12-31T10:00:00Z' }).due).toBe('2026-12-31');
|
|
44
|
+
expect(focusToGoalRow({ ...base, subtype: 'payoff', category: 'financial' }).subtype).toBe('payoff');
|
|
45
|
+
expect(focusToGoalRow({ ...base, category: 'financial' }).subtype).toBe('financial');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('status is the readable label', () => {
|
|
49
|
+
expect(focusToGoalRow({ ...base, status: 'on_track' }).status).toBe('on track');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { GoalsPage } from '../components/pages/goals';
|
|
4
|
+
import { FocusProgressHistory } from '../components/pages/goals/FocusProgressHistory';
|
|
5
|
+
import type { CorpusPage, Focus, FocusQuery } from '../corpus/types';
|
|
6
|
+
|
|
7
|
+
const SCOPE = { orgId: 'tandem' };
|
|
8
|
+
const NOW = Date.parse('2026-11-05T12:00:00Z');
|
|
9
|
+
|
|
10
|
+
const mk = (id: string, over: Partial<Focus> = {}): Focus => ({
|
|
11
|
+
id, externalId: `focus:${id}`, title: `Goal ${id}`, detail: '', status: 'active', scope: SCOPE, ...over,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
function page(results: Focus[], count = results.length, next: string | null = null, previous: string | null = null): CorpusPage<Focus> {
|
|
15
|
+
return { count, next, previous, results, appliedFilters: [] };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe('GoalsPage', () => {
|
|
19
|
+
it('shows a measurable goal with its numbers and a qualitative one as No target, never 0%', async () => {
|
|
20
|
+
const listFocuses = vi.fn(async () => page([
|
|
21
|
+
mk('a', { targetValue: 10, currentValue: 4, unit: 'deals' }),
|
|
22
|
+
mk('b'),
|
|
23
|
+
mk('c', { targetValue: 0, currentValue: 0 }),
|
|
24
|
+
]));
|
|
25
|
+
render(<GoalsPage api={{ listFocuses }} scope={SCOPE} now={NOW} />);
|
|
26
|
+
expect(await screen.findByText('Goal a')).toBeTruthy();
|
|
27
|
+
expect(screen.getByText(/4 \/ 10 deals/)).toBeTruthy();
|
|
28
|
+
expect(screen.getAllByText('No target')).toHaveLength(2);
|
|
29
|
+
expect(screen.getByTestId('goal-progress-table').textContent).not.toMatch(/\b0%/);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('asks the server for page 1 in play, worst-off first, and states the range', async () => {
|
|
33
|
+
const listFocuses = vi.fn(async (_q?: FocusQuery) => page([mk('a')], 60, 'next'));
|
|
34
|
+
render(<GoalsPage api={{ listFocuses }} scope={SCOPE} now={NOW} pageSize={25} />);
|
|
35
|
+
await screen.findByText('Goal a');
|
|
36
|
+
const q = listFocuses.mock.calls[0][0]!;
|
|
37
|
+
expect(q).toMatchObject({ page: 1, pageSize: 25, orderBy: 'progress' });
|
|
38
|
+
expect(q.status).toEqual(['draft', 'active', 'on_track', 'at_risk', 'off_track', 'completed']);
|
|
39
|
+
expect(screen.getByTestId('goals-range').textContent).toBe('Showing 1–1 of 60');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('Next asks the server for page 2; changing a filter returns to page 1', async () => {
|
|
43
|
+
const listFocuses = vi.fn(async (q?: FocusQuery) => page([mk(`p${q?.page}`)], 60, q?.page === 1 ? 'n' : null));
|
|
44
|
+
render(<GoalsPage api={{ listFocuses }} scope={SCOPE} now={NOW} />);
|
|
45
|
+
await screen.findByText('Goal p1');
|
|
46
|
+
fireEvent.click(screen.getByRole('button', { name: 'Next' }));
|
|
47
|
+
await screen.findByText('Goal p2');
|
|
48
|
+
expect(listFocuses.mock.calls.at(-1)![0]).toMatchObject({ page: 2 });
|
|
49
|
+
fireEvent.change(screen.getByLabelText('Sort goals'), { target: { value: 'endDate' } });
|
|
50
|
+
await waitFor(() => expect(listFocuses.mock.calls.at(-1)![0]).toMatchObject({ page: 1, orderBy: 'endDate' }));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('filters by status and searches on the server', async () => {
|
|
54
|
+
const listFocuses = vi.fn(async (_q?: FocusQuery) => page([mk('a')]));
|
|
55
|
+
render(<GoalsPage api={{ listFocuses }} scope={SCOPE} now={NOW} />);
|
|
56
|
+
await screen.findByText('Goal a');
|
|
57
|
+
fireEvent.change(screen.getByLabelText('Filter by status'), { target: { value: 'at_risk' } });
|
|
58
|
+
await waitFor(() => expect(listFocuses.mock.calls.at(-1)![0]).toMatchObject({ status: 'at_risk' }));
|
|
59
|
+
fireEvent.change(screen.getByLabelText('Search goals'), { target: { value: 'launch' } });
|
|
60
|
+
fireEvent.click(screen.getByRole('button', { name: 'Search' }));
|
|
61
|
+
await waitFor(() => expect(listFocuses.mock.calls.at(-1)![0]).toMatchObject({ search: 'launch', page: 1 }));
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('row click hands the focus id to the host', async () => {
|
|
65
|
+
const onOpenFocus = vi.fn();
|
|
66
|
+
render(<GoalsPage api={{ listFocuses: async () => page([mk('a')]) }} scope={SCOPE} now={NOW} onOpenFocus={onOpenFocus} />);
|
|
67
|
+
fireEvent.click(await screen.findByText('Goal a'));
|
|
68
|
+
expect(onOpenFocus).toHaveBeenCalledWith('a');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('marks a past-due goal overdue against the injected clock, not a done one', async () => {
|
|
72
|
+
render(<GoalsPage
|
|
73
|
+
api={{ listFocuses: async () => page([mk('a', { endDate: '2026-10-01' }), mk('b', { endDate: '2026-10-01', status: 'completed' })]) }}
|
|
74
|
+
scope={SCOPE} now={NOW}
|
|
75
|
+
/>);
|
|
76
|
+
await screen.findByText('Goal a');
|
|
77
|
+
expect(screen.getAllByText('Overdue')).toHaveLength(1);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('says when a filter was requested but the server did not apply it', async () => {
|
|
81
|
+
const listFocuses = async () => ({ ...page([mk('a')]), appliedFilters: ['type', 'order'] });
|
|
82
|
+
render(<GoalsPage api={{ listFocuses }} scope={SCOPE} now={NOW} />);
|
|
83
|
+
expect((await screen.findByRole('status')).textContent).toMatch(/did not filter by status/);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('surfaces a failed read', async () => {
|
|
87
|
+
render(<GoalsPage api={{ listFocuses: async () => { throw new Error('boom'); } }} scope={SCOPE} now={NOW} />);
|
|
88
|
+
expect(await screen.findByRole('alert')).toBeTruthy();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('FocusProgressHistory', () => {
|
|
93
|
+
const rev = (version: number, at: string, before: number, after: number) => ({
|
|
94
|
+
version, createdAt: at, currentValue: { before, after },
|
|
95
|
+
});
|
|
96
|
+
const goal = mk('a', { targetValue: 10, currentValue: 8 });
|
|
97
|
+
|
|
98
|
+
it('draws the chart from recorded changes', async () => {
|
|
99
|
+
const listFocusRevisions = vi.fn(async () => ({ count: 2, next: null, previous: null, results: [rev(3, '2026-11-04T10:00:00Z', 5, 8), rev(2, '2026-10-20T10:00:00Z', 0, 5)] }));
|
|
100
|
+
render(<FocusProgressHistory focus={goal} api={{ listFocusRevisions }} today="2026-11-05" />);
|
|
101
|
+
expect(await screen.findByTestId('range-timeline')).toBeTruthy();
|
|
102
|
+
expect(screen.getByText(/Recorded since 2026-10-20/)).toBeTruthy();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('with no recorded change it says so instead of drawing a flat line', async () => {
|
|
106
|
+
const listFocusRevisions = async () => ({ count: 0, next: null, previous: null, results: [] });
|
|
107
|
+
render(<FocusProgressHistory focus={goal} api={{ listFocusRevisions }} today="2026-11-05" />);
|
|
108
|
+
expect(await screen.findByText(/No progress changes recorded yet/)).toBeTruthy();
|
|
109
|
+
expect(screen.queryByTestId('range-timeline')).toBeNull();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('a workspace without the trail says history is unavailable', async () => {
|
|
113
|
+
const listFocusRevisions = async () => { throw new Error('404'); };
|
|
114
|
+
render(<FocusProgressHistory focus={goal} api={{ listFocusRevisions }} today="2026-11-05" />);
|
|
115
|
+
expect(await screen.findByText(/not available/)).toBeTruthy();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('renders nothing for a qualitative goal or an api without history', () => {
|
|
119
|
+
const { container, rerender } = render(<FocusProgressHistory focus={mk('q')} api={{ listFocusRevisions: async () => ({ count: 0, next: null, previous: null, results: [] }) }} today="2026-11-05" />);
|
|
120
|
+
expect(container.firstChild).toBeNull();
|
|
121
|
+
rerender(<FocusProgressHistory focus={goal} api={{}} today="2026-11-05" />);
|
|
122
|
+
expect(container.firstChild).toBeNull();
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Liabilities as generic entities, and a payoff scenario as a focus variant
|
|
3
|
+
* (bd startsim-a01ps.8).
|
|
4
|
+
*
|
|
5
|
+
* One `liability` type with a free-text subtype maps onto the payoff engine's
|
|
6
|
+
* `PayoffDebt`; a scenario is a `focus` with subtype `payoff_scenario` whose
|
|
7
|
+
* `params` the engine reads. Nothing here is stored that can be computed.
|
|
8
|
+
*/
|
|
9
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
10
|
+
import {
|
|
11
|
+
LIABILITY_TYPE,
|
|
12
|
+
PAYOFF_SCENARIO,
|
|
13
|
+
liabilitiesToPayoffDebts,
|
|
14
|
+
liabilityToEntity,
|
|
15
|
+
liabilityToPayoffDebt,
|
|
16
|
+
scenarioFocusDraft,
|
|
17
|
+
scenarioParamsFromFocus,
|
|
18
|
+
toLiability,
|
|
19
|
+
} from '../corpus/liabilities';
|
|
20
|
+
import { runPayoffScenario } from '../corpus/liability-plan';
|
|
21
|
+
import { createLiabilityApi } from '../corpus/liability-client';
|
|
22
|
+
import { createPlanningApi } from '../corpus/client';
|
|
23
|
+
import { focusToEntity, toFocus } from '../corpus/planning';
|
|
24
|
+
|
|
25
|
+
const SCOPE = { orgId: 'o' } as never;
|
|
26
|
+
|
|
27
|
+
function row(over: Record<string, unknown> = {}) {
|
|
28
|
+
return {
|
|
29
|
+
id: 'l1', entity_type: LIABILITY_TYPE, external_id: 'liability:l1', name: 'Visa',
|
|
30
|
+
data: { title: 'Visa', subtype: 'credit_card', status: 'active', balance: 5000, apr: 21.99, min_payment: 125, ...over },
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe('toLiability / liabilityToEntity', () => {
|
|
35
|
+
it('reads the shared fields and keeps the kind a free string', () => {
|
|
36
|
+
const l = toLiability(row({ subtype: 'boat_loan', credit_limit: 9000 }), { orgId: 'o' });
|
|
37
|
+
expect(l).toMatchObject({ title: 'Visa', subtype: 'boat_loan', status: 'active', balance: 5000, apr: 21.99, minPayment: 125, creditLimit: 9000 });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('leaves an absent balance absent, never 0', () => {
|
|
41
|
+
const l = toLiability(row({ balance: undefined }), { orgId: 'o' });
|
|
42
|
+
expect(l.balance).toBeUndefined();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('accepts numbers that arrive as strings', () => {
|
|
46
|
+
const l = toLiability(row({ balance: '5000.50', apr: '21.99' }), { orgId: 'o' });
|
|
47
|
+
expect([l.balance, l.apr]).toEqual([5000.5, 21.99]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('falls back to active for a status that did not survive the round trip', () => {
|
|
51
|
+
expect(toLiability(row({ status: 'weird' }), { orgId: 'o' }).status).toBe('active');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('writes the upsert payload under the liability type, with an authored origin', () => {
|
|
55
|
+
const e = liabilityToEntity({ title: 'Visa', subtype: 'credit_card', balance: 5000, apr: 21.99, minPayment: 125 }, 'liability:abc');
|
|
56
|
+
expect(e).toMatchObject({
|
|
57
|
+
entity_type: 'liability', external_id: 'liability:abc', name: 'Visa',
|
|
58
|
+
data: { title: 'Visa', subtype: 'credit_card', status: 'active', balance: 5000, apr: 21.99, min_payment: 125, _origin: 'human' },
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('omits what was not given instead of writing nulls', () => {
|
|
63
|
+
const { data } = liabilityToEntity({ title: 'Visa', subtype: 'credit_card' }, 'liability:abc');
|
|
64
|
+
expect(Object.keys(data)).not.toContain('balance');
|
|
65
|
+
expect(Object.keys(data)).not.toContain('apr');
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('liabilityToPayoffDebt', () => {
|
|
70
|
+
it('maps balance, apr and minimum payment onto the engine shape', () => {
|
|
71
|
+
const l = toLiability(row(), { orgId: 'o' });
|
|
72
|
+
expect(liabilityToPayoffDebt(l)).toEqual({ id: 'l1', name: 'Visa', balance: 5000, apr: 21.99, minPayment: 125 });
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('leaves out debts the plan cannot pay down: paid off, closed, deferred or no balance', () => {
|
|
76
|
+
const mk = (over: Record<string, unknown>) => toLiability(row(over), { orgId: 'o' });
|
|
77
|
+
expect(liabilityToPayoffDebt(mk({ status: 'paid_off' }))).toBeNull();
|
|
78
|
+
expect(liabilityToPayoffDebt(mk({ status: 'closed' }))).toBeNull();
|
|
79
|
+
expect(liabilityToPayoffDebt(mk({ status: 'deferred' }))).toBeNull();
|
|
80
|
+
expect(liabilityToPayoffDebt(mk({ balance: 0 }))).toBeNull();
|
|
81
|
+
expect(liabilityToPayoffDebt(mk({ balance: undefined }))).toBeNull();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('treats a missing apr or minimum as zero rather than dropping the debt', () => {
|
|
85
|
+
const l = toLiability(row({ apr: undefined, min_payment: undefined }), { orgId: 'o' });
|
|
86
|
+
expect(liabilityToPayoffDebt(l)).toMatchObject({ apr: 0, minPayment: 0 });
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('maps a list and skips the ineligible', () => {
|
|
90
|
+
const ls = [toLiability(row(), { orgId: 'o' }), toLiability(row({ status: 'closed' }), { orgId: 'o' })];
|
|
91
|
+
expect(liabilitiesToPayoffDebts(ls)).toHaveLength(1);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('a payoff scenario is a focus variant', () => {
|
|
96
|
+
const params = { strategy: 'avalanche' as const, monthlyPayment: 600, startDate: '2026-12-01' };
|
|
97
|
+
|
|
98
|
+
it('builds a focus draft with the subtype, params and a parent', () => {
|
|
99
|
+
const draft = scenarioFocusDraft('Avalanche $600', params, { parentId: 'plan1' });
|
|
100
|
+
expect(draft).toMatchObject({ title: 'Avalanche $600', subtype: PAYOFF_SCENARIO, params: { strategy: 'avalanche', monthly_payment: 600, start_date: '2026-12-01' }, parentId: 'plan1' });
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('round-trips through the focus entity', () => {
|
|
104
|
+
const draft = scenarioFocusDraft('Avalanche $600', params);
|
|
105
|
+
const e = focusToEntity(draft, 'focus:s1');
|
|
106
|
+
expect(e.data.subtype).toBe('payoff_scenario');
|
|
107
|
+
const focus = toFocus({ id: 'f1', entity_type: 'focus', external_id: 'focus:s1', name: 'x', data: e.data } as never, { orgId: 'o' });
|
|
108
|
+
expect(scenarioParamsFromFocus(focus)).toEqual(params);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('is not a scenario when the subtype is something else or the params are unusable', () => {
|
|
112
|
+
const base = toFocus({ id: 'f', entity_type: 'focus', external_id: 'focus:x', name: 'x', data: { title: 'x' } } as never, { orgId: 'o' });
|
|
113
|
+
expect(scenarioParamsFromFocus(base)).toBeNull();
|
|
114
|
+
expect(scenarioParamsFromFocus({ ...base, subtype: PAYOFF_SCENARIO, params: { strategy: 'nope' } })).toBeNull();
|
|
115
|
+
expect(scenarioParamsFromFocus({ ...base, subtype: PAYOFF_SCENARIO, params: { strategy: 'snowball', monthly_payment: -5 } })).toBeNull();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('an ordinary focus entity carries no subtype or params keys', () => {
|
|
119
|
+
expect(Object.keys(focusToEntity({ title: 'Plain' }).data)).not.toContain('subtype');
|
|
120
|
+
expect(Object.keys(focusToEntity({ title: 'Plain' }).data)).not.toContain('params');
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('runPayoffScenario', () => {
|
|
125
|
+
const ls = [
|
|
126
|
+
toLiability(row({ title: 'Visa', balance: 5000, apr: 21.99, min_payment: 125 }), { orgId: 'o' }),
|
|
127
|
+
toLiability({ ...row(), id: 'l2', external_id: 'liability:l2', name: 'Car', data: { title: 'Car', subtype: 'auto_loan', balance: 8000, apr: 5, min_payment: 200 } }, { orgId: 'o' }),
|
|
128
|
+
];
|
|
129
|
+
|
|
130
|
+
it('runs the shared engine over the eligible liabilities', () => {
|
|
131
|
+
const r = runPayoffScenario(ls, { strategy: 'avalanche', monthlyPayment: 600, startDate: '2026-12-01' });
|
|
132
|
+
expect(r.debts.map((d) => d.id)).toEqual(['l1', 'l2']);
|
|
133
|
+
expect(r.schedule.paidOff).toBe(true);
|
|
134
|
+
expect(r.schedule.strategy).toBe('avalanche');
|
|
135
|
+
expect(r.labels).toEqual([{ id: 'l1', name: 'Visa' }, { id: 'l2', name: 'Car' }]);
|
|
136
|
+
expect(r.startingBalance).toBe(13000);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('avalanche costs no more interest than snowball here', () => {
|
|
140
|
+
const a = runPayoffScenario(ls, { strategy: 'avalanche', monthlyPayment: 600 });
|
|
141
|
+
const s = runPayoffScenario(ls, { strategy: 'snowball', monthlyPayment: 600 });
|
|
142
|
+
expect(a.schedule.totalInterest).toBeLessThanOrEqual(s.schedule.totalInterest);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('defaults the budget to the sum of minimums when none is given', () => {
|
|
146
|
+
const r = runPayoffScenario(ls, { strategy: 'avalanche' });
|
|
147
|
+
expect(r.monthlyPayment).toBe(325);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('answers an empty plan without throwing when nothing is eligible', () => {
|
|
151
|
+
const r = runPayoffScenario([], { strategy: 'avalanche', monthlyPayment: 100 });
|
|
152
|
+
expect(r.debts).toEqual([]);
|
|
153
|
+
expect(r.schedule.months).toEqual([]);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('the liability client', () => {
|
|
158
|
+
function tenant() {
|
|
159
|
+
const gets: Array<{ path: string; params: Record<string, unknown> }> = [];
|
|
160
|
+
const posts: Array<{ path: string; body: unknown }> = [];
|
|
161
|
+
const http = {
|
|
162
|
+
get: vi.fn(async (path: string, o?: { params?: Record<string, unknown> }) => {
|
|
163
|
+
gets.push({ path, params: o?.params ?? {} });
|
|
164
|
+
return { count: 1, next: null, previous: null, results: [row()] };
|
|
165
|
+
}),
|
|
166
|
+
post: vi.fn(async (path: string, body: unknown) => {
|
|
167
|
+
posts.push({ path, body });
|
|
168
|
+
return { ...row(), data: (body as { data: object }).data };
|
|
169
|
+
}),
|
|
170
|
+
};
|
|
171
|
+
return { gets, posts, api: createLiabilityApi({ http: http as never, scope: SCOPE }) };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
it('lists liabilities server-side, active first by default, one page at a time', async () => {
|
|
175
|
+
const { api, gets } = tenant();
|
|
176
|
+
const page = await api.listLiabilities({ pageSize: 50 });
|
|
177
|
+
expect(page.results[0].title).toBe('Visa');
|
|
178
|
+
expect(gets[0].params).toMatchObject({ type: 'liability', page: 1, page_size: 50 });
|
|
179
|
+
expect(gets[0].params['attr.status']).toBeUndefined();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('filters by status and subtype only when asked', async () => {
|
|
183
|
+
const { api, gets } = tenant();
|
|
184
|
+
await api.listLiabilities({ status: 'active', subtype: 'credit_card' });
|
|
185
|
+
expect(gets[0].params).toMatchObject({ 'attr.status': 'active', 'attr.subtype': 'credit_card' });
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('creates through the shallow-merging upsert', async () => {
|
|
189
|
+
const { api, posts } = tenant();
|
|
190
|
+
const made = await api.createLiability({ title: 'Visa', subtype: 'credit_card', balance: 5000 });
|
|
191
|
+
expect(posts[0].path).toBe('api/v1/entities/upsert');
|
|
192
|
+
expect(made.title).toBe('Visa');
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('updates only the keys it was given, so an edit cannot resurrect a closed debt', async () => {
|
|
196
|
+
const { api, posts } = tenant();
|
|
197
|
+
const l = toLiability(row({ status: 'closed' }), { orgId: 'o' });
|
|
198
|
+
await api.updateLiability(l, { balance: 4000 });
|
|
199
|
+
const body = posts[0].body as { data: Record<string, unknown>; external_id: string };
|
|
200
|
+
expect(body.external_id).toBe('liability:l1');
|
|
201
|
+
expect(body.data).toEqual({ title: 'Visa', balance: 4000 });
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe('listing focuses on a tenant that never declared a subtype', () => {
|
|
206
|
+
it('sends no attr.subtype unless the caller asks, so a live tenant cannot 400', async () => {
|
|
207
|
+
const gets: Array<Record<string, unknown>> = [];
|
|
208
|
+
const http = { get: vi.fn(async (_p: string, o?: { params?: Record<string, unknown> }) => { gets.push(o?.params ?? {}); return { count: 0, results: [] }; }) };
|
|
209
|
+
const api = createPlanningApi({ http: http as never, scope: SCOPE });
|
|
210
|
+
await api.listFocuses({});
|
|
211
|
+
expect(Object.keys(gets[0])).not.toContain('attr.subtype');
|
|
212
|
+
await api.listFocuses({ subtype: 'payoff_scenario' });
|
|
213
|
+
expect(gets[1]['attr.subtype']).toBe('payoff_scenario');
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('patches subtype and params through updateFocus', async () => {
|
|
217
|
+
const posts: Array<{ data: Record<string, unknown> }> = [];
|
|
218
|
+
const http = { get: vi.fn(), post: vi.fn(async (_p: string, b: { data: Record<string, unknown> }) => { posts.push(b); return { id: 'f', entity_type: 'focus', external_id: 'focus:s', name: 's', data: b.data }; }) };
|
|
219
|
+
const api = createPlanningApi({ http: http as never, scope: SCOPE });
|
|
220
|
+
const focus = toFocus({ id: 'f', entity_type: 'focus', external_id: 'focus:s', name: 's', data: { title: 's' } } as never, { orgId: 'o' });
|
|
221
|
+
await api.updateFocus!(focus, { params: { strategy: 'snowball', monthly_payment: 400 } });
|
|
222
|
+
expect(posts[0].data.params).toEqual({ strategy: 'snowball', monthly_payment: 400 });
|
|
223
|
+
});
|
|
224
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** The Debt plan composer: lists liabilities, runs the scenario, saves it as a focus (bd startsim-a01ps.8). */
|
|
2
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import { LiabilityPlanPage } from '../components/pages/LiabilityPlanPage';
|
|
6
|
+
import { toLiability } from '../corpus/liabilities';
|
|
7
|
+
|
|
8
|
+
const mk = (id: string, title: string, balance: number, apr: number, min: number) => toLiability(
|
|
9
|
+
{ id, entity_type: 'liability', external_id: `liability:${id}`, name: title, data: { title, subtype: 'credit_card', status: 'active', balance, apr, min_payment: min } } as never,
|
|
10
|
+
{ orgId: 'o' },
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
function setup() {
|
|
14
|
+
const createFocus = vi.fn(async (d: { title: string }) => ({ id: 'f', title: d.title }) as never);
|
|
15
|
+
const api = {
|
|
16
|
+
listLiabilities: vi.fn(async () => ({ count: 2, next: null, previous: null, results: [mk('a', 'Visa', 5000, 22, 125), mk('b', 'Auto', 8000, 5, 200)] })),
|
|
17
|
+
listFocuses: vi.fn(async () => ({ count: 0, next: null, previous: null, results: [] })),
|
|
18
|
+
createFocus,
|
|
19
|
+
};
|
|
20
|
+
render(<LiabilityPlanPage api={api as never} now={Date.parse('2026-11-07T00:00:00Z')} />);
|
|
21
|
+
return { api, createFocus };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
describe('LiabilityPlanPage', () => {
|
|
25
|
+
it('shows what is owed and a debt-free summary', async () => {
|
|
26
|
+
setup();
|
|
27
|
+
expect(await screen.findByText('2 liabilities · $13,000 owed')).toBeTruthy();
|
|
28
|
+
expect(screen.getAllByTestId('liability-row')).toHaveLength(2);
|
|
29
|
+
expect(screen.getByTestId('payoff-summary')).toBeTruthy();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('asks for scenario focuses only by subtype', async () => {
|
|
33
|
+
const { api } = setup();
|
|
34
|
+
await screen.findByTestId('liability-plan');
|
|
35
|
+
expect(api.listFocuses).toHaveBeenCalledWith({ subtype: 'payoff_scenario', pageSize: 50 });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('saves a scenario only on click', async () => {
|
|
39
|
+
const { createFocus } = setup();
|
|
40
|
+
await screen.findByTestId('save-scenario');
|
|
41
|
+
expect(createFocus).not.toHaveBeenCalled();
|
|
42
|
+
await userEvent.click(screen.getByTestId('save-scenario'));
|
|
43
|
+
await waitFor(() => expect(createFocus).toHaveBeenCalledTimes(1));
|
|
44
|
+
expect(createFocus.mock.calls[0][0]).toMatchObject({ subtype: 'payoff_scenario', params: { strategy: 'avalanche' } });
|
|
45
|
+
});
|
|
46
|
+
});
|