@startsimpli/integrations 0.2.203 → 0.2.205

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.
@@ -0,0 +1,193 @@
1
+ /** The Library on the shared table: columns, toolbar, server queries, and the source/folder tree. */
2
+ import { describe, expect, it } from 'vitest';
3
+ import { configure, render, screen, waitFor, within } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+
6
+ import { LibraryPage } from '../components/pages/LibraryPage';
7
+ import type { CorpusApi, DocumentQuery, SourceDocument, SourceFreshness } from '../corpus/types';
8
+
9
+ configure({ asyncUtilTimeout: 5000 });
10
+ const SCOPE = { orgId: 'org_a' };
11
+ const EMPTY = { count: 0, next: null, previous: null, results: [] };
12
+
13
+ function doc(id: string, title: string, extra: Partial<SourceDocument> = {}): SourceDocument {
14
+ return {
15
+ id, title, body: '', sections: [], occurredAt: '2026-11-01T10:00:00Z', source: 'dropbox', sourceLabel: 'Dropbox',
16
+ sourceRef: id, participants: [], scope: SCOPE, ...extra,
17
+ } as SourceDocument;
18
+ }
19
+
20
+ const SOURCES: SourceFreshness[] = [
21
+ { source: 'dropbox', label: 'Dropbox', documentCount: 2, lastSyncedAt: null, status: 'ok' },
22
+ { source: 'granola', label: 'Granola', documentCount: 1, lastSyncedAt: null, status: 'ok' },
23
+ ];
24
+
25
+ function corpus() {
26
+ const queries: DocumentQuery[] = [];
27
+ const folderAsks: Array<{ under: string; source?: string }> = [];
28
+ const rows = [
29
+ doc('d1', 'Master Services Agreement', { folder: '/Contracts', subtype: 'document', participants: [{ id: 'p1', name: 'Ada' }] }),
30
+ doc('d2', 'Brand guide', { folder: '/Design/Brand', subtype: 'document' }),
31
+ doc('d3', 'Weekly sync', { source: 'granola', sourceLabel: 'Granola', subtype: 'meeting' }),
32
+ ];
33
+ const api: CorpusApi = {
34
+ listDocuments: async (query) => {
35
+ queries.push(query as DocumentQuery);
36
+ return { count: 41, next: null, previous: null, appliedFilters: Object.keys(query as object), results: rows };
37
+ },
38
+ getDocument: async () => { throw new Error('unused'); },
39
+ listParties: async () => EMPTY,
40
+ listSources: async () => SOURCES,
41
+ listFolders: async (query) => {
42
+ folderAsks.push({ under: query.under, source: query.source });
43
+ // Only Dropbox has folders; Granola's meetings live in none.
44
+ if (query.source === 'dropbox' && query.under === '/') {
45
+ return { count: 1, next: null, previous: null, results: [{ path: '/Contracts', name: 'Contracts', count: 2, hasChildren: false }] };
46
+ }
47
+ return EMPTY;
48
+ },
49
+ };
50
+ return { api, queries, folderAsks };
51
+ }
52
+
53
+ describe('LibraryPage on the shared table', () => {
54
+ it('has the six columns, no Size, and a dash where a source has no folder, type or people', async () => {
55
+ const { api } = corpus();
56
+ render(<LibraryPage api={api} scope={SCOPE} />);
57
+ const table = await screen.findByTestId('table-library');
58
+ for (const header of ['Title', 'Source', 'Folder', 'Type', 'Date', 'Who']) {
59
+ expect(within(table).getByRole('columnheader', { name: new RegExp(header) })).toBeInTheDocument();
60
+ }
61
+ expect(within(table).queryByRole('columnheader', { name: /Size/ })).toBeNull();
62
+ const row = (await within(table).findByText('Weekly sync')).closest('tr')!;
63
+ expect(within(row).getByText('Meeting')).toBeInTheDocument();
64
+ expect(within(row).getAllByText('—').length).toBeGreaterThanOrEqual(2);
65
+ });
66
+
67
+ it('has one toolbar (search, Type, Date), no connector cards, no title and no pills', async () => {
68
+ const { api } = corpus();
69
+ render(<LibraryPage api={api} scope={SCOPE} />);
70
+ await screen.findByText('Weekly sync');
71
+ expect(screen.getByRole('searchbox', { name: 'Search the library' })).toBeInTheDocument();
72
+ expect(screen.getByRole('combobox', { name: 'Type' })).toBeInTheDocument();
73
+ expect(screen.getByRole('combobox', { name: 'Date' })).toBeInTheDocument();
74
+ expect(screen.queryByRole('heading')).toBeNull();
75
+ expect(screen.queryByText(/Up to date|Not syncing|Last sync/)).toBeNull();
76
+ expect(screen.getByRole('navigation', { name: 'Pagination' })).toBeInTheDocument();
77
+ expect(screen.getByText(/1-25 of 41/)).toBeInTheDocument();
78
+ });
79
+
80
+ it('sorts only by Date, and asks the server for it', async () => {
81
+ const user = userEvent.setup();
82
+ const { api, queries } = corpus();
83
+ render(<LibraryPage api={api} scope={SCOPE} />);
84
+ const table = await screen.findByTestId('table-library');
85
+ await screen.findByText('Weekly sync');
86
+ expect(within(table).queryByRole('button', { name: /^Title/ })).toBeNull();
87
+ await user.click(within(table).getByRole('button', { name: /^Date/ }));
88
+ await waitFor(() => expect(queries[queries.length - 1].order).toBeDefined());
89
+ expect(['recent', 'oldest']).toContain(queries[queries.length - 1].order);
90
+ });
91
+
92
+ it('sends Type and Date to the server and returns to page 1', async () => {
93
+ const user = userEvent.setup();
94
+ const { api, queries } = corpus();
95
+ render(<LibraryPage api={api} scope={SCOPE} />);
96
+ await screen.findByText('Weekly sync');
97
+ await user.click(screen.getByRole('button', { name: 'Next page' }));
98
+ await waitFor(() => expect(queries[queries.length - 1].page).toBe(2));
99
+ await user.selectOptions(screen.getByRole('combobox', { name: 'Type' }), 'meeting');
100
+ await waitFor(() => expect(queries[queries.length - 1]).toMatchObject({ subtype: 'meeting', page: 1 }));
101
+ await user.selectOptions(screen.getByRole('combobox', { name: 'Date' }), '30');
102
+ await waitFor(() => expect(queries[queries.length - 1].occurredAfter).toBeTruthy());
103
+ });
104
+
105
+ it('lists All documents first, then each source with its count', async () => {
106
+ const { api } = corpus();
107
+ render(<LibraryPage api={api} scope={SCOPE} />);
108
+ const tree = await screen.findByRole('navigation', { name: 'Sources and folders' });
109
+ const buttons = await within(tree).findAllByRole('button');
110
+ expect(buttons[0]).toHaveTextContent('All documents');
111
+ await waitFor(() => expect(within(tree).getByRole('button', { name: /Dropbox/ })).toHaveTextContent('2'));
112
+ expect(within(tree).getByRole('button', { name: /Granola/ })).toHaveTextContent('1');
113
+ });
114
+
115
+ it('draws folders only under the source that has them, one source at a time, after the rows', async () => {
116
+ const { api, folderAsks } = corpus();
117
+ render(<LibraryPage api={api} scope={SCOPE} />);
118
+ const tree = await screen.findByRole('navigation', { name: 'Sources and folders' });
119
+ await within(tree).findByRole('button', { name: 'Expand Dropbox' });
120
+ expect(within(tree).queryByRole('button', { name: 'Expand Granola' })).toBeNull();
121
+ expect(folderAsks.every((ask) => ask.source)).toBe(true);
122
+ expect(folderAsks.map((ask) => ask.source)).toEqual(['dropbox', 'granola']);
123
+ });
124
+
125
+ it('a source click filters by that source; a folder click lists the folder and its subtree', async () => {
126
+ const user = userEvent.setup();
127
+ const { api, queries } = corpus();
128
+ render(<LibraryPage api={api} scope={SCOPE} />);
129
+ const tree = await screen.findByRole('navigation', { name: 'Sources and folders' });
130
+ await user.click(await within(tree).findByRole('button', { name: /Dropbox/ }));
131
+ await waitFor(() => expect(queries[queries.length - 1]).toMatchObject({ source: 'dropbox', page: 1 }));
132
+ await user.click(await within(tree).findByRole('button', { name: /^Contracts/ }));
133
+ await waitFor(() => expect(queries[queries.length - 1]).toMatchObject({ source: 'dropbox', underFolder: '/Contracts' }));
134
+ expect(queries[queries.length - 1].folder).toBeUndefined();
135
+ });
136
+
137
+ it('opens a record when its row is clicked', async () => {
138
+ const user = userEvent.setup();
139
+ const { api } = corpus();
140
+ render(<LibraryPage api={api} scope={SCOPE} />);
141
+ await user.click(await screen.findByText('Brand guide'));
142
+ expect(await screen.findByRole('region', { name: 'Record detail' })).toBeInTheDocument();
143
+ });
144
+
145
+ it('does not claim the server ignored a filter while the answer is still on its way', async () => {
146
+ const user = userEvent.setup();
147
+ let release: () => void = () => {};
148
+ const { api } = corpus();
149
+ const base = api.listDocuments.bind(api);
150
+ let calls = 0;
151
+ api.listDocuments = async (query, options) => {
152
+ calls += 1;
153
+ const page = await base(query, options);
154
+ if (calls === 1) return { ...page, appliedFilters: [] };
155
+ await new Promise<void>((resolve) => { release = resolve; });
156
+ return { ...page, appliedFilters: ['source'] };
157
+ };
158
+ render(<LibraryPage api={api} scope={SCOPE} />);
159
+ await screen.findByText('Weekly sync');
160
+ await user.click(await screen.findByRole('button', { name: /Dropbox/ }));
161
+ await waitFor(() => expect(calls).toBe(2));
162
+ expect(screen.queryByText(/does not filter by/)).toBeNull();
163
+ release();
164
+ await waitFor(() => expect(screen.queryByText(/does not filter by/)).toBeNull());
165
+ });
166
+
167
+ it('hides Type, Folder and Who (and the Type filter) when nothing on the page has a value', async () => {
168
+ const { api } = corpus();
169
+ api.listDocuments = async () => ({ count: 2, next: null, previous: null, appliedFilters: [], results: [doc('a', 'Alpha', { source: 'granola' }), doc('b', 'Beta', { source: 'granola' })] });
170
+ render(<LibraryPage api={api} scope={SCOPE} />);
171
+ const table = await screen.findByTestId('table-library');
172
+ await within(table).findByText('Alpha');
173
+ for (const header of ['Type', 'Folder', 'Who']) {
174
+ expect(within(table).queryByRole('columnheader', { name: header })).toBeNull();
175
+ }
176
+ expect(within(table).getByRole('columnheader', { name: /Title/ })).toBeInTheDocument();
177
+ expect(within(table).getByRole('columnheader', { name: /Date/ })).toBeInTheDocument();
178
+ expect(screen.queryByRole('combobox', { name: 'Type' })).toBeNull();
179
+ });
180
+
181
+ it('keeps Who until the people read has landed, then shows it when someone is on a row', async () => {
182
+ let release: (m: Map<string, never[]>) => void = () => {};
183
+ const { api } = corpus();
184
+ api.participantsFor = () => new Promise((resolve) => { release = resolve as never; });
185
+ api.listDocuments = async () => ({ count: 1, next: null, previous: null, appliedFilters: [], results: [doc('a', 'Alpha')] });
186
+ render(<LibraryPage api={api} scope={SCOPE} />);
187
+ const table = await screen.findByTestId('table-library');
188
+ await within(table).findByText('Alpha');
189
+ expect(within(table).getByRole('columnheader', { name: 'Who' })).toBeInTheDocument();
190
+ release(new Map([['a', [{ id: 'p1', name: 'Ada' }] as never]]) as never);
191
+ expect(await within(table).findByText('Ada')).toBeInTheDocument();
192
+ });
193
+ });
@@ -0,0 +1,86 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import { fireEvent, render, screen, within } from '@testing-library/react';
3
+
4
+ import { SourcesTable } from '../components/pages/library/SourcesTable';
5
+ import type { SourceFreshness } from '../corpus/types';
6
+
7
+ const NOW = Date.parse('2026-11-20T12:00:00Z');
8
+ const mins = (m: number) => new Date(NOW + m * 60_000).toISOString();
9
+ const cls = { section: '', muted: '' };
10
+
11
+ function row(over: Partial<SourceFreshness> & { source: string; label: string }): SourceFreshness {
12
+ return { documentCount: null, lastSyncedAt: null, status: 'ok', ...over };
13
+ }
14
+
15
+ function renderTable(sources: SourceFreshness[], onManage = vi.fn()) {
16
+ render(<SourcesTable sources={sources} now={NOW} onManage={onManage} classNames={cls} />);
17
+ return onManage;
18
+ }
19
+
20
+ describe('SourcesTable', () => {
21
+ it('a throttled Gmail reads as slowed, with records, last attempt and a retry time, and no vendor text', () => {
22
+ renderTable([row({
23
+ source: 'google', label: 'Google', documentCount: null, status: 'ok', lastSyncedAt: mins(-30),
24
+ sync: { state: 'limited', note: 'The provider is limiting requests; it resumes on its own', records: 72,
25
+ lastAttemptAt: mins(-2), lastSuccessAt: mins(-30), nextSyncAt: mins(9), intervalMinutes: 10 },
26
+ })]);
27
+ const r = within(screen.getByRole('row', { name: /Google/ }));
28
+ expect(r.getByRole('cell', { name: 'Slowed by the provider' })).toBeInTheDocument();
29
+ expect(r.getByRole('cell', { name: '72' })).toBeInTheDocument();
30
+ expect(r.getByRole('cell', { name: /30 min ago \(tried 2 min ago\)/ })).toBeInTheDocument();
31
+ expect(r.getByRole('cell', { name: 'In 9 min' })).toBeInTheDocument();
32
+ expect(screen.queryByText(/Quota|403|rate_limited/)).not.toBeInTheDocument();
33
+ });
34
+
35
+ it('a source that only receives data says so plainly and has no action', () => {
36
+ renderTable([row({
37
+ source: 'n8n', label: 'n8n',
38
+ sync: { state: 'passive', note: 'Receives data only when one of your workflows sends it; nothing sent yet',
39
+ records: 0, lastAttemptAt: null, lastSuccessAt: null, nextSyncAt: null, intervalMinutes: null },
40
+ })]);
41
+ const r = within(screen.getByRole('row', { name: /n8n/ }));
42
+ expect(r.getByRole('cell', { name: /Receives data only when one of your workflows sends it; nothing sent yet/ })).toBeInTheDocument();
43
+ expect(r.queryByRole('button')).not.toBeInTheDocument();
44
+ });
45
+
46
+ it('a task tracker shows the number of to-dos synced when the corpus holds no documents', () => {
47
+ renderTable([row({
48
+ source: 'linear', label: 'Linear', documentCount: 0, lastSyncedAt: mins(-5),
49
+ sync: { state: 'ok', note: '', records: 41, lastAttemptAt: mins(-5), lastSuccessAt: mins(-5), nextSyncAt: mins(5), intervalMinutes: 10 },
50
+ })]);
51
+ expect(within(screen.getByRole('row', { name: /Linear/ })).getByRole('cell', { name: '41' })).toBeInTheDocument();
52
+ });
53
+
54
+ it('a source needing a new sign-in offers Reconnect, and the action reports which source', () => {
55
+ const onManage = renderTable([row({
56
+ source: 'microsoft', label: 'Microsoft', status: 'error',
57
+ sync: { state: 'reauth', note: 'Reconnect this account to resume syncing', records: 1218, lastAttemptAt: null,
58
+ lastSuccessAt: mins(-60 * 24), nextSyncAt: null, intervalMinutes: 60 },
59
+ })]);
60
+ fireEvent.click(screen.getByRole('button', { name: 'Reconnect' }));
61
+ expect(onManage).toHaveBeenCalledWith('microsoft');
62
+ expect(screen.getByRole('cell', { name: 'After you reconnect' })).toBeInTheDocument();
63
+ });
64
+
65
+ it('a source with no schedule says Not scheduled instead of a blank', () => {
66
+ renderTable([row({
67
+ source: 'google', label: 'Google',
68
+ sync: { state: 'waiting', note: '', records: 0, lastAttemptAt: null, lastSuccessAt: null, nextSyncAt: null, intervalMinutes: null },
69
+ })]);
70
+ expect(screen.getByRole('cell', { name: 'Not scheduled' })).toBeInTheDocument();
71
+ });
72
+
73
+ it('a mailbox source shows its window under the record count', () => {
74
+ renderTable([row({
75
+ source: 'google', label: 'Google', documentCount: 72,
76
+ sync: { state: 'ok', note: '', records: 72, lastAttemptAt: mins(-1), lastSuccessAt: mins(-1), nextSyncAt: mins(9), intervalMinutes: 10, windowDays: 14 },
77
+ })]);
78
+ expect(within(screen.getByRole('row', { name: /Google/ })).getByText('last 14 days')).toBeInTheDocument();
79
+ });
80
+
81
+ it('has exactly the six columns and no pills or subtitles', () => {
82
+ renderTable([row({ source: 'dropbox', label: 'Dropbox', documentCount: 37, lastSyncedAt: mins(-60) })]);
83
+ expect(screen.getAllByRole('columnheader').map((h) => h.textContent)).toEqual(
84
+ ['Source', 'Status', 'Records', 'Last sync', 'Next sync', 'Action']);
85
+ });
86
+ });
@@ -103,6 +103,11 @@ export interface FolderTreeProps {
103
103
  * while it waits; nothing about what it draws changes.
104
104
  */
105
105
  hold?: boolean;
106
+ /** Only the folders of one source. The root row is not drawn when `showRoot` is false (the Library tree owns it). */
107
+ source?: string;
108
+ showRoot?: boolean;
109
+ /** Told once with the number of top-level folders the first read returned (0 = this source has none). */
110
+ onRootLoaded?: (count: number) => void;
106
111
  classNames?: Partial<Record<FolderTreeSlot, string>>;
107
112
  }
