@startsimpli/integrations 0.2.82 → 0.2.83
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 +1 -1
- package/src/__tests__/voice-notes-page-query.test.tsx +118 -0
- package/src/__tests__/voice-notes-query.test.ts +72 -0
- package/src/components/pages/VoiceNotesPage.tsx +180 -119
- package/src/corpus/voice-query.ts +49 -0
- package/src/corpus/voice.ts +36 -16
- package/src/native/components/NoteDetailScreen.tsx +6 -4
- package/src/native/components/NotesListScreen.tsx +81 -20
- package/src/native/components/__tests__/notes-screens.test.tsx +141 -0
- package/src/native/voice/__tests__/controller-query.test.ts +242 -0
- package/src/native/voice/__tests__/fake-query.test.ts +40 -0
- package/src/native/voice/controller.ts +197 -21
- package/src/native/voice/fake.ts +54 -7
package/src/corpus/voice.ts
CHANGED
|
@@ -31,12 +31,16 @@ import type { CorpusScope } from './types';
|
|
|
31
31
|
import { ABOUT_FOCUS, fileDocument, listFocusChoices, setDocumentFocuses } from './filing';
|
|
32
32
|
import { filingsFromRow, filingsToRow, uniqueFocusIds } from './voice-sections';
|
|
33
33
|
import { currentNoteFocus, refileVoiceCommitments } from './voice-refile';
|
|
34
|
+
import { QUERY_FILTER_KEYS, voiceNotesParams } from './voice-query';
|
|
35
|
+
import { toEntityPage } from './entity-query';
|
|
36
|
+
import type { VoiceNotesPage, VoiceNotesQuery } from './voice-query';
|
|
34
37
|
import type { FilingMove } from './voice-refile';
|
|
35
38
|
import type { SectionFiling, VoiceSection } from './voice-sections';
|
|
36
39
|
import type { FocusChoice } from './filing';
|
|
37
40
|
|
|
38
41
|
export { ABOUT_FOCUS };
|
|
39
42
|
export type { FocusChoice };
|
|
43
|
+
export type { VoiceNotesPage, VoiceNotesQuery, VoiceNoteOrder } from './voice-query';
|
|
40
44
|
export type { SectionFiling, VoiceSection, VoiceItem, VoiceSectionKind } from './voice-sections';
|
|
41
45
|
|
|
42
46
|
export const VOICE_SOURCE = 'voice';
|
|
@@ -355,6 +359,11 @@ export interface VoiceNotesApi {
|
|
|
355
359
|
/** Upload a finished recording. Resolves once it is saved; processing continues server-side. */
|
|
356
360
|
submit(audio: Blob, meta: { durationMs: number }): Promise<{ id: string }>;
|
|
357
361
|
list(): Promise<VoiceNote[]>;
|
|
362
|
+
/**
|
|
363
|
+
* One page of notes for a server query: search, project, order (bd startsim-23np6.3).
|
|
364
|
+
* Absent = an older client that can only `list()`; screens then hide the query controls.
|
|
365
|
+
*/
|
|
366
|
+
listPage?(query: VoiceNotesQuery, page: number): Promise<VoiceNotesPage>;
|
|
358
367
|
listFocuses(): Promise<VoiceFocus[]>;
|
|
359
368
|
/** Move a note to another project, or `null` to unfile it. With sections: every section moves. */
|
|
360
369
|
file(noteId: string, focusId: string | null): Promise<void>;
|
|
@@ -449,26 +458,37 @@ export function createVoiceApi(options: CreateVoiceApiOptions): VoiceNotesApi {
|
|
|
449
458
|
...(options.server?.remove ? { remove: options.server.remove } : {}),
|
|
450
459
|
...(options.server?.audioUrl ? { audioUrl: options.server.audioUrl } : {}),
|
|
451
460
|
|
|
452
|
-
async
|
|
453
|
-
const
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
const rows =
|
|
457
|
-
if (!rows.length) return [];
|
|
458
|
-
const edges = await http.get<Page<TenantRelationship>>('api/v1/relationships', {
|
|
459
|
-
params: { rel_type: ABOUT_FOCUS, entity__in: rows.map((r) => r.id).join(','), page_size: 200 },
|
|
460
|
-
});
|
|
461
|
+
async listPage(query, page) {
|
|
462
|
+
const params = voiceNotesParams(query, page, options.limit ?? 25);
|
|
463
|
+
const envelope = await http.get<Parameters<typeof toEntityPage<TenantEntity, TenantEntity>>[1]>('api/v1/entities', { params });
|
|
464
|
+
const found = toEntityPage(params, envelope, (row) => row);
|
|
465
|
+
const rows = found.items;
|
|
461
466
|
const focusOf = new Map<string, string[]>();
|
|
462
|
-
|
|
463
|
-
const
|
|
464
|
-
|
|
465
|
-
|
|
467
|
+
if (rows.length) {
|
|
468
|
+
const edges = await http.get<Page<TenantRelationship>>('api/v1/relationships', {
|
|
469
|
+
params: { rel_type: ABOUT_FOCUS, entity__in: rows.map((r) => r.id).join(','), page_size: 200 },
|
|
470
|
+
});
|
|
471
|
+
for (const edge of edges.results ?? []) {
|
|
472
|
+
const list = focusOf.get(String(edge.source)) ?? [];
|
|
473
|
+
list.push(String(edge.target));
|
|
474
|
+
focusOf.set(String(edge.source), list);
|
|
475
|
+
}
|
|
466
476
|
}
|
|
467
|
-
return
|
|
477
|
+
return {
|
|
468
478
|
// `source=voice` may be ignored by an older backend (it says so in
|
|
469
479
|
// `applied_filters`); never show another source's rows as voice notes.
|
|
470
|
-
|
|
471
|
-
|
|
480
|
+
notes: rows
|
|
481
|
+
.filter((r) => text(((r.data ?? {}) as Record<string, unknown>).source) === VOICE_SOURCE)
|
|
482
|
+
.map((r) => toVoiceNote(r, focusOf.get(String(r.id)) ?? [])),
|
|
483
|
+
count: found.count,
|
|
484
|
+
nextPage: found.nextPage,
|
|
485
|
+
// Only a report-less (older) server names `source` etc. as ignored; say so for the query parts a user chose.
|
|
486
|
+
ignoredFilters: found.ignoredFilters.filter((k) => QUERY_FILTER_KEYS.includes(k)),
|
|
487
|
+
};
|
|
488
|
+
},
|
|
489
|
+
|
|
490
|
+
async list() {
|
|
491
|
+
return (await this.listPage!({}, 1)).notes;
|
|
472
492
|
},
|
|
473
493
|
|
|
474
494
|
listFocuses: () => listFocusChoices(http),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
2
|
import { Alert as RNAlert, ScrollView, View } from 'react-native';
|
|
3
|
-
import { Alert, Badge, Button, Chip, Separator, Text, useTheme } from '@startsimpli/ui-native';
|
|
3
|
+
import { Alert, Badge, Button, Chip, Separator, Spinner, Text, useTheme } from '@startsimpli/ui-native';
|
|
4
4
|
import type { VoiceFocus, VoiceNote } from '../../corpus/voice';
|
|
5
5
|
import type { VoiceNotesController } from '../voice/controller';
|
|
6
6
|
import { formatDuration, formatNoteDate, statusLabel, statusVariant } from '../voice/format';
|
|
@@ -29,14 +29,16 @@ export function NoteDetailScreen({ controller, noteId, onBack }: NoteDetailScree
|
|
|
29
29
|
const theme = useTheme();
|
|
30
30
|
const [showTranscript, setShowTranscript] = useState(false);
|
|
31
31
|
const [picking, setPicking] = useState(false);
|
|
32
|
-
|
|
32
|
+
// A deep link, or a note moved out of the active filter, is not on a loaded page: the controller fetches it by id.
|
|
33
|
+
useEffect(() => { void controller.open(noteId); }, [controller, noteId]);
|
|
34
|
+
const note: VoiceNote | undefined = state.notes?.find((n) => n.id === noteId) ?? (state.opened?.id === noteId ? state.opened : undefined);
|
|
33
35
|
const gap = { gap: theme.spacing.sm } as const;
|
|
34
36
|
|
|
35
37
|
if (!note) {
|
|
36
38
|
return (
|
|
37
39
|
<View style={{ padding: theme.spacing.lg, ...gap }}>
|
|
38
40
|
<Button title="Back" variant="ghost" size="sm" onPress={onBack} testID="note-back" />
|
|
39
|
-
<Text variant="muted">This note is no longer available.</Text>
|
|
41
|
+
{state.notes === null || state.opening ? <Spinner /> : <Text variant="muted">This note is no longer available.</Text>}
|
|
40
42
|
</View>
|
|
41
43
|
);
|
|
42
44
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import type
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { Pressable, View } from 'react-native';
|
|
3
|
+
import { Alert, Badge, DataList, Text, useTheme, type FilterGroup } from '@startsimpli/ui-native';
|
|
4
|
+
import type { VoiceNote, VoiceNoteOrder } from '../../corpus/voice';
|
|
4
5
|
import type { VoiceNotesController } from '../voice/controller';
|
|
5
6
|
import { formatDuration, formatNoteDate, statusLabel, statusVariant } from '../voice/format';
|
|
6
7
|
import { noteSections } from '../voice/sections';
|
|
@@ -14,34 +15,94 @@ export interface NotesListScreenProps {
|
|
|
14
15
|
const subtitle = (n: VoiceNote) =>
|
|
15
16
|
[formatNoteDate(n.occurredAt), formatDuration(n.durationMs)].filter(Boolean).join(' · ');
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
const IGNORED_NAMES: Record<string, string> = { search: 'search notes', related_to: 'filter by project', order: 'sort' };
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Notes, newest first: server-side search, project filter, sort and paging (the
|
|
22
|
+
* same controller the web page uses). Pull to refresh, polls while any note is
|
|
23
|
+
* transcribing, tap to open.
|
|
24
|
+
*/
|
|
18
25
|
export function NotesListScreen({ controller, onOpen }: NotesListScreenProps) {
|
|
19
26
|
const state = useVoiceNotes(controller);
|
|
20
27
|
const theme = useTheme();
|
|
28
|
+
const [draft, setDraft] = useState(state.query.search);
|
|
29
|
+
const { query, notes } = state;
|
|
30
|
+
const canQuery = controller.canQuery;
|
|
31
|
+
|
|
32
|
+
const projects: FilterGroup = {
|
|
33
|
+
key: 'project', label: 'Project', display: 'select', value: query.focusId,
|
|
34
|
+
options: state.focuses.map((f) => ({ value: f.id, label: f.title })),
|
|
35
|
+
};
|
|
36
|
+
const ignored = state.ignoredFilters.map((k) => IGNORED_NAMES[k] ?? k);
|
|
37
|
+
const count = state.count;
|
|
38
|
+
|
|
21
39
|
return (
|
|
22
|
-
<
|
|
40
|
+
<DataList<VoiceNote>
|
|
23
41
|
testID="notes-list"
|
|
24
|
-
data={
|
|
42
|
+
data={notes ?? []}
|
|
25
43
|
keyExtractor={(n) => n.id}
|
|
26
|
-
|
|
27
|
-
|
|
44
|
+
loading={notes === null && !state.error}
|
|
45
|
+
refreshing={false}
|
|
46
|
+
onRefresh={() => { void controller.refresh(); }}
|
|
47
|
+
// With rows on screen a failure shows in the header (a filing / paging error is not "the list failed").
|
|
48
|
+
error={notes === null ? state.error : null}
|
|
49
|
+
onRetry={() => { void controller.refresh(); }}
|
|
50
|
+
hasMore={state.hasMore}
|
|
51
|
+
loadingMore={state.loadingMore}
|
|
52
|
+
onLoadMore={() => { void controller.loadMore(); }}
|
|
53
|
+
search={canQuery ? {
|
|
54
|
+
value: draft, onChange: setDraft, placeholder: 'Search your notes',
|
|
55
|
+
onSearch: (text) => { void controller.setSearch(text); },
|
|
56
|
+
} : undefined}
|
|
57
|
+
filters={canQuery && projects.options.length ? [projects] : []}
|
|
58
|
+
onFilterChange={(_key, value) => { void controller.setFocusFilter(value); }}
|
|
59
|
+
onClearFilters={() => { setDraft(''); void controller.clearFilters(); }}
|
|
60
|
+
sort={canQuery ? {
|
|
61
|
+
value: query.order,
|
|
62
|
+
options: [
|
|
63
|
+
{ value: 'recent', label: 'Newest' },
|
|
64
|
+
{ value: 'oldest', label: 'Oldest' },
|
|
65
|
+
...(query.search.trim() ? [{ value: 'relevance', label: 'Best match' }] : []),
|
|
66
|
+
],
|
|
67
|
+
onChange: (v) => { void controller.setOrder(v as VoiceNoteOrder); },
|
|
68
|
+
} : undefined}
|
|
69
|
+
emptyTitle="No notes yet"
|
|
70
|
+
emptyDescription="Record one from the GO tab."
|
|
71
|
+
noResultsTitle="No notes match"
|
|
28
72
|
ListHeaderComponent={
|
|
29
73
|
<View style={{ gap: theme.spacing.sm, paddingBottom: theme.spacing.sm }}>
|
|
30
74
|
<Text variant="heading">Notes</Text>
|
|
31
|
-
{
|
|
75
|
+
{count !== null && canQuery ? <Text variant="caption">{`${count} note${count === 1 ? '' : 's'}`}</Text> : null}
|
|
76
|
+
{ignored.length ? (
|
|
77
|
+
<Alert>{`This workspace does not ${ignored.join(', ')} yet, so the list below is not narrowed by ${ignored.length > 1 ? 'those' : 'that'}.`}</Alert>
|
|
78
|
+
) : null}
|
|
79
|
+
{state.error && notes !== null ? <Alert variant="destructive">{state.error}</Alert> : null}
|
|
32
80
|
</View>
|
|
33
81
|
}
|
|
34
|
-
|
|
35
|
-
state.notes === null ? <Spinner /> : <EmptyState title="No notes yet" description="Record one from the GO tab." />
|
|
36
|
-
}
|
|
37
|
-
renderItem={({ item }) => (
|
|
38
|
-
<ListRow
|
|
39
|
-
title={item.title}
|
|
40
|
-
subtitle={[subtitle(item), noteSections(item)[0]?.summary].filter(Boolean).join('\n') || undefined}
|
|
41
|
-
onPress={() => onOpen(item)}
|
|
42
|
-
trailing={<Badge label={statusLabel(item.status)} variant={statusVariant(item.status)} />}
|
|
43
|
-
/>
|
|
44
|
-
)}
|
|
82
|
+
renderItem={({ item }) => <NoteRow note={item} onPress={() => onOpen(item)} />}
|
|
45
83
|
/>
|
|
46
84
|
);
|
|
47
85
|
}
|
|
86
|
+
|
|
87
|
+
function NoteRow({ note, onPress }: { note: VoiceNote; onPress: () => void }) {
|
|
88
|
+
const theme = useTheme();
|
|
89
|
+
const preview = noteSections(note)[0]?.summary;
|
|
90
|
+
return (
|
|
91
|
+
<Pressable
|
|
92
|
+
testID={`note-row-${note.id}`}
|
|
93
|
+
accessibilityRole="button"
|
|
94
|
+
onPress={onPress}
|
|
95
|
+
style={({ pressed }) => ({
|
|
96
|
+
flexDirection: 'row', alignItems: 'center', gap: theme.spacing.sm, paddingVertical: theme.spacing.md,
|
|
97
|
+
borderBottomWidth: 1, borderBottomColor: theme.colors.border, opacity: pressed ? 0.6 : 1,
|
|
98
|
+
})}
|
|
99
|
+
>
|
|
100
|
+
<View style={{ flex: 1, gap: theme.spacing.xs }}>
|
|
101
|
+
<Text style={{ fontWeight: '600' }} numberOfLines={2}>{note.title}</Text>
|
|
102
|
+
{subtitle(note) ? <Text variant="caption">{subtitle(note)}</Text> : null}
|
|
103
|
+
{preview ? <Text variant="muted" numberOfLines={2}>{preview}</Text> : null}
|
|
104
|
+
</View>
|
|
105
|
+
<Badge label={statusLabel(note.status)} variant={statusVariant(note.status)} />
|
|
106
|
+
</Pressable>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bd startsim-23np6.3 (search / project filter / sort / paging on the Notes tab)
|
|
3
|
+
* and startsim-ij1lw.13 (a note's to-dos come from its section items, nothing else).
|
|
4
|
+
*/
|
|
5
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
6
|
+
import { act, allText, hostById, maybeById, press, render } from '../../../../../ui-native/test/render';
|
|
7
|
+
import { createVoiceNotesController } from '../../voice/controller';
|
|
8
|
+
import { createFakeVoiceApi, type FakeVoiceApiOptions } from '../../voice/fake';
|
|
9
|
+
import type { VoiceNotesApi } from '../../../corpus/voice';
|
|
10
|
+
import { NoteDetailScreen } from '../NoteDetailScreen';
|
|
11
|
+
import { NotesListScreen } from '../NotesListScreen';
|
|
12
|
+
|
|
13
|
+
const settle = () => act(async () => { await new Promise((res) => setTimeout(res, 0)); });
|
|
14
|
+
|
|
15
|
+
async function mountList(options: FakeVoiceApiOptions = {}, api: VoiceNotesApi = createFakeVoiceApi(options)) {
|
|
16
|
+
const controller = createVoiceNotesController({ api, pollMs: 60_000 });
|
|
17
|
+
const onOpen = vi.fn();
|
|
18
|
+
const r = render(<NotesListScreen controller={controller} onOpen={onOpen} />);
|
|
19
|
+
await settle();
|
|
20
|
+
return { r, controller, onOpen, api };
|
|
21
|
+
}
|
|
22
|
+
const type = async (r: ReturnType<typeof render>, text: string) => {
|
|
23
|
+
act(() => { hostById(r, 'notes-list-search').props.onChangeText(text); });
|
|
24
|
+
act(() => { hostById(r, 'notes-list-search').props.onSubmitEditing(); });
|
|
25
|
+
await settle();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
describe('NotesListScreen', () => {
|
|
29
|
+
it('shows the notes with a count', async () => {
|
|
30
|
+
const { r } = await mountList();
|
|
31
|
+
expect(allText(r)).toContain('Hearing prep and a dentist reminder');
|
|
32
|
+
expect(allText(r)).toContain('Snake plant watering');
|
|
33
|
+
expect(allText(r)).toContain('4 notes');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('search is a server query and shows only what the server returned', async () => {
|
|
37
|
+
const { r, controller } = await mountList();
|
|
38
|
+
await type(r, 'dentist');
|
|
39
|
+
expect(controller.getState().query.search).toBe('dentist');
|
|
40
|
+
expect(controller.getState().notes?.map((n) => n.id)).toEqual(['n1']);
|
|
41
|
+
expect(allText(r)).toContain('1 note');
|
|
42
|
+
expect(allText(r)).not.toContain('Snake plant watering');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('a search with no hits says so and offers to clear it', async () => {
|
|
46
|
+
const { r, controller } = await mountList();
|
|
47
|
+
await type(r, 'zzzz');
|
|
48
|
+
expect(maybeById(r, 'notes-list-no-results').length).toBe(1);
|
|
49
|
+
press(hostById(r, 'notes-list-empty-clear'));
|
|
50
|
+
await settle();
|
|
51
|
+
expect(controller.getState().query.search).toBe('');
|
|
52
|
+
expect(controller.getState().notes).toHaveLength(4);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('the project filter is a server query', async () => {
|
|
56
|
+
const { r, controller } = await mountList();
|
|
57
|
+
press(hostById(r, 'notes-list-filter-project'));
|
|
58
|
+
press(hostById(r, 'notes-list-filter-project-option-fma'));
|
|
59
|
+
await settle();
|
|
60
|
+
expect(controller.getState().query.focusId).toBe('fma');
|
|
61
|
+
expect(controller.getState().notes?.map((n) => n.id).sort()).toEqual(['n1', 'n2']);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('newest / oldest changes the server order, and best match appears only with a search', async () => {
|
|
65
|
+
const { r, controller } = await mountList();
|
|
66
|
+
expect(maybeById(r, 'notes-list-sort-relevance').length).toBe(0);
|
|
67
|
+
press(hostById(r, 'notes-list-sort-oldest'));
|
|
68
|
+
await settle();
|
|
69
|
+
expect(controller.getState().notes?.[0].id).toBe('n3');
|
|
70
|
+
await type(r, 'the');
|
|
71
|
+
expect(maybeById(r, 'notes-list-sort-relevance').length).toBe(1);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('end of list loads the next page; nothing more when there is none', async () => {
|
|
75
|
+
const { r, controller } = await mountList({ pageSize: 3 });
|
|
76
|
+
expect(controller.getState().notes).toHaveLength(3);
|
|
77
|
+
expect(allText(r)).toContain('4 notes');
|
|
78
|
+
await act(async () => { hostById(r, 'notes-list').props.onEndReached?.({ distanceFromEnd: 0 }); await new Promise((res) => setTimeout(res, 0)); });
|
|
79
|
+
expect(controller.getState().notes).toHaveLength(4);
|
|
80
|
+
expect(controller.getState().hasMore).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('says so when the server did not apply the search', async () => {
|
|
84
|
+
const { r } = await mountList({ unsupported: ['search'] });
|
|
85
|
+
await type(r, 'dentist');
|
|
86
|
+
expect(allText(r)).toContain('does not search notes yet');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('a client that cannot page has no search, filter or sort controls (no faking them locally)', async () => {
|
|
90
|
+
const full = createFakeVoiceApi();
|
|
91
|
+
const { r } = await mountList({}, { ...full, listPage: undefined });
|
|
92
|
+
expect(maybeById(r, 'notes-list-search').length).toBe(0);
|
|
93
|
+
expect(maybeById(r, 'notes-list-sort-oldest').length).toBe(0);
|
|
94
|
+
expect(allText(r)).toContain('Snake plant watering');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('tapping a row opens that note', async () => {
|
|
98
|
+
const { r, onOpen } = await mountList();
|
|
99
|
+
press(hostById(r, 'note-row-n2'));
|
|
100
|
+
expect(onOpen).toHaveBeenCalledWith(expect.objectContaining({ id: 'n2' }));
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
async function mountDetail(id: string, options: FakeVoiceApiOptions = {}) {
|
|
105
|
+
const controller = createVoiceNotesController({ api: createFakeVoiceApi(options), pollMs: 60_000 });
|
|
106
|
+
const onBack = vi.fn();
|
|
107
|
+
const r = render(<NoteDetailScreen controller={controller} noteId={id} onBack={onBack} />);
|
|
108
|
+
await settle();
|
|
109
|
+
return { r, controller, onBack };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
describe('NoteDetailScreen', () => {
|
|
113
|
+
it('to-dos come from the section items, one list per section', async () => {
|
|
114
|
+
const { r } = await mountDetail('n1');
|
|
115
|
+
const text = allText(r);
|
|
116
|
+
expect(text).toContain('• Finish exhibit list');
|
|
117
|
+
expect(text).toContain('• Call Megan about the filing receipt');
|
|
118
|
+
expect(text).toContain('• Move weekly report to Monday');
|
|
119
|
+
expect(text).toContain('• Book the dentist');
|
|
120
|
+
expect(text).toContain('Finish the exhibit list before the hearing.');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('a note without sections gets its to-dos from the summary bullets', async () => {
|
|
124
|
+
const { r } = await mountDetail('n2', {
|
|
125
|
+
notes: [{ id: 'n2', title: 'Garage', status: 'ready', occurredAt: null, focusId: null, transcript: '', summary: 'Garage plans.\n\n## Next Steps\n- **Buy brackets** (Quinn)\n- **Cut shelves**' }],
|
|
126
|
+
});
|
|
127
|
+
expect(allText(r)).toContain('• Buy brackets (Quinn)');
|
|
128
|
+
expect(allText(r)).toContain('• Cut shelves');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('a note past the first page still opens (fetched by id)', async () => {
|
|
132
|
+
const { r } = await mountDetail('n3', { pageSize: 1 });
|
|
133
|
+
expect(allText(r)).toContain('No speech was detected');
|
|
134
|
+
expect(allText(r)).not.toContain('no longer available');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('a note that does not exist says so', async () => {
|
|
138
|
+
const { r } = await mountDetail('nope');
|
|
139
|
+
expect(allText(r)).toContain('This note is no longer available.');
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bd startsim-23np6.3: search, project filter, order and paging on the shared
|
|
3
|
+
* notes controller. Every one of them is a server request, never a local narrow.
|
|
4
|
+
*/
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
+
import type { VoiceNote, VoiceNotesApi, VoiceNotesPage, VoiceNotesQuery } from '../../../corpus/voice';
|
|
7
|
+
import { createVoiceNotesController } from '../controller';
|
|
8
|
+
|
|
9
|
+
const note = (id: string, status: VoiceNote['status'] = 'ready', over: Partial<VoiceNote> = {}): VoiceNote => ({
|
|
10
|
+
id, title: `n${id}`, summary: '', transcript: '', status, occurredAt: null, focusId: null, ...over,
|
|
11
|
+
});
|
|
12
|
+
const page = (notes: VoiceNote[], nextPage: number | null = null, over: Partial<VoiceNotesPage> = {}): VoiceNotesPage =>
|
|
13
|
+
({ notes, count: notes.length, nextPage, ignoredFilters: [], ...over });
|
|
14
|
+
|
|
15
|
+
function fakeApi(listPage: VoiceNotesApi['listPage'], over: Partial<VoiceNotesApi> = {}): VoiceNotesApi {
|
|
16
|
+
return {
|
|
17
|
+
submit: vi.fn(),
|
|
18
|
+
list: vi.fn().mockResolvedValue([]),
|
|
19
|
+
listPage,
|
|
20
|
+
listFocuses: vi.fn().mockResolvedValue([{ id: 'f1', title: 'Alpha' }]),
|
|
21
|
+
file: vi.fn().mockResolvedValue(undefined),
|
|
22
|
+
...over,
|
|
23
|
+
} as VoiceNotesApi;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
beforeEach(() => { vi.useFakeTimers(); });
|
|
27
|
+
afterEach(() => { vi.useRealTimers(); });
|
|
28
|
+
|
|
29
|
+
describe('query', () => {
|
|
30
|
+
it('first load asks the server for page 1 and keeps count + hasMore', async () => {
|
|
31
|
+
const listPage = vi.fn().mockResolvedValue(page([note('1'), note('2')], 2, { count: 7 }));
|
|
32
|
+
const c = createVoiceNotesController({ api: fakeApi(listPage) });
|
|
33
|
+
await c.refresh();
|
|
34
|
+
expect(listPage).toHaveBeenCalledWith({ order: 'recent' }, 1);
|
|
35
|
+
expect(c.getState()).toMatchObject({ count: 7, hasMore: true });
|
|
36
|
+
expect(c.canQuery).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('setSearch is a server query from page 1, and the typed text stays in state', async () => {
|
|
40
|
+
const listPage = vi.fn<NonNullable<VoiceNotesApi['listPage']>>().mockResolvedValue(page([note('1')]));
|
|
41
|
+
const c = createVoiceNotesController({ api: fakeApi(listPage) });
|
|
42
|
+
await c.refresh();
|
|
43
|
+
await c.setSearch(' brackets ');
|
|
44
|
+
expect(listPage).toHaveBeenLastCalledWith({ search: 'brackets', order: 'recent' }, 1);
|
|
45
|
+
expect(c.getState().query.search).toBe(' brackets ');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('does not ask again when only whitespace changed', async () => {
|
|
49
|
+
const listPage = vi.fn().mockResolvedValue(page([note('1')]));
|
|
50
|
+
const c = createVoiceNotesController({ api: fakeApi(listPage) });
|
|
51
|
+
await c.refresh();
|
|
52
|
+
await c.setSearch('x');
|
|
53
|
+
await c.setSearch('x ');
|
|
54
|
+
expect(listPage).toHaveBeenCalledTimes(2);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('project filter and order are server parameters', async () => {
|
|
58
|
+
const listPage = vi.fn<NonNullable<VoiceNotesApi['listPage']>>().mockResolvedValue(page([]));
|
|
59
|
+
const c = createVoiceNotesController({ api: fakeApi(listPage) });
|
|
60
|
+
await c.setFocusFilter('f1');
|
|
61
|
+
expect(listPage).toHaveBeenLastCalledWith({ focusId: 'f1', order: 'recent' }, 1);
|
|
62
|
+
await c.setOrder('oldest');
|
|
63
|
+
expect(listPage).toHaveBeenLastCalledWith({ focusId: 'f1', order: 'oldest' }, 1);
|
|
64
|
+
await c.clearFilters();
|
|
65
|
+
expect(listPage).toHaveBeenLastCalledWith({ order: 'recent' }, 1);
|
|
66
|
+
expect(c.getState().query).toEqual({ search: '', focusId: null, order: 'recent' });
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('clearing the search leaves "best match" order, which needs a term', async () => {
|
|
70
|
+
const listPage = vi.fn<NonNullable<VoiceNotesApi['listPage']>>().mockResolvedValue(page([]));
|
|
71
|
+
const c = createVoiceNotesController({ api: fakeApi(listPage) });
|
|
72
|
+
await c.setSearch('x');
|
|
73
|
+
await c.setOrder('relevance');
|
|
74
|
+
expect(listPage).toHaveBeenLastCalledWith({ search: 'x', order: 'relevance' }, 1);
|
|
75
|
+
await c.setSearch('');
|
|
76
|
+
expect(c.getState().query.order).toBe('recent');
|
|
77
|
+
expect(listPage).toHaveBeenLastCalledWith({ order: 'recent' }, 1);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('drops a slow response to an older query', async () => {
|
|
81
|
+
let releaseSlow!: (p: VoiceNotesPage) => void;
|
|
82
|
+
const listPage = vi.fn<NonNullable<VoiceNotesApi['listPage']>>((q: VoiceNotesQuery) =>
|
|
83
|
+
q.search === 'old' ? new Promise<VoiceNotesPage>((res) => { releaseSlow = res; }) : Promise.resolve(page([note('new')])));
|
|
84
|
+
const c = createVoiceNotesController({ api: fakeApi(listPage) });
|
|
85
|
+
const slow = c.setSearch('old');
|
|
86
|
+
await c.setSearch('new');
|
|
87
|
+
releaseSlow(page([note('old')]));
|
|
88
|
+
await slow;
|
|
89
|
+
expect(c.getState().notes?.map((n) => n.id)).toEqual(['new']);
|
|
90
|
+
expect(c.getState().refreshing).toBe(false);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('reports a query part the server did not apply', async () => {
|
|
94
|
+
const listPage = vi.fn().mockResolvedValue(page([note('1')], null, { ignoredFilters: ['search'] }));
|
|
95
|
+
const c = createVoiceNotesController({ api: fakeApi(listPage) });
|
|
96
|
+
await c.setSearch('x');
|
|
97
|
+
expect(c.getState().ignoredFilters).toEqual(['search']);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('a client that cannot page keeps working as a plain list and says it cannot query', async () => {
|
|
101
|
+
const list = vi.fn().mockResolvedValue([note('1')]);
|
|
102
|
+
const c = createVoiceNotesController({ api: fakeApi(undefined, { list }) });
|
|
103
|
+
await c.refresh();
|
|
104
|
+
await c.setSearch('x');
|
|
105
|
+
expect(c.canQuery).toBe(false);
|
|
106
|
+
expect(list).toHaveBeenCalledTimes(1);
|
|
107
|
+
expect(c.getState().notes).toHaveLength(1);
|
|
108
|
+
expect(c.getState().hasMore).toBe(false);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('paging', () => {
|
|
113
|
+
it('loadMore appends the next page, then stops when there is none', async () => {
|
|
114
|
+
const listPage = vi.fn<NonNullable<VoiceNotesApi['listPage']>>()
|
|
115
|
+
.mockResolvedValueOnce(page([note('1'), note('2')], 2, { count: 3 }))
|
|
116
|
+
.mockResolvedValueOnce(page([note('3')], null, { count: 3 }));
|
|
117
|
+
const c = createVoiceNotesController({ api: fakeApi(listPage) });
|
|
118
|
+
await c.refresh();
|
|
119
|
+
await c.loadMore();
|
|
120
|
+
expect(listPage).toHaveBeenLastCalledWith({ order: 'recent' }, 2);
|
|
121
|
+
expect(c.getState().notes?.map((n) => n.id)).toEqual(['1', '2', '3']);
|
|
122
|
+
expect(c.getState().hasMore).toBe(false);
|
|
123
|
+
await c.loadMore();
|
|
124
|
+
expect(listPage).toHaveBeenCalledTimes(2);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('loadMore does nothing while a page is already loading', async () => {
|
|
128
|
+
let release!: (p: VoiceNotesPage) => void;
|
|
129
|
+
const listPage = vi.fn<NonNullable<VoiceNotesApi['listPage']>>()
|
|
130
|
+
.mockResolvedValueOnce(page([note('1')], 2))
|
|
131
|
+
.mockImplementationOnce(() => new Promise<VoiceNotesPage>((res) => { release = res; }));
|
|
132
|
+
const c = createVoiceNotesController({ api: fakeApi(listPage) });
|
|
133
|
+
await c.refresh();
|
|
134
|
+
const first = c.loadMore();
|
|
135
|
+
await c.loadMore();
|
|
136
|
+
release(page([note('2')]));
|
|
137
|
+
await first;
|
|
138
|
+
expect(listPage).toHaveBeenCalledTimes(2);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('a page loaded for an old query is dropped when the query changes', async () => {
|
|
142
|
+
let release!: (p: VoiceNotesPage) => void;
|
|
143
|
+
const listPage = vi.fn<NonNullable<VoiceNotesApi['listPage']>>()
|
|
144
|
+
.mockResolvedValueOnce(page([note('1')], 2))
|
|
145
|
+
.mockImplementationOnce(() => new Promise<VoiceNotesPage>((res) => { release = res; }))
|
|
146
|
+
.mockResolvedValueOnce(page([note('x')]));
|
|
147
|
+
const c = createVoiceNotesController({ api: fakeApi(listPage) });
|
|
148
|
+
await c.refresh();
|
|
149
|
+
const more = c.loadMore();
|
|
150
|
+
await c.setFocusFilter('f1');
|
|
151
|
+
release(page([note('2')]));
|
|
152
|
+
await more;
|
|
153
|
+
expect(c.getState().notes?.map((n) => n.id)).toEqual(['x']);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('polling re-reads only the processing notes and keeps the pages already loaded', async () => {
|
|
157
|
+
const listPage = vi.fn<NonNullable<VoiceNotesApi['listPage']>>(async (q) => {
|
|
158
|
+
if (q.ids) return page([note('1', 'ready', { title: 'Done now' })]);
|
|
159
|
+
return page([note('1', 'processing'), note('2')], 2);
|
|
160
|
+
});
|
|
161
|
+
listPage.mockResolvedValueOnce(page([note('1', 'processing'), note('2')], 2))
|
|
162
|
+
.mockResolvedValueOnce(page([note('3'), note('4')], null));
|
|
163
|
+
const c = createVoiceNotesController({ api: fakeApi(listPage), pollMs: 3000 });
|
|
164
|
+
c.start();
|
|
165
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
166
|
+
await c.loadMore();
|
|
167
|
+
expect(c.getState().notes?.map((n) => n.id)).toEqual(['1', '2', '3', '4']);
|
|
168
|
+
await vi.advanceTimersByTimeAsync(3000);
|
|
169
|
+
expect(listPage).toHaveBeenLastCalledWith({ ids: ['1'] }, 1);
|
|
170
|
+
expect(c.getState().notes?.map((n) => n.id)).toEqual(['1', '2', '3', '4']);
|
|
171
|
+
expect(c.getState().notes?.[0]).toMatchObject({ status: 'ready', title: 'Done now' });
|
|
172
|
+
const calls = listPage.mock.calls.length;
|
|
173
|
+
await vi.advanceTimersByTimeAsync(10000);
|
|
174
|
+
expect(listPage.mock.calls.length).toBe(calls);
|
|
175
|
+
c.stop();
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe('filing', () => {
|
|
180
|
+
it('moving a note out of an active project filter re-reads the list', async () => {
|
|
181
|
+
const listPage = vi.fn<NonNullable<VoiceNotesApi['listPage']>>()
|
|
182
|
+
.mockResolvedValueOnce(page([note('1', 'ready', { focusId: 'f1' })]))
|
|
183
|
+
.mockResolvedValueOnce(page([]));
|
|
184
|
+
const c = createVoiceNotesController({ api: fakeApi(listPage) });
|
|
185
|
+
await c.setFocusFilter('f1');
|
|
186
|
+
await c.file('1', null);
|
|
187
|
+
expect(listPage).toHaveBeenCalledTimes(2);
|
|
188
|
+
expect(c.getState().notes).toEqual([]);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('without a filter, filing does not re-read', async () => {
|
|
192
|
+
const listPage = vi.fn().mockResolvedValue(page([note('1', 'ready', { focusId: 'f1' })]));
|
|
193
|
+
const c = createVoiceNotesController({ api: fakeApi(listPage) });
|
|
194
|
+
await c.refresh();
|
|
195
|
+
await c.file('1', null);
|
|
196
|
+
expect(listPage).toHaveBeenCalledTimes(1);
|
|
197
|
+
expect(c.getState().notes?.[0].focusId).toBeNull();
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('fileSection is optimistic and rolls back with the reason on failure', async () => {
|
|
201
|
+
const sectioned = note('1', 'ready', { sections: [{ label: 'A', kind: 'project', focusId: 'f1' }, { label: 'P', kind: 'personal', focusId: null }] });
|
|
202
|
+
const fileSection = vi.fn().mockRejectedValue(new Error('refused'));
|
|
203
|
+
const c = createVoiceNotesController({ api: fakeApi(vi.fn().mockResolvedValue(page([sectioned])), { fileSection }) });
|
|
204
|
+
await c.refresh();
|
|
205
|
+
expect(c.canFileSection).toBe(true);
|
|
206
|
+
const moving = c.fileSection('1', 1, 'f2');
|
|
207
|
+
expect(c.getState().notes?.[0].sections?.[1].focusId).toBe('f2');
|
|
208
|
+
await moving;
|
|
209
|
+
expect(fileSection).toHaveBeenCalledWith('1', 1, 'f2');
|
|
210
|
+
expect(c.getState().notes?.[0].sections?.[1].focusId).toBeNull();
|
|
211
|
+
expect(c.getState().error).toBe('refused');
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
describe('open', () => {
|
|
216
|
+
it('fetches a note that is not on a loaded page by id', async () => {
|
|
217
|
+
const listPage = vi.fn<NonNullable<VoiceNotesApi['listPage']>>(async (q) => (q.ids ? page([note('deep')]) : page([note('1')])));
|
|
218
|
+
const c = createVoiceNotesController({ api: fakeApi(listPage) });
|
|
219
|
+
await c.refresh();
|
|
220
|
+
await c.open('deep');
|
|
221
|
+
expect(listPage).toHaveBeenLastCalledWith({ ids: ['deep'] }, 1);
|
|
222
|
+
expect(c.getState().opened?.id).toBe('deep');
|
|
223
|
+
expect(c.getState().opening).toBe(false);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('does not fetch a note that is already loaded', async () => {
|
|
227
|
+
const listPage = vi.fn().mockResolvedValue(page([note('1')]));
|
|
228
|
+
const c = createVoiceNotesController({ api: fakeApi(listPage) });
|
|
229
|
+
await c.refresh();
|
|
230
|
+
await c.open('1');
|
|
231
|
+
expect(listPage).toHaveBeenCalledTimes(1);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('a mutation reaches the opened note too', async () => {
|
|
235
|
+
const listPage = vi.fn<NonNullable<VoiceNotesApi['listPage']>>(async (q) => (q.ids ? page([note('deep')]) : page([note('1')])));
|
|
236
|
+
const c = createVoiceNotesController({ api: fakeApi(listPage) });
|
|
237
|
+
await c.refresh();
|
|
238
|
+
await c.open('deep');
|
|
239
|
+
await c.file('deep', 'f1');
|
|
240
|
+
expect(c.getState().opened?.focusId).toBe('f1');
|
|
241
|
+
});
|
|
242
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createFakeVoiceApi } from '../fake';
|
|
3
|
+
|
|
4
|
+
describe('createFakeVoiceApi.listPage (server semantics)', () => {
|
|
5
|
+
it('searches, filters by project, orders and pages', async () => {
|
|
6
|
+
const api = createFakeVoiceApi({ pageSize: 2 });
|
|
7
|
+
const all = await api.listPage!({}, 1);
|
|
8
|
+
expect(all.count).toBe(4);
|
|
9
|
+
expect(all.notes).toHaveLength(2);
|
|
10
|
+
expect(all.nextPage).toBe(2);
|
|
11
|
+
expect((await api.listPage!({}, 2)).nextPage).toBeNull();
|
|
12
|
+
|
|
13
|
+
expect((await api.listPage!({ search: 'dentist' }, 1)).notes.map((n) => n.id)).toEqual(['n1']);
|
|
14
|
+
expect((await api.listPage!({ focusId: 'fma' }, 1)).notes.map((n) => n.id).sort()).toEqual(['n1', 'n2']);
|
|
15
|
+
const oldest = await api.listPage!({ order: 'oldest' }, 1);
|
|
16
|
+
expect(oldest.notes[0].id).toBe('n3');
|
|
17
|
+
expect((await api.listPage!({ ids: ['n2'] }, 1)).notes.map((n) => n.id)).toEqual(['n2']);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('behaves like an older server when asked: not applied, and reported ignored', async () => {
|
|
21
|
+
const api = createFakeVoiceApi({ unsupported: ['search'] });
|
|
22
|
+
const page = await api.listPage!({ search: 'dentist' }, 1);
|
|
23
|
+
expect(page.notes).toHaveLength(4);
|
|
24
|
+
expect(page.ignoredFilters).toEqual(['search']);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('a processing note finishes through listPage reads', async () => {
|
|
28
|
+
const api = createFakeVoiceApi({ processingPolls: 1 });
|
|
29
|
+
await api.listPage!({ ids: ['n0'] }, 1);
|
|
30
|
+
const later = await api.listPage!({ ids: ['n0'] }, 1);
|
|
31
|
+
expect(later.notes[0].status).toBe('ready');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('fileSection moves one section only', async () => {
|
|
35
|
+
const api = createFakeVoiceApi();
|
|
36
|
+
await api.fileSection!('n1', 2, 'fdbg');
|
|
37
|
+
const n1 = (await api.listPage!({ ids: ['n1'] }, 1)).notes[0];
|
|
38
|
+
expect(n1.sections?.map((s) => s.focusId)).toEqual(['f287', 'fma', 'fdbg']);
|
|
39
|
+
});
|
|
40
|
+
});
|