@startsimpli/integrations 0.2.149 → 0.2.151
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 +3 -3
- 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__/helpers/question-tenant.ts +45 -0
- package/src/__tests__/question-checkin.test.ts +139 -0
- package/src/__tests__/question-voice-parse.test.ts +110 -0
- package/src/__tests__/question-voice.test.ts +208 -0
- package/src/__tests__/stated-date-extract.test.ts +119 -0
- package/src/__tests__/stated-date.test.ts +107 -0
- package/src/__tests__/tracker-done-stamp.test.ts +42 -0
- package/src/__tests__/tracker-timeline-component.test.tsx +81 -0
- package/src/__tests__/tracker-timeline-reader.test.ts +94 -0
- package/src/__tests__/tracker-timeline.test.ts +209 -0
- package/src/components/index.ts +1 -0
- package/src/components/pages/PlanningPage.tsx +16 -2
- package/src/components/pages/TrackerPage.tsx +8 -0
- 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/tracker/TrackerTimeline.tsx +123 -0
- package/src/components/pages/types.ts +2 -2
- package/src/corpus/client.ts +27 -1
- 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 +6 -0
- package/src/corpus/questions/checkin-handle.ts +67 -0
- package/src/corpus/questions/checkin.ts +103 -0
- package/src/corpus/questions/index.ts +9 -0
- package/src/corpus/questions/respond.ts +76 -0
- package/src/corpus/questions/store.ts +5 -1
- package/src/corpus/questions/sync.ts +1 -0
- package/src/corpus/questions/types.ts +10 -2
- package/src/corpus/questions/voice-parse.ts +98 -0
- package/src/corpus/questions/voice.ts +225 -0
- package/src/corpus/spoken-time.ts +4 -4
- package/src/corpus/stated-date.ts +187 -0
- package/src/corpus/tracker-timeline-client.ts +117 -0
- package/src/corpus/tracker-timeline.ts +228 -0
- package/src/corpus/types.ts +25 -1
- package/src/corpus/work-item-logic.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/integrations",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.151",
|
|
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",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"react-native-safe-area-context": ">=4.0.0",
|
|
53
53
|
"@startsimpli/auth": "^0.4.50",
|
|
54
54
|
"@startsimpli/utils": "^0.4.18",
|
|
55
|
-
"@startsimpli/ui": "^0.4.
|
|
55
|
+
"@startsimpli/ui": "^0.4.173"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"react": {
|
|
@@ -99,7 +99,7 @@
|
|
|
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.173",
|
|
103
103
|
"@startsimpli/ui-native": "0.1.14",
|
|
104
104
|
"@startsimpli/auth": "0.4.50",
|
|
105
105
|
"@startsimpli/utils": "0.4.18"
|
|
@@ -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,45 @@
|
|
|
1
|
+
import { expect } from 'vitest';
|
|
2
|
+
import type { CorpusHttp } from '../../corpus/client';
|
|
3
|
+
|
|
4
|
+
export interface Row { id: string; entity_type: string; external_id: string; name: string; data: Record<string, unknown>; version: number }
|
|
5
|
+
|
|
6
|
+
/** A tenant in memory: list/get, shallow-merging upsert, and the PATCH door. */
|
|
7
|
+
export function tenant(seed: Array<Omit<Row, 'version'>> = []) {
|
|
8
|
+
const rows = new Map<string, Row>(seed.map((r) => [r.id, { ...r, version: 1 }]));
|
|
9
|
+
let next = 1000;
|
|
10
|
+
const http: CorpusHttp & { post: NonNullable<CorpusHttp['post']>; patch: NonNullable<CorpusHttp['patch']> } = {
|
|
11
|
+
async get(path, options) {
|
|
12
|
+
const clean = path.replace(/\/+$/, '');
|
|
13
|
+
if (clean === 'api/v1/entities') {
|
|
14
|
+
const type = String(options?.params?.type ?? '');
|
|
15
|
+
const all = [...rows.values()].filter((r) => r.entity_type === type);
|
|
16
|
+
return { results: all, next: null } as never;
|
|
17
|
+
}
|
|
18
|
+
const row = rows.get(decodeURIComponent(clean.split('/').pop() as string));
|
|
19
|
+
if (!row) throw Object.assign(new Error('nf'), { status: 404 });
|
|
20
|
+
return structuredClone(row) as never;
|
|
21
|
+
},
|
|
22
|
+
async post(path, body) {
|
|
23
|
+
const b = body as { entity_type: string; external_id: string; name?: string; data: Record<string, unknown> };
|
|
24
|
+
expect(path).toContain('upsert');
|
|
25
|
+
const hit = [...rows.values()].find((r) => r.entity_type === b.entity_type && r.external_id === b.external_id);
|
|
26
|
+
if (hit) {
|
|
27
|
+
hit.data = { ...hit.data, ...b.data };
|
|
28
|
+
if (b.name) hit.name = b.name;
|
|
29
|
+
hit.version += 1;
|
|
30
|
+
return structuredClone(hit) as never;
|
|
31
|
+
}
|
|
32
|
+
const row: Row = { id: `e${next++}`, entity_type: b.entity_type, external_id: b.external_id, name: b.name ?? '', data: { ...b.data }, version: 1 };
|
|
33
|
+
rows.set(row.id, row);
|
|
34
|
+
return structuredClone(row) as never;
|
|
35
|
+
},
|
|
36
|
+
async patch(path, body) {
|
|
37
|
+
const row = rows.get(decodeURIComponent(path.replace(/\/+$/, '').split('/').pop() as string)) as Row;
|
|
38
|
+
row.data = (body as { data: Record<string, unknown> }).data;
|
|
39
|
+
row.version += 1;
|
|
40
|
+
return structuredClone(row) as never;
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
return { rows, http };
|
|
44
|
+
}
|
|
45
|
+
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The check-in: "there are N things I am unsure about" (bd startsim-tmrvi.4). Grouped, most important first,
|
|
3
|
+
* each with the guess Tandem is acting on, in words fit to be read aloud.
|
|
4
|
+
*/
|
|
5
|
+
import { describe, expect, it } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { composeCheckIn } from '../corpus/questions/checkin';
|
|
8
|
+
import type { OpenQuestion } from '../corpus/questions';
|
|
9
|
+
|
|
10
|
+
const NOW = Date.parse('2026-11-04T15:00:00Z');
|
|
11
|
+
const TZ = 'America/New_York';
|
|
12
|
+
const q = (id: string, itemId: string, over: Partial<OpenQuestion>): OpenQuestion => ({
|
|
13
|
+
id, itemId, kind: 'due_date', question: 'When is this due?', status: 'open', candidates: [], score: 70, ownerSub: 'me', createdAt: '', updatedAt: '', ...over,
|
|
14
|
+
});
|
|
15
|
+
const titles = new Map([['a', 'Call the vet'], ['b', "Order dad's bench"], ['c', 'Pay LIN-123 invoice'], ['d', 'Plan offsite'], ['e', 'Email Sam'], ['f', 'Renew passport']]);
|
|
16
|
+
const make = (qs: OpenQuestion[], over = {}) => composeCheckIn(qs, { titles, now: NOW, timeZone: TZ, ...over });
|
|
17
|
+
|
|
18
|
+
describe('composeCheckIn', () => {
|
|
19
|
+
it('says nothing when nothing is open', () => {
|
|
20
|
+
const out = make([]);
|
|
21
|
+
expect(out.empty).toBe(true);
|
|
22
|
+
expect(out.text).toBe('');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('counts the doubts and reads the best first, with its guess', () => {
|
|
26
|
+
const out = make([
|
|
27
|
+
q('1', 'b', { kind: 'team', question: 'Which team is this for?', score: 100 }),
|
|
28
|
+
q('2', 'a', { assumed: { value: '2026-11-06', confidence: 0.5, reason: 'said Friday on a Friday' }, score: 80 }),
|
|
29
|
+
]);
|
|
30
|
+
expect(out.total).toBe(2);
|
|
31
|
+
expect(out.text).toMatch(/^I am not sure about two things\./);
|
|
32
|
+
expect(out.text.indexOf("Order dad's bench")).toBeLessThan(out.text.indexOf('Call the vet'));
|
|
33
|
+
expect(out.text).toMatch(/Friday the sixth/);
|
|
34
|
+
expect(out.entries[1].guess).toBe('Friday the sixth');
|
|
35
|
+
expect(out.entries[0].guess).toBeNull();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('offers how to answer once, not per item', () => {
|
|
39
|
+
const out = make([q('1', 'a', {}), q('2', 'b', {})]);
|
|
40
|
+
expect(out.text.match(/say yes to keep/gi)?.length).toBe(1);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('never reads ticket codes, markup or numeric dates aloud', () => {
|
|
44
|
+
const out = make([q('1', 'c', { assumed: { value: '2026-11-06', confidence: 0.5, reason: 'r' } })]);
|
|
45
|
+
expect(out.text).not.toMatch(/LIN-123|2026-11|\d{4}/);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('speaks a project guess by its name', () => {
|
|
49
|
+
const out = make([q('1', 'a', { kind: 'project', question: 'Which project?', assumed: { value: 'f1', display: 'Marketing', confidence: 0.4, reason: 'r' } })]);
|
|
50
|
+
expect(out.text).toMatch(/Marketing/);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('keeps it short: five items, then how many more', () => {
|
|
54
|
+
const many = ['a', 'b', 'c', 'd', 'e', 'f'].map((id, n) => q(String(n), id, { score: 70 - n }));
|
|
55
|
+
const out = make(many);
|
|
56
|
+
expect(out.entries).toHaveLength(5);
|
|
57
|
+
expect(out.remaining).toBe(1);
|
|
58
|
+
expect(out.text).toMatch(/one more/);
|
|
59
|
+
expect(out.text).toMatch(/six things/);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('segments point at the question each stretch is about, so a reply can be resolved by position', () => {
|
|
63
|
+
const out = make([q('1', 'a', {}), q('2', 'b', {})]);
|
|
64
|
+
const ids = out.segments.filter((s) => s.id).map((s) => s.id);
|
|
65
|
+
expect(ids).toEqual(['1', '2']);
|
|
66
|
+
for (const s of out.segments) expect(out.text.slice(s.start, s.end).length).toBeGreaterThan(0);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('says one thing in the singular', () => {
|
|
70
|
+
expect(make([q('1', 'a', {})]).text).toMatch(/^I am not sure about one thing\./);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
import { vi } from 'vitest';
|
|
75
|
+
import { buildCheckIn } from '../corpus/questions/checkin-handle';
|
|
76
|
+
import { syncOpenQuestions } from '../corpus/questions';
|
|
77
|
+
import { createMemoryActionLog } from '../corpus/briefing/actions/log';
|
|
78
|
+
import { commitmentEditSeam } from '../corpus/briefing/actions/seam';
|
|
79
|
+
import { createPlanningApi } from '../corpus/client';
|
|
80
|
+
import { tenant } from './helpers/question-tenant';
|
|
81
|
+
|
|
82
|
+
describe('buildCheckIn', () => {
|
|
83
|
+
const SCOPE = { orgId: 'o' } as never;
|
|
84
|
+
const held = (id: string, title: string) => ({
|
|
85
|
+
id, entity_type: 'commitment', external_id: `commit:${id}`, name: title,
|
|
86
|
+
data: { title, status: 'open', open_question_kind: 'team', open_question: 'Which team is this for?', sync_state: 'needs_team' },
|
|
87
|
+
});
|
|
88
|
+
function setup(synth = true) {
|
|
89
|
+
const t = tenant([held('x', "Order dad's bench"), held('y', 'Call the vet')]);
|
|
90
|
+
const api = createPlanningApi({ http: t.http, scope: SCOPE, supportedFilters: [], resolveParticipants: false } as never);
|
|
91
|
+
const synthesize = vi.fn(async () => ({ audio: new Uint8Array([1]), mimeType: 'audio/mpeg', model: 'm', provider: 'p', usage: {} }));
|
|
92
|
+
const put = vi.fn(async () => 'ref-1');
|
|
93
|
+
const deps = {
|
|
94
|
+
http: t.http, scope: SCOPE, ownerSub: 'me', now: () => NOW, timeZone: TZ,
|
|
95
|
+
seam: commitmentEditSeam({ api, http: t.http, scope: SCOPE }),
|
|
96
|
+
patchItem: vi.fn(), options: async () => [], log: createMemoryActionLog(),
|
|
97
|
+
...(synth ? { synthesize, audio: { put }, audioPath: (id: string) => `/a/${id}` } : {}),
|
|
98
|
+
};
|
|
99
|
+
return { deps, synthesize };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
it('reads the queue with the item titles and offers the first question to answer', async () => {
|
|
103
|
+
const { deps } = setup(false);
|
|
104
|
+
const out = await buildCheckIn(deps);
|
|
105
|
+
expect(out.total).toBe(2);
|
|
106
|
+
expect(out.text).toMatch(/Order dad's bench|Call the vet/);
|
|
107
|
+
expect(out.firstQuestionId).toBe(out.entries[0].questionId);
|
|
108
|
+
expect(out.audioUrl).toBeNull();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('speaks it once: asking again for the same words does not synthesize again', async () => {
|
|
112
|
+
const { deps, synthesize } = setup(true);
|
|
113
|
+
const a = await buildCheckIn(deps);
|
|
114
|
+
const b = await buildCheckIn(deps);
|
|
115
|
+
expect(a.audioUrl).toMatch(/^\/a\/checkin-/);
|
|
116
|
+
expect(b.audioUrl).toBe(a.audioUrl);
|
|
117
|
+
expect(synthesize).toHaveBeenCalledTimes(1);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('is empty and silent when nothing is open', async () => {
|
|
121
|
+
const t = tenant([]);
|
|
122
|
+
const api = createPlanningApi({ http: t.http, scope: SCOPE, supportedFilters: [], resolveParticipants: false } as never);
|
|
123
|
+
const out = await buildCheckIn({
|
|
124
|
+
http: t.http, scope: SCOPE, ownerSub: 'me', now: () => NOW, seam: commitmentEditSeam({ api, http: t.http, scope: SCOPE }),
|
|
125
|
+
patchItem: vi.fn(), options: async () => [], log: createMemoryActionLog(),
|
|
126
|
+
} as never);
|
|
127
|
+
expect(out).toMatchObject({ empty: true, audioUrl: null, firstQuestionId: null });
|
|
128
|
+
void syncOpenQuestions;
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe('a guess stored as an id', () => {
|
|
133
|
+
it('is said by name when the name is known, and not at all when it is not', () => {
|
|
134
|
+
const unnamed = make([q('1', 'a', { kind: 'project', question: 'Which project?', assumed: { value: '854c5d84-d879', confidence: 0.4, reason: 'r' } })]);
|
|
135
|
+
expect(unnamed.text).not.toMatch(/854c/);
|
|
136
|
+
expect(unnamed.entries[0].guess).toBeNull();
|
|
137
|
+
expect(unnamed.text).toMatch(/which project/i);
|
|
138
|
+
});
|
|
139
|
+
});
|