108
113
 
@@ -148,6 +153,9 @@ export function FolderTree({
148
153
  pageSize = 100,
149
154
  onUnavailable,
150
155
  hold = false,
156
+ source,
157
+ showRoot = true,
158
+ onRootLoaded,
151
159
  classNames = {},
152
160
  }: FolderTreeProps) {
153
161
  const cn = { ...DEFAULTS, ...classNames };
@@ -186,7 +194,7 @@ export function FolderTree({
186
194
  [under]: { ...(prev[under] ?? EMPTY), loading: true, error: '' },
187
195
  }));
188
196
  try {
189
- const result = await api.listFolders({ under, page, pageSize });
197
+ const result = await api.listFolders({ under, page, pageSize, ...(source ? { source } : {}) });
190
198
  setLevels((prev) => {
191
199
  const before = prev[under] ?? EMPTY;
192
200
  return {
@@ -213,7 +221,7 @@ export function FolderTree({
213
221
  [under]: { ...(prev[under] ?? EMPTY), loading: false, error: failure(err) },
214
222
  }));
215
223
  }
216
- }, [api, pageSize]);
224
+ }, [api, pageSize, source]);
217
225
 
218
226
  /**
219
227
  * Fetch a container's first page, once. The ref rather than a check on
@@ -245,25 +253,33 @@ export function FolderTree({
245
253
  ensure(path);
246
254
  }, [ensure]);
247
255
 
248
- if (unavailable) return null;
249
-
250
256
  const root = levels[FOLDER_ROOT] ?? EMPTY;
257
+ const rootDone = (root.page > 0 || Boolean(root.error)) && !root.loading;
258
+ const reported = React.useRef(false);
259
+ React.useEffect(() => { reported.current = false; }, [api, source]);
260
+ React.useEffect(() => {
261
+ if (rootDone && !reported.current) { reported.current = true; onRootLoaded?.(root.total); }
262
+ }, [rootDone, root.total, onRootLoaded]);
263
+
264
+ if (unavailable) return null;
251
265
 
252
266
  return (
253
267
  <nav className={cn.root} aria-label="Folders">
254
- <div className="flex items-center">
255
- <span aria-hidden="true" className="w-4 shrink-0" />
256
- <button
257
- type="button"
258
- className={`${cn.node} ${selected === null ? cn.nodeSelected : ''}`}
259
- aria-current={selected === null ? 'true' : undefined}
260
- onClick={() => onSelect(null)}
261
- >
262
- <span className="truncate">{rootLabel}</span>
263
- </button>
264
- </div>
268
+ {showRoot ? (
269
+ <div className="flex items-center">
270
+ <span aria-hidden="true" className="w-4 shrink-0" />
271
+ <button
272
+ type="button"
273
+ className={`${cn.node} ${selected === null ? cn.nodeSelected : ''}`}
274
+ aria-current={selected === null ? 'true' : undefined}
275
+ onClick={() => onSelect(null)}
276
+ >
277
+ <span className="truncate">{rootLabel}</span>
278
+ </button>
279
+ </div>
280
+ ) : null}
265
281
 
266
- {(root.loading || hold) && root.rows.length === 0 ? (
282
+ {showRoot && (root.loading || hold) && root.rows.length === 0 ? (
267
283
  <p className={cn.muted}>Loading folders…</p>
268
284
  ) : null}
269
285
  {root.error ? <p className={cn.error} role="alert">{root.error}</p> : null}