@startsimpli/integrations 0.2.72 → 0.2.74
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/README.md +2 -0
- package/package.json +3 -3
- package/src/__tests__/view-text.test.ts +31 -0
- package/src/components/Markdown.tsx +1 -15
- package/src/components/pages/AskPage.tsx +12 -59
- package/src/components/pages/LibraryPage.tsx +1 -45
- package/src/corpus/client.ts +8 -4
- package/src/corpus/entities.ts +1 -0
- package/src/corpus/types.ts +4 -0
- package/src/corpus/view-text.ts +113 -0
- package/src/native/components/NotesShell.tsx +9 -4
- package/src/native/corpus/fake-tenant.ts +6 -0
- package/src/native/home/HomeScreen.tsx +2 -2
- package/src/native/index.ts +9 -0
- package/src/native/screens/__tests__/ask-controller.test.ts +135 -0
- package/src/native/screens/__tests__/ask-screen.test.tsx +96 -0
- package/src/native/screens/__tests__/library-controller.test.ts +185 -0
- package/src/native/screens/__tests__/library-screens.test.tsx +134 -0
- package/src/native/screens/__tests__/tabs.test.tsx +46 -0
- package/src/native/screens/ask/AskScreen.tsx +118 -0
- package/src/native/screens/ask/answer-view.ts +53 -0
- package/src/native/screens/ask/controller.ts +100 -0
- package/src/native/screens/library/LibraryDetailScreen.tsx +93 -0
- package/src/native/screens/library/LibraryListScreen.tsx +99 -0
- package/src/native/screens/library/controller.ts +196 -0
- package/src/native/screens/library/fake-library.ts +38 -0
- package/src/native/screens/store.ts +19 -0
- package/src/native/screens/tabs.tsx +41 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import type { AskRequest, AskResult, CorpusAskApi } from '../../../corpus/types';
|
|
3
|
+
import { answerView } from '../ask/answer-view';
|
|
4
|
+
import { createAskController } from '../ask/controller';
|
|
5
|
+
import { createFakeLibraryApi } from '../library/fake-library';
|
|
6
|
+
|
|
7
|
+
const scope = { orgId: 'tandem' };
|
|
8
|
+
const provider = { provider: 'fixture', model: 'fixture-echo', live: false };
|
|
9
|
+
const result = (over: Partial<AskResult> = {}): AskResult => ({
|
|
10
|
+
status: 'answered', answer: 'Acme renews at **$4,800**.', citations: [], considered: [],
|
|
11
|
+
unresolvedCitations: [], droppedOutOfScope: 0, provider, ...over,
|
|
12
|
+
} as AskResult);
|
|
13
|
+
|
|
14
|
+
function scripted(replies: Array<AskResult | Error>) {
|
|
15
|
+
const seen: AskRequest[] = [];
|
|
16
|
+
const api: CorpusAskApi = {
|
|
17
|
+
async ask(request) {
|
|
18
|
+
seen.push(request);
|
|
19
|
+
const next = replies.shift()!;
|
|
20
|
+
if (next instanceof Error) throw next;
|
|
21
|
+
return next;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
return { api, seen };
|
|
25
|
+
}
|
|
26
|
+
const listProjects = async () => [{ id: 'fma', title: 'Marketing agents' }, { id: 'f287', title: '287A' }];
|
|
27
|
+
|
|
28
|
+
describe('ask controller', () => {
|
|
29
|
+
it('sends the question in ask mode with the tenant scope, and shows the answer', async () => {
|
|
30
|
+
const { api, seen } = scripted([result()]);
|
|
31
|
+
const ask = createAskController({ api, scope });
|
|
32
|
+
await ask.send(' What did Acme agree? ');
|
|
33
|
+
expect(seen).toEqual([{ question: 'What did Acme agree?', mode: 'ask', scope }]);
|
|
34
|
+
const [user, assistant] = ask.getState().messages;
|
|
35
|
+
expect(user).toMatchObject({ role: 'user', text: 'What did Acme agree?' });
|
|
36
|
+
expect(assistant).toMatchObject({ role: 'assistant', status: 'done', text: 'Acme renews at **$4,800**.' });
|
|
37
|
+
expect(ask.getState().busy).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('scopes to a project server-side via filters.focus, and back to all projects', async () => {
|
|
41
|
+
const { api, seen } = scripted([result(), result()]);
|
|
42
|
+
const ask = createAskController({ api, scope, listProjects });
|
|
43
|
+
await ask.start();
|
|
44
|
+
expect(ask.getState().projects).toEqual([{ id: 'fma', title: 'Marketing agents' }, { id: 'f287', title: '287A' }]);
|
|
45
|
+
ask.setProject('fma');
|
|
46
|
+
await ask.send('status?');
|
|
47
|
+
expect(seen[0].filters).toEqual({ focus: 'fma' });
|
|
48
|
+
ask.setProject(null);
|
|
49
|
+
await ask.send('and overall?');
|
|
50
|
+
expect(seen[1].filters).toBeUndefined();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('ignores an empty question and a second send while one is in flight', async () => {
|
|
54
|
+
let release!: (r: AskResult) => void;
|
|
55
|
+
const calls: string[] = [];
|
|
56
|
+
const api: CorpusAskApi = { ask: (r) => { calls.push(r.question); return new Promise((res) => { release = res; }); } };
|
|
57
|
+
const ask = createAskController({ api, scope });
|
|
58
|
+
await ask.send(' ');
|
|
59
|
+
expect(calls).toEqual([]);
|
|
60
|
+
const first = ask.send('one');
|
|
61
|
+
expect(ask.getState().busy).toBe(true);
|
|
62
|
+
expect(ask.getState().messages.at(-1)).toMatchObject({ role: 'assistant', status: 'pending' });
|
|
63
|
+
await ask.send('two');
|
|
64
|
+
expect(calls).toEqual(['one']);
|
|
65
|
+
release(result());
|
|
66
|
+
await first;
|
|
67
|
+
expect(ask.getState().busy).toBe(false);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('a failed ask is an error on that answer, with a reason, and retry asks it again', async () => {
|
|
71
|
+
const { api, seen } = scripted([Object.assign(new Error('x'), { status: 403 }), result({ answer: 'Second time.' })]);
|
|
72
|
+
const ask = createAskController({ api, scope });
|
|
73
|
+
await ask.send('who?');
|
|
74
|
+
const failed = ask.getState().messages[1];
|
|
75
|
+
expect(failed).toMatchObject({ status: 'error', error: 'You do not have access to this workspace’s records.' });
|
|
76
|
+
await ask.retry(failed.id);
|
|
77
|
+
expect(seen.map((r) => r.question)).toEqual(['who?', 'who?']);
|
|
78
|
+
const messages = ask.getState().messages;
|
|
79
|
+
expect(messages).toHaveLength(2);
|
|
80
|
+
expect(messages[1]).toMatchObject({ status: 'done', text: 'Second time.' });
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('retry uses the project the question was asked under', async () => {
|
|
84
|
+
const { api, seen } = scripted([new Error('boom'), result()]);
|
|
85
|
+
const ask = createAskController({ api, scope, listProjects });
|
|
86
|
+
ask.setProject('fma');
|
|
87
|
+
await ask.send('q');
|
|
88
|
+
ask.setProject(null);
|
|
89
|
+
await ask.retry(ask.getState().messages[1].id);
|
|
90
|
+
expect(seen[1].filters).toEqual({ focus: 'fma' });
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('works end to end over the fake tenant: the answer cites the documents it used', async () => {
|
|
94
|
+
const fake = createFakeLibraryApi();
|
|
95
|
+
const ask = createAskController({ api: fake.ask, scope: fake.scope, listProjects: async () => (await fake.corpus.listFocusChoices!()) });
|
|
96
|
+
await ask.start();
|
|
97
|
+
ask.setProject('fma');
|
|
98
|
+
await ask.send('pricing Acme');
|
|
99
|
+
const view = ask.getState().messages[1].view!;
|
|
100
|
+
expect(view.citations.map((c) => c.title)).toEqual(['Pricing call with Acme']);
|
|
101
|
+
expect(view.citations[0].documentId).toBe('d4');
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('answerView: what an answer owes its reader', () => {
|
|
106
|
+
const doc = (id: string, title: string) => ({ id, title, source: 'granola', sourceLabel: 'Granola', occurredAt: '2026-10-20T13:00:00Z' });
|
|
107
|
+
it('lists citations with source, title, date and the model\'s quote flattened', () => {
|
|
108
|
+
const v = answerView(result({ citations: [{ documentId: 'd4', document: doc('d4', 'Pricing call') as never, quote: '**Acme** renews' }] }));
|
|
109
|
+
expect(v.citations).toEqual([{ documentId: 'd4', title: 'Pricing call', sourceLabel: 'Granola', dateLabel: expect.stringContaining('2026'), quote: 'Acme renews' }]);
|
|
110
|
+
expect(v.provider).toBe('Answered by a fixture stub (fixture-echo) — no live model was called');
|
|
111
|
+
});
|
|
112
|
+
it('an uncited answer is shown as unsourced, first', () => {
|
|
113
|
+
const v = answerView(result({ status: 'uncited', unresolvedCitations: ['zz'] }));
|
|
114
|
+
expect(v.notices[0]).toMatchObject({ tone: 'warning', text: expect.stringContaining('could not be traced') });
|
|
115
|
+
expect(v.notices.some((n) => n.text.includes('(zz)'))).toBe(true);
|
|
116
|
+
});
|
|
117
|
+
it('no evidence is its own outcome, not an error', () => {
|
|
118
|
+
const v = answerView(result({ status: 'no_evidence', answer: 'Nothing in your records.' }));
|
|
119
|
+
expect(v).toMatchObject({ status: 'no_evidence', text: 'Nothing in your records.', citations: [] });
|
|
120
|
+
});
|
|
121
|
+
it('states stale sources, withheld fields and out-of-scope drops', () => {
|
|
122
|
+
const v = answerView(result({
|
|
123
|
+
freshness: [{ source: 'granola', label: 'Granola', status: 'stale' } as never],
|
|
124
|
+
withheldFields: ['transcript'], droppedOutOfScope: 2,
|
|
125
|
+
}));
|
|
126
|
+
const text = v.notices.map((n) => n.text).join('|');
|
|
127
|
+
expect(text).toContain('Granola (stale)');
|
|
128
|
+
expect(text).toContain('transcript');
|
|
129
|
+
expect(text).toContain('2 records from another workspace');
|
|
130
|
+
});
|
|
131
|
+
it('counts what was searched but not cited', () => {
|
|
132
|
+
const considered = [{ document: doc('d9', 'Unused') as never, matchedTerms: ['acme'] }];
|
|
133
|
+
expect(answerView(result({ considered: considered as never })).uncited).toEqual([{ documentId: 'd9', title: 'Unused', sourceLabel: 'Granola' }]);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { act, allText, hostById, maybeById, press, render } from '../../../../../ui-native/test/render';
|
|
3
|
+
import type { CorpusAskApi } from '../../../corpus/types';
|
|
4
|
+
import { AskScreen } from '../ask/AskScreen';
|
|
5
|
+
import { createAskController } from '../ask/controller';
|
|
6
|
+
import { createFakeLibraryApi } from '../library/fake-library';
|
|
7
|
+
|
|
8
|
+
const tick = () => act(async () => { await new Promise((res) => setTimeout(res, 0)); });
|
|
9
|
+
|
|
10
|
+
async function mount(opts: { api?: CorpusAskApi; onOpenDocument?: (id: string) => void } = {}) {
|
|
11
|
+
const fake = createFakeLibraryApi();
|
|
12
|
+
const controller = createAskController({
|
|
13
|
+
api: opts.api ?? fake.ask, scope: fake.scope,
|
|
14
|
+
listProjects: async () => fake.corpus.listFocusChoices!(),
|
|
15
|
+
});
|
|
16
|
+
const onOpenDocument = opts.onOpenDocument ?? vi.fn();
|
|
17
|
+
const r = render(<AskScreen controller={controller} onOpenDocument={onOpenDocument} />);
|
|
18
|
+
await act(async () => { await controller.start(); });
|
|
19
|
+
return { r, controller, onOpenDocument };
|
|
20
|
+
}
|
|
21
|
+
const type = (r: ReturnType<typeof render>, text: string) => act(() => { hostById(r, 'ask-composer-input').props.onChangeText(text); });
|
|
22
|
+
const send = async (r: ReturnType<typeof render>) => { press(hostById(r, 'ask-composer-send')); await tick(); await tick(); };
|
|
23
|
+
|
|
24
|
+
describe('AskScreen', () => {
|
|
25
|
+
it('starts with an empty state that says what Ask is for', async () => {
|
|
26
|
+
const { r } = await mount();
|
|
27
|
+
expect(allText(r)).toContain('Ask your documents');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('asks, shows the question and a Markdown answer with its sources', async () => {
|
|
31
|
+
const { r } = await mount();
|
|
32
|
+
type(r, 'pricing Acme');
|
|
33
|
+
await send(r);
|
|
34
|
+
const text = allText(r);
|
|
35
|
+
expect(text).toContain('pricing Acme');
|
|
36
|
+
expect(text).toContain('1 source');
|
|
37
|
+
expect(text).toContain('Pricing call with Acme');
|
|
38
|
+
expect(text).toContain('Granola');
|
|
39
|
+
expect(text).toContain('no live model was called');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('tapping a citation opens that document', async () => {
|
|
43
|
+
const { r, onOpenDocument } = await mount();
|
|
44
|
+
type(r, 'pricing Acme');
|
|
45
|
+
await send(r);
|
|
46
|
+
press(hostById(r, 'ask-citation-d4'));
|
|
47
|
+
expect(onOpenDocument).toHaveBeenCalledWith('d4');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('a project chosen in the picker scopes the question server-side', async () => {
|
|
51
|
+
const seen: unknown[] = [];
|
|
52
|
+
const fake = createFakeLibraryApi();
|
|
53
|
+
const { r } = await mount({ api: { ask: (req) => { seen.push(req.filters); return fake.ask.ask(req); } } });
|
|
54
|
+
press(hostById(r, 'ask-project'));
|
|
55
|
+
press(hostById(r, 'ask-project-option-fma'));
|
|
56
|
+
type(r, 'pricing Acme');
|
|
57
|
+
await send(r);
|
|
58
|
+
expect(seen).toEqual([{ focus: 'fma' }]);
|
|
59
|
+
expect(allText(r)).toContain('Marketing agents');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('shows a loading bubble while the answer is coming', async () => {
|
|
63
|
+
let release!: () => void;
|
|
64
|
+
const fake = createFakeLibraryApi();
|
|
65
|
+
const { r } = await mount({ api: { ask: (req) => new Promise((res) => { release = () => res(fake.ask.ask(req) as never); }) } });
|
|
66
|
+
type(r, 'pricing Acme');
|
|
67
|
+
press(hostById(r, 'ask-composer-send'));
|
|
68
|
+
await tick();
|
|
69
|
+
expect(maybeById(r, 'ask-pending').length).toBeGreaterThan(0);
|
|
70
|
+
await act(async () => { release(); await new Promise((res) => setTimeout(res, 0)); });
|
|
71
|
+
expect(maybeById(r, 'ask-pending')).toHaveLength(0);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('a failure says why and Retry asks again', async () => {
|
|
75
|
+
const fake = createFakeLibraryApi();
|
|
76
|
+
let fail = true;
|
|
77
|
+
const { r } = await mount({ api: { ask: async (req) => { if (fail) throw Object.assign(new Error('x'), { status: 401 }); return fake.ask.ask(req); } } });
|
|
78
|
+
type(r, 'pricing Acme');
|
|
79
|
+
await send(r);
|
|
80
|
+
expect(allText(r)).toContain('Your session has expired. Sign in again.');
|
|
81
|
+
fail = false;
|
|
82
|
+
const retry = r.root.findAll((n) => typeof n.type === 'string' && String(n.props.testID ?? '').endsWith('-retry'))[0];
|
|
83
|
+
press(retry);
|
|
84
|
+
await tick(); await tick();
|
|
85
|
+
expect(allText(r)).toContain('Pricing call with Acme');
|
|
86
|
+
expect(allText(r)).not.toContain('Sign in again');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('an answer from no records is said plainly, not as an error', async () => {
|
|
90
|
+
const fake = createFakeLibraryApi();
|
|
91
|
+
const { r } = await mount({ api: { ask: async () => ({ ...(await fake.ask.ask({ question: 'zzzzqqq nothing', mode: 'ask', scope: fake.scope })) }) } });
|
|
92
|
+
type(r, 'zzzzqqq nothing');
|
|
93
|
+
await send(r);
|
|
94
|
+
expect(allText(r)).not.toContain('Something went wrong');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createNativeCorpusApi } from '../../corpus/api';
|
|
3
|
+
import { createFakeTenantHttp } from '../../corpus/fake-tenant';
|
|
4
|
+
import { sampleTenantEntities, sampleTenantRelationships } from '../../corpus/fake-data';
|
|
5
|
+
import { createLibraryController } from '../library/controller';
|
|
6
|
+
import { createFakeLibraryApi, libraryExtraEntities, libraryExtraRelationships } from '../library/fake-library';
|
|
7
|
+
|
|
8
|
+
type Req = { method: string; path: string; params: Record<string, unknown> };
|
|
9
|
+
function setup(options: Parameters<typeof createFakeLibraryApi>[0] = {}, pageSize?: number) {
|
|
10
|
+
const requests: Req[] = [];
|
|
11
|
+
const api = createFakeLibraryApi({ ...options, onRequest: (method, path, params) => requests.push({ method, path, params }) });
|
|
12
|
+
const controller = createLibraryController(api, { pageSize });
|
|
13
|
+
const documentReads = () => requests.filter((r) => r.method === 'GET' && r.path === 'api/v1/entities' && r.params.type === 'source_document');
|
|
14
|
+
return { api, controller, requests, documentReads };
|
|
15
|
+
}
|
|
16
|
+
const ids = (c: ReturnType<typeof createLibraryController>) => c.getState().list.items.map((d) => d.id);
|
|
17
|
+
|
|
18
|
+
describe('library controller: the list is the server\'s page', () => {
|
|
19
|
+
it('start() loads newest first, with the filter options and each row\'s project', async () => {
|
|
20
|
+
const { controller } = setup();
|
|
21
|
+
await controller.start();
|
|
22
|
+
const s = controller.getState();
|
|
23
|
+
expect(ids(controller)).toEqual(['d1', 'd2', 'd3', 'd4', 'd5']);
|
|
24
|
+
expect(s.list.count).toBe(5);
|
|
25
|
+
expect(s.projects.map((p) => p.label)).toEqual(['287A', 'Debug', 'Marketing agents']);
|
|
26
|
+
expect(s.sources.map((o) => o.value).sort()).toEqual(['drive', 'granola', 'voice']);
|
|
27
|
+
expect(s.types.map((o) => o.value).sort()).toEqual(['document', 'meeting', 'voice_note']);
|
|
28
|
+
expect(s.filings.d1.map((f) => f.title)).toEqual(['287A']);
|
|
29
|
+
expect(s.filings.d5).toEqual([]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('search is sent to the server, never filtered on the phone', async () => {
|
|
33
|
+
const { controller, documentReads } = setup();
|
|
34
|
+
await controller.start();
|
|
35
|
+
await controller.setSearch('checklist');
|
|
36
|
+
expect(ids(controller)).toEqual(['d3']);
|
|
37
|
+
expect(documentReads().at(-1)!.params.search).toBe('checklist');
|
|
38
|
+
await controller.setSearch('');
|
|
39
|
+
expect(ids(controller)).toHaveLength(5);
|
|
40
|
+
expect(documentReads().at(-1)!.params.search).toBeUndefined();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('source, type and project are server parameters', async () => {
|
|
44
|
+
const { controller, documentReads } = setup();
|
|
45
|
+
await controller.start();
|
|
46
|
+
await controller.setFilter('source', 'granola');
|
|
47
|
+
expect(ids(controller)).toEqual(['d2', 'd4']);
|
|
48
|
+
expect(documentReads().at(-1)!.params.source).toBe('granola');
|
|
49
|
+
await controller.setFilter('subtype', 'meeting');
|
|
50
|
+
expect(documentReads().at(-1)!.params['attr.subtype']).toBe('meeting');
|
|
51
|
+
await controller.setFilter('project', 'fma');
|
|
52
|
+
expect(ids(controller)).toEqual(['d2', 'd4']);
|
|
53
|
+
expect(documentReads().at(-1)!.params).toMatchObject({ related_to: 'fma', related_via: 'about_focus', related_direction: 'out' });
|
|
54
|
+
await controller.setFilter('source', null);
|
|
55
|
+
await controller.setFilter('subtype', null);
|
|
56
|
+
await controller.setFilter('project', '287a-none');
|
|
57
|
+
expect(ids(controller)).toEqual([]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('newest / oldest is the server\'s order', async () => {
|
|
61
|
+
const { controller, documentReads } = setup();
|
|
62
|
+
await controller.start();
|
|
63
|
+
await controller.setOrder('oldest');
|
|
64
|
+
expect(ids(controller)).toEqual(['d5', 'd4', 'd3', 'd2', 'd1']);
|
|
65
|
+
expect(documentReads().at(-1)!.params.order).toBe('oldest');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('pages: loadMore asks the server for the next page and appends', async () => {
|
|
69
|
+
const { controller, documentReads } = setup({}, 2);
|
|
70
|
+
await controller.start();
|
|
71
|
+
expect(ids(controller)).toEqual(['d1', 'd2']);
|
|
72
|
+
expect(controller.getState().list.hasMore).toBe(true);
|
|
73
|
+
await controller.loadMore();
|
|
74
|
+
expect(ids(controller)).toEqual(['d1', 'd2', 'd3', 'd4']);
|
|
75
|
+
expect(documentReads().at(-1)!.params.page).toBe(2);
|
|
76
|
+
await controller.loadMore();
|
|
77
|
+
expect(ids(controller)).toHaveLength(5);
|
|
78
|
+
expect(controller.getState().list.hasMore).toBe(false);
|
|
79
|
+
// Filings were fetched for the rows that arrived, once each.
|
|
80
|
+
expect(controller.getState().filings.d4.map((f) => f.title)).toEqual(['Marketing agents']);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('says so when the server ignores a filter, instead of showing an unfiltered list as filtered', async () => {
|
|
84
|
+
const { controller } = setup({ unsupported: ['attr.subtype'] });
|
|
85
|
+
await controller.start();
|
|
86
|
+
await controller.setFilter('subtype', 'meeting');
|
|
87
|
+
expect(controller.getState().list.ignoredFilters).toContain('subtype');
|
|
88
|
+
expect(ids(controller)).toHaveLength(5);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('clearFilters returns to the whole corpus', async () => {
|
|
92
|
+
const { controller } = setup();
|
|
93
|
+
await controller.start();
|
|
94
|
+
await controller.setSearch('acme');
|
|
95
|
+
await controller.setFilter('source', 'granola');
|
|
96
|
+
await controller.clearFilters();
|
|
97
|
+
expect(controller.getState().filters).toEqual({ search: '', source: null, subtype: null, project: null, order: 'recent' });
|
|
98
|
+
expect(ids(controller)).toHaveLength(5);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('library controller: open a document', () => {
|
|
103
|
+
it('uses the row already loaded', async () => {
|
|
104
|
+
const { controller, requests } = setup();
|
|
105
|
+
await controller.start();
|
|
106
|
+
const before = requests.length;
|
|
107
|
+
await controller.open('d4');
|
|
108
|
+
expect(controller.getState().selected).toMatchObject({ id: 'd4', loading: false, error: null });
|
|
109
|
+
expect(controller.getState().selected!.document!.summary).toContain('$4,800');
|
|
110
|
+
expect(requests.length).toBe(before);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('fetches the one record when it is not on the page (a citation or a link)', async () => {
|
|
114
|
+
const { controller, requests } = setup({}, 2);
|
|
115
|
+
await controller.start();
|
|
116
|
+
await controller.open('d5');
|
|
117
|
+
expect(controller.getState().selected!.document!.title).toBe('Office move notes');
|
|
118
|
+
expect(requests.some((r) => r.path === 'api/v1/entities/d5')).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('names the id when it is gone', async () => {
|
|
122
|
+
const { controller } = setup();
|
|
123
|
+
await controller.start();
|
|
124
|
+
await controller.open('nope');
|
|
125
|
+
const sel = controller.getState().selected!;
|
|
126
|
+
expect(sel.document).toBeNull();
|
|
127
|
+
expect(sel.error).toContain('nope');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('close() clears it', async () => {
|
|
131
|
+
const { controller } = setup();
|
|
132
|
+
await controller.start();
|
|
133
|
+
await controller.open('d1');
|
|
134
|
+
controller.close();
|
|
135
|
+
expect(controller.getState().selected).toBeNull();
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe('library controller: change the project (the existing filing code)', () => {
|
|
140
|
+
it('replaces the about_focus edge and updates the row at once', async () => {
|
|
141
|
+
const { controller, api } = setup();
|
|
142
|
+
await controller.start();
|
|
143
|
+
await controller.fileUnder('d1', 'fdbg');
|
|
144
|
+
expect(controller.getState().filings.d1.map((f) => f.title)).toEqual(['Debug']);
|
|
145
|
+
const edges = await api.relationships.list({ relType: 'about_focus', source: 'd1' });
|
|
146
|
+
expect(edges.items.map((e) => String(e.target))).toEqual(['fdbg']);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('files an unfiled document, and unfiles with null', async () => {
|
|
150
|
+
const { controller, api } = setup();
|
|
151
|
+
await controller.start();
|
|
152
|
+
await controller.fileUnder('d5', 'f287');
|
|
153
|
+
expect(controller.getState().filings.d5.map((f) => f.title)).toEqual(['287A']);
|
|
154
|
+
await controller.fileUnder('d5', null);
|
|
155
|
+
expect(controller.getState().filings.d5).toEqual([]);
|
|
156
|
+
expect((await api.relationships.list({ relType: 'about_focus', source: 'd5' })).items).toEqual([]);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('says why when the write fails, and shows what the server holds', async () => {
|
|
160
|
+
const tenant = createFakeTenantHttp({
|
|
161
|
+
entities: [...sampleTenantEntities(), ...libraryExtraEntities()],
|
|
162
|
+
relationships: [...sampleTenantRelationships(), ...libraryExtraRelationships()],
|
|
163
|
+
});
|
|
164
|
+
const http = { ...tenant.http, post: async () => { throw Object.assign(new Error('Server hiccup'), { status: 500 }); } };
|
|
165
|
+
const controller = createLibraryController(createNativeCorpusApi({ http, scope: { orgId: 'tandem' } }));
|
|
166
|
+
await controller.start();
|
|
167
|
+
// Nothing was written for an unfiled document: it stays unfiled.
|
|
168
|
+
await controller.fileUnder('d5', 'fdbg');
|
|
169
|
+
expect(controller.getState().filingError).toBe('Server hiccup');
|
|
170
|
+
expect(controller.getState().filings.d5).toEqual([]);
|
|
171
|
+
expect(controller.getState().filingBusy).toBe(false);
|
|
172
|
+
// Moving d1 deletes its old edge first, so the server now holds it unfiled; the row says that, not a stale guess.
|
|
173
|
+
await controller.fileUnder('d1', 'fdbg');
|
|
174
|
+
expect(controller.getState().filings.d1).toEqual([]);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('re-reads the page when a project filter is on, so a moved row leaves it', async () => {
|
|
178
|
+
const { controller } = setup();
|
|
179
|
+
await controller.start();
|
|
180
|
+
await controller.setFilter('project', 'f287');
|
|
181
|
+
expect(ids(controller)).toEqual(['d1']);
|
|
182
|
+
await controller.fileUnder('d1', 'fdbg');
|
|
183
|
+
expect(ids(controller)).toEqual([]);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { act, allText, hostById, maybeById, press, render } from '../../../../../ui-native/test/render';
|
|
3
|
+
import { createLibraryController } from '../library/controller';
|
|
4
|
+
import { createFakeLibraryApi } from '../library/fake-library';
|
|
5
|
+
import { LibraryDetailScreen } from '../library/LibraryDetailScreen';
|
|
6
|
+
import { LibraryListScreen } from '../library/LibraryListScreen';
|
|
7
|
+
|
|
8
|
+
async function mountList(onOpen = vi.fn()) {
|
|
9
|
+
const api = createFakeLibraryApi();
|
|
10
|
+
const controller = createLibraryController(api);
|
|
11
|
+
const r = render(<LibraryListScreen controller={controller} onOpen={onOpen} />);
|
|
12
|
+
await act(async () => { await controller.start(); });
|
|
13
|
+
return { r, controller, onOpen, api };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('LibraryListScreen', () => {
|
|
17
|
+
it('shows the documents with their source, date, preview and the project they are filed under', async () => {
|
|
18
|
+
const { r } = await mountList();
|
|
19
|
+
const text = allText(r);
|
|
20
|
+
for (const title of ['Hearing prep and a dentist reminder', 'Weekly sync with Rae', 'Pricing call with Acme', 'Office move notes']) expect(text).toContain(title);
|
|
21
|
+
expect(text).toContain('5 documents');
|
|
22
|
+
expect(text).toContain('Granola');
|
|
23
|
+
expect(text).toContain('Acme renews at $4,800 per month');
|
|
24
|
+
expect(maybeById(r, 'library-chip-d1-f287').length).toBeGreaterThan(0);
|
|
25
|
+
expect(allText(r)).toContain('287A');
|
|
26
|
+
expect(allText(r)).toContain('Unfiled');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('tapping a row opens that document', async () => {
|
|
30
|
+
const { r, onOpen } = await mountList();
|
|
31
|
+
press(hostById(r, 'library-row-d4'));
|
|
32
|
+
expect(onOpen).toHaveBeenCalledWith('d4');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('a filter picked in the sheet is a server query', async () => {
|
|
36
|
+
const { r, controller } = await mountList();
|
|
37
|
+
press(hostById(r, 'library-list-filter-source'));
|
|
38
|
+
press(hostById(r, 'library-list-filter-source-option-granola'));
|
|
39
|
+
await act(async () => { await Promise.resolve(); });
|
|
40
|
+
await act(async () => { await new Promise((res) => setTimeout(res, 0)); });
|
|
41
|
+
expect(controller.getState().filters.source).toBe('granola');
|
|
42
|
+
expect(controller.getState().list.items.map((d) => d.id)).toEqual(['d2', 'd4']);
|
|
43
|
+
expect(allText(r)).toContain('2 documents');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('newest / oldest changes the server order', async () => {
|
|
47
|
+
const { r, controller } = await mountList();
|
|
48
|
+
press(hostById(r, 'library-list-sort-oldest'));
|
|
49
|
+
await act(async () => { await new Promise((res) => setTimeout(res, 0)); });
|
|
50
|
+
expect(controller.getState().filters.order).toBe('oldest');
|
|
51
|
+
expect(controller.getState().list.items[0].id).toBe('d5');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('says so when a filter was not applied by the server', async () => {
|
|
55
|
+
const api = createFakeLibraryApi({ unsupported: ['attr.subtype'] });
|
|
56
|
+
const controller = createLibraryController(api);
|
|
57
|
+
const r = render(<LibraryListScreen controller={controller} onOpen={() => {}} />);
|
|
58
|
+
await act(async () => { await controller.start(); await controller.setFilter('subtype', 'meeting'); });
|
|
59
|
+
expect(allText(r)).toContain('does not filter by type');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('a failed first load is an error with Retry, not an empty library', async () => {
|
|
63
|
+
const api = createFakeLibraryApi();
|
|
64
|
+
let fail = true;
|
|
65
|
+
const realList = api.corpus.listDocuments!;
|
|
66
|
+
api.corpus.listDocuments = async (q) => { if (fail) throw new Error('Offline'); return realList(q); };
|
|
67
|
+
const controller = createLibraryController(api);
|
|
68
|
+
const r = render(<LibraryListScreen controller={controller} onOpen={() => {}} />);
|
|
69
|
+
await act(async () => { await controller.start(); });
|
|
70
|
+
expect(allText(r)).toContain('Offline');
|
|
71
|
+
fail = false;
|
|
72
|
+
await act(async () => { press(hostById(r, 'library-list-retry')); await new Promise((res) => setTimeout(res, 0)); });
|
|
73
|
+
expect(allText(r)).toContain('Office move notes');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
async function mountDetail(id: string, onBack = vi.fn()) {
|
|
78
|
+
const api = createFakeLibraryApi();
|
|
79
|
+
const controller = createLibraryController(api);
|
|
80
|
+
const r = render(<LibraryDetailScreen controller={controller} documentId={id} onBack={onBack} />);
|
|
81
|
+
await act(async () => { await controller.start(); await controller.open(id); });
|
|
82
|
+
return { r, controller, onBack, api };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
describe('LibraryDetailScreen', () => {
|
|
86
|
+
it('reads the summary as Markdown, with its source, date and project', async () => {
|
|
87
|
+
const { r } = await mountDetail('d4');
|
|
88
|
+
const text = allText(r);
|
|
89
|
+
expect(text).toContain('Pricing call with Acme');
|
|
90
|
+
expect(text).toContain('Decisions');
|
|
91
|
+
expect(text).toContain('$4,800 per month');
|
|
92
|
+
expect(text).not.toContain('**');
|
|
93
|
+
expect(text).not.toContain('## ');
|
|
94
|
+
expect(text).toContain('Granola');
|
|
95
|
+
expect(text).toContain('Filed under');
|
|
96
|
+
expect(text).toContain('Marketing agents');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('Back goes back', async () => {
|
|
100
|
+
const { r, onBack } = await mountDetail('d4');
|
|
101
|
+
press(hostById(r, 'library-detail-back'));
|
|
102
|
+
expect(onBack).toHaveBeenCalled();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('changes the project through the filing code and shows the new one', async () => {
|
|
106
|
+
const { r, controller, api } = await mountDetail('d4');
|
|
107
|
+
press(hostById(r, 'library-detail-project'));
|
|
108
|
+
press(hostById(r, 'library-detail-project-option-fdbg'));
|
|
109
|
+
await act(async () => { await new Promise((res) => setTimeout(res, 0)); });
|
|
110
|
+
expect(controller.getState().filings.d4.map((f) => f.title)).toEqual(['Debug']);
|
|
111
|
+
expect((await api.relationships.list({ relType: 'about_focus', source: 'd4' })).items.map((e) => String(e.target))).toEqual(['fdbg']);
|
|
112
|
+
expect(allText(r)).toContain('Debug');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('an unfiled document can be filed, and unfiled again with the clear row', async () => {
|
|
116
|
+
const { r, controller } = await mountDetail('d5');
|
|
117
|
+
expect(allText(r)).toContain('Unfiled');
|
|
118
|
+
press(hostById(r, 'library-detail-project'));
|
|
119
|
+
press(hostById(r, 'library-detail-project-option-f287'));
|
|
120
|
+
await act(async () => { await new Promise((res) => setTimeout(res, 0)); });
|
|
121
|
+
expect(controller.getState().filings.d5.map((f) => f.title)).toEqual(['287A']);
|
|
122
|
+
press(hostById(r, 'library-detail-project'));
|
|
123
|
+
press(hostById(r, 'library-detail-project-clear'));
|
|
124
|
+
await act(async () => { await new Promise((res) => setTimeout(res, 0)); });
|
|
125
|
+
expect(controller.getState().filings.d5).toEqual([]);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('a record that is gone says which one, with a way back', async () => {
|
|
129
|
+
const { r, onBack } = await mountDetail('nope');
|
|
130
|
+
expect(allText(r)).toContain('nope');
|
|
131
|
+
press(hostById(r, 'library-detail-back'));
|
|
132
|
+
expect(onBack).toHaveBeenCalled();
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { act, allText, hostById, press, render } from '../../../../../ui-native/test/render';
|
|
3
|
+
import type { TabContext } from '../../components/FoundryTabsShell';
|
|
4
|
+
import { askTab, libraryAskTabs, libraryTab } from '../tabs';
|
|
5
|
+
import { createFakeLibraryApi } from '../library/fake-library';
|
|
6
|
+
|
|
7
|
+
const ctx = (over: Partial<TabContext> = {}): TabContext => ({
|
|
8
|
+
tab: 'library', active: true, route: null, push: vi.fn(), back: vi.fn(), openTab: vi.fn(), ...over,
|
|
9
|
+
});
|
|
10
|
+
const tick = () => act(async () => { await new Promise((res) => setTimeout(res, 20)); });
|
|
11
|
+
|
|
12
|
+
describe('Library and Ask tab config', () => {
|
|
13
|
+
it('registers two tabs with stable keys', () => {
|
|
14
|
+
expect(libraryAskTabs(createFakeLibraryApi()).map((t) => [t.key, t.label])).toEqual([['library', 'Library'], ['ask', 'Ask']]);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('Library: the list, and a tapped row pushes the document id', async () => {
|
|
18
|
+
const c = ctx();
|
|
19
|
+
const r = render(<>{libraryTab(createFakeLibraryApi()).render(c)}</>);
|
|
20
|
+
await tick();
|
|
21
|
+
expect(allText(r)).toContain('Pricing call with Acme');
|
|
22
|
+
press(hostById(r, 'library-row-d4'));
|
|
23
|
+
expect(c.push).toHaveBeenCalledWith('d4');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('Library: with a route it shows that document (a deep link or a citation), Back pops', async () => {
|
|
27
|
+
const c = ctx({ route: { id: 'd4' } });
|
|
28
|
+
const r = render(<>{libraryTab(createFakeLibraryApi()).render(c)}</>);
|
|
29
|
+
await tick();
|
|
30
|
+
expect(allText(r)).toContain('$4,800 per month');
|
|
31
|
+
expect(allText(r)).toContain('Marketing agents');
|
|
32
|
+
press(hostById(r, 'library-detail-back'));
|
|
33
|
+
expect(c.back).toHaveBeenCalled();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('Ask: a citation opens the document in the Library tab', async () => {
|
|
37
|
+
const c = ctx({ tab: 'ask' });
|
|
38
|
+
const r = render(<>{askTab(createFakeLibraryApi()).render(c)}</>);
|
|
39
|
+
await tick();
|
|
40
|
+
act(() => { hostById(r, 'ask-composer-input').props.onChangeText('pricing Acme'); });
|
|
41
|
+
press(hostById(r, 'ask-composer-send'));
|
|
42
|
+
await tick();
|
|
43
|
+
press(hostById(r, 'ask-citation-d4'));
|
|
44
|
+
expect(c.openTab).toHaveBeenCalledWith('library', 'd4');
|
|
45
|
+
});
|
|
46
|
+
});
|