@startsimpli/integrations 0.2.79 → 0.2.81
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 +1 -1
- package/package.json +12 -2
- package/src/native/components/FoundryTabsShell.tsx +56 -8
- package/src/native/components/MoreTabList.tsx +35 -0
- package/src/native/components/__tests__/FoundryTabsShell.more.test.tsx +101 -0
- package/src/native/index.ts +2 -0
- package/src/native/recording/__tests__/deeplink.test.ts +92 -0
- package/src/native/recording/__tests__/diagnostics.test.ts +80 -0
- package/src/native/recording/__tests__/fakeForm.ts +10 -0
- package/src/native/recording/__tests__/flow.test.ts +47 -0
- package/src/native/recording/__tests__/levels.test.ts +38 -0
- package/src/native/recording/__tests__/notes.test.ts +74 -0
- package/src/native/recording/__tests__/permissions.test.ts +64 -0
- package/src/native/recording/__tests__/recorder.test.ts +233 -0
- package/src/native/recording/__tests__/recorderAudio.test.ts +153 -0
- package/src/native/recording/__tests__/recovery.test.ts +45 -0
- package/src/native/recording/__tests__/session.test.ts +120 -0
- package/src/native/recording/deeplink.ts +57 -0
- package/src/native/recording/diagnostics.ts +65 -0
- package/src/native/recording/index.ts +15 -0
- package/src/native/recording/levels.ts +32 -0
- package/src/native/recording/notes.ts +46 -0
- package/src/native/recording/permissions.ts +49 -0
- package/src/native/recording/recorder.ts +164 -0
- package/src/native/recording/recorderAudio.ts +154 -0
- package/src/native/recording/recovery.ts +40 -0
- package/src/native/recording/session.ts +65 -0
- package/src/native/recording/strings.ts +4 -0
- package/src/native/shell/__tests__/overflow.test.ts +31 -0
- package/src/native/shell/overflow.ts +23 -0
package/README.md
CHANGED
|
@@ -184,7 +184,7 @@ the screens need the OPTIONAL peers `react-native`, `react-native-safe-area-cont
|
|
|
184
184
|
|
|
185
185
|
1. Copy `~/Repos/tandem-ios` to `<foundry>-ios`. Change `app.json` (`name`, `slug`, `scheme`, `ios.bundleIdentifier`, microphone strings), `src/config.ts` (the Foundry's tenant URL; central auth is `https://api.startsimpli.com`), `src/strings.ts` and the theme in `App.tsx`.
|
|
186
186
|
2. `pnpm install`. It depends on published `@startsimpli/{auth,integrations,ui-native,utils}`, so nothing is linked.
|
|
187
|
-
3.
|
|
187
|
+
3. The recording path is in this package (`native/recording`: `createRecorder`, `createRecorderAudio`, `createPermissionFlow`, `recoverOrphans`, `createDeepLink`, `createDiagnostics`, `createSession`, `createNotes`, level helpers). The shell keeps only the device bindings, injected through `AudioDriver`, `SessionInspector`, `PermissionsApi` and `RecordingFile`: `src/native.ts` (expo-audio, expo-file-system) and `modules/tandem-audio-session` (bd startsim-ij1lw.9). `createDeepLink({ scheme })`, `createDiagnostics({ tag })` and `createSession({ app })` default to the Tandem Go values.
|
|
188
188
|
4. `src/services.ts` builds `createNativeVoiceApi` + `createVoiceNotesController`; `App.tsx` renders `<NotesShell go={<MainScreen .../>} controller={s.notesController} />`.
|
|
189
189
|
5. Check without a login: launch with `-tgFakeNotes list` (or a note id such as `n1`) to see the screens over `createFakeVoiceApi`.
|
|
190
190
|
6. `npx expo prebuild --platform ios`, then `npx expo run:ios --configuration Release` (Hermes). Signing and device install are per-Apple-team, see the template README.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/integrations",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.81",
|
|
4
4
|
"description": "Provider-agnostic types, API clients, hooks, and UI primitives for email + calendar integrations across StartSimpli apps, plus foundry customer email (subpath ./comms).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://startsimpli.com",
|
|
@@ -50,6 +50,8 @@
|
|
|
50
50
|
"react-native": ">=0.74.0",
|
|
51
51
|
"@startsimpli/ui-native": ">=0.1.0",
|
|
52
52
|
"react-native-safe-area-context": ">=4.0.0",
|
|
53
|
+
"@startsimpli/auth": "^0.4.47",
|
|
54
|
+
"@startsimpli/utils": "^0.4.15",
|
|
53
55
|
"@startsimpli/ui": "^0.4.167"
|
|
54
56
|
},
|
|
55
57
|
"peerDependenciesMeta": {
|
|
@@ -73,6 +75,12 @@
|
|
|
73
75
|
},
|
|
74
76
|
"react-native-safe-area-context": {
|
|
75
77
|
"optional": true
|
|
78
|
+
},
|
|
79
|
+
"@startsimpli/auth": {
|
|
80
|
+
"optional": true
|
|
81
|
+
},
|
|
82
|
+
"@startsimpli/utils": {
|
|
83
|
+
"optional": true
|
|
76
84
|
}
|
|
77
85
|
},
|
|
78
86
|
"devDependencies": {
|
|
@@ -92,7 +100,9 @@
|
|
|
92
100
|
"react-native-safe-area-context": "~5.7.0",
|
|
93
101
|
"@startsimpli/llm": "0.4.28",
|
|
94
102
|
"@startsimpli/ui": "0.4.167",
|
|
95
|
-
"@startsimpli/ui-native": "0.1.
|
|
103
|
+
"@startsimpli/ui-native": "0.1.3",
|
|
104
|
+
"@startsimpli/utils": "0.4.15",
|
|
105
|
+
"@startsimpli/auth": "0.4.47"
|
|
96
106
|
},
|
|
97
107
|
"scripts": {
|
|
98
108
|
"type-check": "tsc --noEmit && tsc --noEmit -p tsconfig.native.json",
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { useMemo, useSyncExternalStore, type ReactNode } from 'react';
|
|
2
|
-
import { View } from 'react-native';
|
|
1
|
+
import { useMemo, useState, useSyncExternalStore, type ReactNode } from 'react';
|
|
2
|
+
import { Pressable, Text, View } from 'react-native';
|
|
3
3
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
4
4
|
import { TabBar, useTheme, type TabItem } from '@startsimpli/ui-native';
|
|
5
5
|
import { createTabsNavigator, type Route, type TabsNavigator } from '../shell/navigator';
|
|
6
|
+
import { DEFAULT_MAX_VISIBLE, MORE_KEY, planTabs } from '../shell/overflow';
|
|
7
|
+
import { MoreTabList } from './MoreTabList';
|
|
6
8
|
|
|
7
9
|
/** What a tab's `render` is given. */
|
|
8
10
|
export interface TabContext {
|
|
@@ -23,6 +25,10 @@ export interface FoundryTab {
|
|
|
23
25
|
key: string;
|
|
24
26
|
label: string;
|
|
25
27
|
icon?: TabItem['icon'];
|
|
28
|
+
/** One line shown under the label when the tab sits in the More list. */
|
|
29
|
+
description?: string;
|
|
30
|
+
/** Higher stays in the bar when tabs overflow. Default 0; ties keep declared order. */
|
|
31
|
+
priority?: number;
|
|
26
32
|
render(ctx: TabContext): ReactNode;
|
|
27
33
|
/** Pad the top safe area for this tab. Default true; a screen that draws under the status bar sets false. */
|
|
28
34
|
safeArea?: boolean;
|
|
@@ -32,11 +38,16 @@ export interface FoundryTab {
|
|
|
32
38
|
|
|
33
39
|
export interface FoundryTabsShellProps {
|
|
34
40
|
tabs: FoundryTab[];
|
|
41
|
+
/** A tab key, or `more` to open the More list. */
|
|
35
42
|
initialTab?: string;
|
|
36
43
|
/** Open straight on one detail (implies its tab). From a launch arg or deep link. */
|
|
37
44
|
initialDetail?: { tab: string; id: string; params?: Record<string, unknown> };
|
|
38
45
|
/** Drive the shell from outside (warm deep links): `navigator.open(tab, {id})`. */
|
|
39
46
|
navigator?: TabsNavigator;
|
|
47
|
+
/** Bar slots, More included. Above this many tabs the rest go behind More. Default 5. */
|
|
48
|
+
maxVisible?: number;
|
|
49
|
+
/** Label of the overflow tab. Default "More". */
|
|
50
|
+
moreLabel?: string;
|
|
40
51
|
}
|
|
41
52
|
|
|
42
53
|
/**
|
|
@@ -44,7 +55,7 @@ export interface FoundryTabsShellProps {
|
|
|
44
55
|
* tab is mounted the first time it is shown and then kept mounted (hidden) so
|
|
45
56
|
* its state - and a recording on the GO tab - survives switching away.
|
|
46
57
|
*/
|
|
47
|
-
export function FoundryTabsShell({ tabs, initialTab, initialDetail, navigator }: FoundryTabsShellProps) {
|
|
58
|
+
export function FoundryTabsShell({ tabs, initialTab, initialDetail, navigator, maxVisible = DEFAULT_MAX_VISIBLE, moreLabel = 'More' }: FoundryTabsShellProps) {
|
|
48
59
|
const theme = useTheme();
|
|
49
60
|
const insets = useSafeAreaInsets();
|
|
50
61
|
const nav = useMemo(
|
|
@@ -54,10 +65,36 @@ export function FoundryTabsShell({ tabs, initialTab, initialDetail, navigator }:
|
|
|
54
65
|
[navigator],
|
|
55
66
|
);
|
|
56
67
|
const state = useSyncExternalStore(nav.subscribe, nav.getState, nav.getState);
|
|
68
|
+
const { primary, overflow } = useMemo(() => planTabs(tabs, maxVisible), [tabs, maxVisible]);
|
|
69
|
+
const overflowKeys = useMemo(() => new Set(overflow.map((t) => t.key)), [overflow]);
|
|
70
|
+
|
|
71
|
+
// The More list is open while `moreAt` still matches the navigator: any navigation that changes the
|
|
72
|
+
// active tab or replaces its stack (a bar tap, a deep link, openTab) closes it without extra wiring.
|
|
73
|
+
const [moreAt, setMoreAt] = useState<{ key: string; stack: Route[] } | null>(() => {
|
|
74
|
+
// `initialTab: 'more'` launches on the More list itself.
|
|
75
|
+
const s0 = nav.getState();
|
|
76
|
+
return initialTab === MORE_KEY && overflow.length ? { key: s0.activeKey, stack: s0.stacks[s0.activeKey] } : null;
|
|
77
|
+
});
|
|
78
|
+
const moreOpen = overflow.length > 0 && moreAt !== null && moreAt.key === state.activeKey && moreAt.stack === state.stacks[state.activeKey];
|
|
79
|
+
const markMore = () => { const s = nav.getState(); setMoreAt({ key: s.activeKey, stack: s.stacks[s.activeKey] }); };
|
|
80
|
+
const activeTab = tabs.find((t) => t.key === state.activeKey);
|
|
81
|
+
|
|
82
|
+
const openMore = () => {
|
|
83
|
+
// Going to the More list is leaving the current tab.
|
|
84
|
+
if (activeTab?.resetOnLeave && !moreOpen) nav.open(state.activeKey, null);
|
|
85
|
+
markMore();
|
|
86
|
+
};
|
|
87
|
+
const choose = (key: string) => { setMoreAt(null); nav.select(key); };
|
|
88
|
+
const inMore = moreOpen || overflowKeys.has(state.activeKey);
|
|
89
|
+
|
|
90
|
+
const items: TabItem[] = primary.map(({ key, label, icon }) => ({ key, label, icon }));
|
|
91
|
+
if (overflow.length) items.push({ key: MORE_KEY, label: moreLabel });
|
|
92
|
+
|
|
57
93
|
return (
|
|
58
94
|
<View style={{ flex: 1, backgroundColor: theme.colors.background }}>
|
|
95
|
+
{moreOpen ? <MoreTabList tabs={overflow} title={moreLabel} onOpen={choose} /> : null}
|
|
59
96
|
{tabs.filter((t) => state.visited.includes(t.key)).map((t) => {
|
|
60
|
-
const active = t.key === state.activeKey;
|
|
97
|
+
const active = t.key === state.activeKey && !moreOpen;
|
|
61
98
|
const route = state.stacks[t.key]?.slice(-1)[0] ?? null;
|
|
62
99
|
const ctx: TabContext = {
|
|
63
100
|
tab: t.key, active, route,
|
|
@@ -65,16 +102,27 @@ export function FoundryTabsShell({ tabs, initialTab, initialDetail, navigator }:
|
|
|
65
102
|
back: () => nav.pop(t.key),
|
|
66
103
|
openTab: (key, detailId) => (detailId ? nav.open(key, { id: detailId }) : nav.select(key)),
|
|
67
104
|
};
|
|
105
|
+
// A More tab at its list gets a Back to More strip; the strip carries the top inset instead of the tab.
|
|
106
|
+
const strip = overflowKeys.has(t.key) && !route;
|
|
107
|
+
const topPad = t.safeArea === false || strip ? 0 : insets.top;
|
|
68
108
|
return (
|
|
69
|
-
<View key={t.key} style={{ flex: 1, display: active ? 'flex' : 'none', paddingTop:
|
|
109
|
+
<View key={t.key} style={{ flex: 1, display: active ? 'flex' : 'none', paddingTop: topPad }}>
|
|
110
|
+
{strip ? (
|
|
111
|
+
<Pressable
|
|
112
|
+
testID="more-back" accessibilityRole="button" accessibilityLabel={`Back to ${moreLabel}`} onPress={openMore}
|
|
113
|
+
style={{ paddingTop: insets.top + theme.spacing.xs, paddingHorizontal: theme.spacing.md, paddingBottom: theme.spacing.xs }}
|
|
114
|
+
>
|
|
115
|
+
<Text numberOfLines={1} style={{ color: theme.colors.primary, fontSize: theme.fontSizes.base }}>{`\u2039 ${moreLabel}`}</Text>
|
|
116
|
+
</Pressable>
|
|
117
|
+
) : null}
|
|
70
118
|
{t.render(ctx)}
|
|
71
119
|
</View>
|
|
72
120
|
);
|
|
73
121
|
})}
|
|
74
122
|
<TabBar
|
|
75
|
-
items={
|
|
76
|
-
activeKey={state.activeKey}
|
|
77
|
-
onChange={(key) =>
|
|
123
|
+
items={items}
|
|
124
|
+
activeKey={inMore ? MORE_KEY : state.activeKey}
|
|
125
|
+
onChange={(key) => (key === MORE_KEY ? openMore() : choose(key))}
|
|
78
126
|
/>
|
|
79
127
|
</View>
|
|
80
128
|
);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
2
|
+
import { Pressable, ScrollView, Text, View } from 'react-native';
|
|
3
|
+
import { useTheme } from '@startsimpli/ui-native';
|
|
4
|
+
import type { FoundryTab } from './FoundryTabsShell';
|
|
5
|
+
|
|
6
|
+
/** The list behind the More tab: one row per overflow tab (icon, label, optional description). */
|
|
7
|
+
export function MoreTabList({ tabs, onOpen, title = 'More' }: { tabs: FoundryTab[]; onOpen(key: string): void; title?: string }) {
|
|
8
|
+
const theme = useTheme();
|
|
9
|
+
const insets = useSafeAreaInsets();
|
|
10
|
+
const { colors, spacing, fontSizes } = theme;
|
|
11
|
+
return (
|
|
12
|
+
<View style={{ flex: 1, backgroundColor: colors.background }} testID="more-list">
|
|
13
|
+
<Text accessibilityRole="header" style={{ color: colors.foreground, fontSize: fontSizes.xl, fontWeight: '700', padding: spacing.md, paddingTop: insets.top + spacing.md }}>{title}</Text>
|
|
14
|
+
<ScrollView>
|
|
15
|
+
{tabs.map((t) => (
|
|
16
|
+
<Pressable
|
|
17
|
+
key={t.key}
|
|
18
|
+
testID={`more-row-${t.key}`}
|
|
19
|
+
accessibilityRole="button"
|
|
20
|
+
accessibilityLabel={t.label}
|
|
21
|
+
onPress={() => onOpen(t.key)}
|
|
22
|
+
style={{ flexDirection: 'row', alignItems: 'center', gap: spacing.md, paddingHorizontal: spacing.md, paddingVertical: spacing.md, borderTopWidth: 1, borderTopColor: colors.border }}
|
|
23
|
+
>
|
|
24
|
+
{t.icon ? <View style={{ width: 28, alignItems: 'center' }}>{t.icon({ active: false, color: colors.mutedForeground })}</View> : null}
|
|
25
|
+
<View style={{ flex: 1 }}>
|
|
26
|
+
<Text numberOfLines={1} style={{ color: colors.foreground, fontSize: fontSizes.base }}>{t.label}</Text>
|
|
27
|
+
{t.description ? <Text numberOfLines={2} style={{ color: colors.mutedForeground, fontSize: fontSizes.sm }}>{t.description}</Text> : null}
|
|
28
|
+
</View>
|
|
29
|
+
<Text style={{ color: colors.mutedForeground, fontSize: fontSizes.lg }}>{'›'}</Text>
|
|
30
|
+
</Pressable>
|
|
31
|
+
))}
|
|
32
|
+
</ScrollView>
|
|
33
|
+
</View>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { Text } from 'react-native';
|
|
3
|
+
import { act, allText, hostById, maybeById, press, render } from '../../../../../ui-native/test/render';
|
|
4
|
+
import { FoundryTabsShell, type FoundryTab, type TabContext } from '../FoundryTabsShell';
|
|
5
|
+
import { createTabsNavigator } from '../../shell/navigator';
|
|
6
|
+
|
|
7
|
+
const mk = (key: string, extra: Partial<FoundryTab> = {}): FoundryTab => ({
|
|
8
|
+
key, label: key.toUpperCase(),
|
|
9
|
+
render: (ctx: TabContext) => <Text testID={`body-${key}`} onPress={() => ctx.push('d1')}>{`${key}:${ctx.route ? `detail ${ctx.route.id}` : 'list'}${ctx.active ? '' : ':hidden'}`}</Text>,
|
|
10
|
+
...extra,
|
|
11
|
+
});
|
|
12
|
+
const keys = ['home', 'go', 'notes', 'tracker', 'library', 'ask', 'planning'];
|
|
13
|
+
const tabs = (over: Record<string, Partial<FoundryTab>> = {}) => keys.map((k) => mk(k, over[k]));
|
|
14
|
+
const tabNodes = (r: ReturnType<typeof render>) => r.root.findAll((n) => n.type === 'Pressable' && n.props.accessibilityRole === 'tab');
|
|
15
|
+
const barLabels = (r: ReturnType<typeof render>) =>
|
|
16
|
+
tabNodes(r).map((n) => n.findAllByType('Text').at(-1)!.children.join(''));
|
|
17
|
+
const selected = (r: ReturnType<typeof render>) =>
|
|
18
|
+
tabNodes(r).filter((n) => n.props.accessibilityState?.selected).map((n) => n.findAllByType('Text').at(-1)!.children.join(''));
|
|
19
|
+
|
|
20
|
+
describe('FoundryTabsShell overflow', () => {
|
|
21
|
+
it('shows 4 tabs plus More when 7 tabs exceed the default 5', () => {
|
|
22
|
+
const r = render(<FoundryTabsShell tabs={tabs()} />);
|
|
23
|
+
expect(barLabels(r)).toEqual(['HOME', 'GO', 'NOTES', 'TRACKER', 'More']);
|
|
24
|
+
});
|
|
25
|
+
it('keeps every tab in the bar when they fit', () => {
|
|
26
|
+
const r = render(<FoundryTabsShell tabs={tabs().slice(0, 5)} />);
|
|
27
|
+
expect(barLabels(r)).toEqual(['HOME', 'GO', 'NOTES', 'TRACKER', 'LIBRARY']);
|
|
28
|
+
});
|
|
29
|
+
it('maxVisible and priority choose the bar', () => {
|
|
30
|
+
const r = render(<FoundryTabsShell tabs={tabs({ planning: { priority: 5 } })} maxVisible={4} />);
|
|
31
|
+
expect(barLabels(r)).toEqual(['HOME', 'GO', 'PLANNING', 'More']);
|
|
32
|
+
});
|
|
33
|
+
it('More lists the rest with descriptions, and opening one shows its content with Back to More', () => {
|
|
34
|
+
const r = render(<FoundryTabsShell tabs={tabs({ ask: { description: 'Ask your documents' } })} />);
|
|
35
|
+
press(tabNodes(r).at(-1)!);
|
|
36
|
+
expect(maybeById(r, 'more-list').length).toBe(1);
|
|
37
|
+
expect(allText(r)).toContain('Ask your documents');
|
|
38
|
+
expect(selected(r)).toEqual(['More']);
|
|
39
|
+
press(hostById(r, 'more-row-ask'));
|
|
40
|
+
expect(maybeById(r, 'more-list').length).toBe(0);
|
|
41
|
+
expect(allText(r)).toContain('ask:list');
|
|
42
|
+
expect(selected(r)).toEqual(['More']);
|
|
43
|
+
press(hostById(r, 'more-back'));
|
|
44
|
+
expect(maybeById(r, 'more-list').length).toBe(1);
|
|
45
|
+
});
|
|
46
|
+
it('a More tab keeps its list->detail stack and shows no Back to More while in detail', () => {
|
|
47
|
+
const r = render(<FoundryTabsShell tabs={tabs()} initialDetail={{ tab: 'library', id: 'd9' }} />);
|
|
48
|
+
expect(allText(r)).toContain('library:detail d9');
|
|
49
|
+
expect(selected(r)).toEqual(['More']);
|
|
50
|
+
expect(maybeById(r, 'more-back').length).toBe(0);
|
|
51
|
+
});
|
|
52
|
+
it('initialTab inside More opens that tab', () => {
|
|
53
|
+
const r = render(<FoundryTabsShell tabs={tabs()} initialTab="planning" />);
|
|
54
|
+
expect(allText(r)).toContain('planning:list');
|
|
55
|
+
expect(selected(r)).toEqual(['More']);
|
|
56
|
+
});
|
|
57
|
+
it('initialTab "more" opens the More list', () => {
|
|
58
|
+
const r = render(<FoundryTabsShell tabs={tabs()} initialTab="more" />);
|
|
59
|
+
expect(maybeById(r, 'more-list').length).toBe(1);
|
|
60
|
+
expect(selected(r)).toEqual(['More']);
|
|
61
|
+
});
|
|
62
|
+
it('a warm deep link into More leaves the More list and opens the detail', () => {
|
|
63
|
+
const list = tabs();
|
|
64
|
+
const navigator = createTabsNavigator({ tabs: list });
|
|
65
|
+
const r = render(<FoundryTabsShell tabs={list} navigator={navigator} />);
|
|
66
|
+
press(tabNodes(r).at(-1)!);
|
|
67
|
+
expect(maybeById(r, 'more-list').length).toBe(1);
|
|
68
|
+
act(() => navigator.open('ask', { id: 'x' }));
|
|
69
|
+
expect(maybeById(r, 'more-list').length).toBe(0);
|
|
70
|
+
expect(allText(r)).toContain('ask:detail x');
|
|
71
|
+
});
|
|
72
|
+
it('visited tabs stay mounted, hidden', () => {
|
|
73
|
+
const r = render(<FoundryTabsShell tabs={tabs()} initialTab="notes" />);
|
|
74
|
+
press(tabNodes(r).at(-1)!);
|
|
75
|
+
expect(allText(r)).toContain('notes:list:hidden');
|
|
76
|
+
});
|
|
77
|
+
it('resetOnLeave pops a More tab when the user goes to a bar tab', () => {
|
|
78
|
+
const r = render(<FoundryTabsShell tabs={tabs({ ask: { resetOnLeave: true } })} initialDetail={{ tab: 'ask', id: 'q' }} />);
|
|
79
|
+
expect(allText(r)).toContain('ask:detail q');
|
|
80
|
+
press(tabNodes(r)[0]);
|
|
81
|
+
expect(allText(r)).toContain('ask:list:hidden');
|
|
82
|
+
});
|
|
83
|
+
it('resetOnLeave also resets when the user taps More from a More tab', () => {
|
|
84
|
+
const r = render(<FoundryTabsShell tabs={tabs({ ask: { resetOnLeave: true } })} initialDetail={{ tab: 'ask', id: 'q' }} />);
|
|
85
|
+
press(tabNodes(r).at(-1)!);
|
|
86
|
+
expect(allText(r)).toContain('ask:list:hidden');
|
|
87
|
+
});
|
|
88
|
+
it('tapping a bar tab from the More list leaves the list', () => {
|
|
89
|
+
const r = render(<FoundryTabsShell tabs={tabs()} />);
|
|
90
|
+
press(tabNodes(r).at(-1)!);
|
|
91
|
+
press(tabNodes(r)[0]);
|
|
92
|
+
expect(maybeById(r, 'more-list').length).toBe(0);
|
|
93
|
+
expect(allText(r)).toContain('home:list');
|
|
94
|
+
});
|
|
95
|
+
it('openTab from a tab into a More tab works', () => {
|
|
96
|
+
const spy = vi.fn();
|
|
97
|
+
const r = render(<FoundryTabsShell tabs={[...tabs().slice(0, 3), mk('tracker', { render: (c) => <Text testID="go-ask" onPress={() => { spy(); c.openTab('ask', 'd4'); }}>t</Text> }), ...tabs().slice(4)]} initialTab="tracker" />);
|
|
98
|
+
press(hostById(r, 'go-ask'));
|
|
99
|
+
expect(allText(r)).toContain('ask:detail d4');
|
|
100
|
+
});
|
|
101
|
+
});
|
package/src/native/index.ts
CHANGED
|
@@ -14,7 +14,9 @@ export { NotesListScreen, type NotesListScreenProps } from './components/NotesLi
|
|
|
14
14
|
export { NoteDetailScreen, type NoteDetailScreenProps } from './components/NoteDetailScreen';
|
|
15
15
|
export { NotesShell, type NotesShellProps } from './components/NotesShell';
|
|
16
16
|
export { FoundryTabsShell, type FoundryTab, type FoundryTabsShellProps, type TabContext } from './components/FoundryTabsShell';
|
|
17
|
+
export * from './recording';
|
|
17
18
|
export * from './shell/navigator';
|
|
19
|
+
export * from './shell/overflow';
|
|
18
20
|
export * from './corpus/api';
|
|
19
21
|
export * from './corpus/ask';
|
|
20
22
|
export * from './corpus/paged';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createDeepLink } from '../deeplink';
|
|
3
|
+
|
|
4
|
+
function setup(phase: string = 'idle') {
|
|
5
|
+
const go = vi.fn().mockResolvedValue(undefined);
|
|
6
|
+
const link = createDeepLink({ getPhase: () => phase, go, log: vi.fn() });
|
|
7
|
+
return { link, go };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
describe('deep link tandemgo://record', () => {
|
|
11
|
+
it('waits for the session, then starts recording once', async () => {
|
|
12
|
+
const { link, go } = setup();
|
|
13
|
+
link.handle('tandemgo://record');
|
|
14
|
+
expect(go).not.toHaveBeenCalled();
|
|
15
|
+
await link.sessionReady();
|
|
16
|
+
expect(go).toHaveBeenCalledTimes(1);
|
|
17
|
+
await link.sessionReady();
|
|
18
|
+
expect(go).toHaveBeenCalledTimes(1);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('starts immediately when the session is already ready', async () => {
|
|
22
|
+
const { link, go } = setup();
|
|
23
|
+
await link.sessionReady();
|
|
24
|
+
link.handle('tandemgo://record');
|
|
25
|
+
await Promise.resolve();
|
|
26
|
+
expect(go).toHaveBeenCalledTimes(1);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('is ignored while already recording', async () => {
|
|
30
|
+
const { link, go } = setup('recording');
|
|
31
|
+
await link.sessionReady();
|
|
32
|
+
link.handle('tandemgo://record');
|
|
33
|
+
expect(go).not.toHaveBeenCalled();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('ignores other urls', async () => {
|
|
37
|
+
const { link, go } = setup();
|
|
38
|
+
await link.sessionReady();
|
|
39
|
+
link.handle('tandemgo://settings');
|
|
40
|
+
link.handle('https://example.com/record');
|
|
41
|
+
expect(go).not.toHaveBeenCalled();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('sign-out forgets readiness', async () => {
|
|
45
|
+
const { link, go } = setup();
|
|
46
|
+
await link.sessionReady();
|
|
47
|
+
link.sessionLost();
|
|
48
|
+
link.handle('tandemgo://record');
|
|
49
|
+
expect(go).not.toHaveBeenCalled();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('deep link autostop test hook', () => {
|
|
54
|
+
it('tandemgo://record?autostop=7 starts with a 7s autostop', async () => {
|
|
55
|
+
const { link, go } = setup();
|
|
56
|
+
await link.sessionReady();
|
|
57
|
+
link.handle('tandemgo://record?autostop=7');
|
|
58
|
+
await Promise.resolve();
|
|
59
|
+
expect(go).toHaveBeenCalledWith({ autostopSeconds: 7 });
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('plain record has no autostop', async () => {
|
|
63
|
+
const { link, go } = setup();
|
|
64
|
+
await link.sessionReady();
|
|
65
|
+
link.handle('tandemgo://record');
|
|
66
|
+
await Promise.resolve();
|
|
67
|
+
expect(go).toHaveBeenCalledWith({});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it.each(['autostop=abc', 'autostop=-3', 'autostop=0'])('ignores a bad value (%s) and stays manual', async (q) => {
|
|
71
|
+
const { link, go } = setup();
|
|
72
|
+
await link.sessionReady();
|
|
73
|
+
link.handle(`tandemgo://record?${q}`);
|
|
74
|
+
await Promise.resolve();
|
|
75
|
+
expect(go).toHaveBeenCalledWith({});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('a cold-start autostop link keeps its seconds until the session is ready', async () => {
|
|
79
|
+
const { link, go } = setup();
|
|
80
|
+
link.handle('tandemgo://record?autostop=12');
|
|
81
|
+
await link.sessionReady();
|
|
82
|
+
expect(go).toHaveBeenCalledWith({ autostopSeconds: 12 });
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('logs every link it receives, including ignored ones', async () => {
|
|
86
|
+
const log = vi.fn();
|
|
87
|
+
const link = createDeepLink({ getPhase: () => 'recording', go: vi.fn(), log });
|
|
88
|
+
await link.sessionReady();
|
|
89
|
+
link.handle('tandemgo://record');
|
|
90
|
+
expect(log).toHaveBeenCalledWith('deeplink', expect.objectContaining({ url: 'tandemgo://record', action: 'ignored-recording' }));
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createDiagnostics } from '../diagnostics';
|
|
3
|
+
|
|
4
|
+
describe('diagnostics', () => {
|
|
5
|
+
it('records structured entries and mirrors each as ONE greppable console line', () => {
|
|
6
|
+
const sink = vi.fn();
|
|
7
|
+
let t = 100;
|
|
8
|
+
const d = createDiagnostics({ sink, now: () => t++ });
|
|
9
|
+
d.log('record.start', { id: 'n1', sampleRate: 44100 });
|
|
10
|
+
expect(d.entries()).toEqual([{ t: 100, event: 'record.start', id: 'n1', sampleRate: 44100 }]);
|
|
11
|
+
const line = sink.mock.calls[0][0] as string;
|
|
12
|
+
expect(line.startsWith('[tandemgo] ')).toBe(true);
|
|
13
|
+
expect(JSON.parse(line.replace('[tandemgo] ', ''))).toEqual(d.entries()[0]);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('keeps only the newest N entries', () => {
|
|
17
|
+
const d = createDiagnostics({ sink: vi.fn(), max: 3 });
|
|
18
|
+
for (let i = 0; i < 5; i++) d.log('e', { i });
|
|
19
|
+
expect(d.entries().map((e) => e.i)).toEqual([2, 3, 4]);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('notifies subscribers and persists through the injected store', async () => {
|
|
23
|
+
let saved = '';
|
|
24
|
+
const d = createDiagnostics({ sink: vi.fn(), persist: async (v) => { saved = v; } });
|
|
25
|
+
const seen = vi.fn();
|
|
26
|
+
d.subscribe(seen);
|
|
27
|
+
d.log('x', {});
|
|
28
|
+
expect(seen).toHaveBeenCalledTimes(1);
|
|
29
|
+
await d.flush();
|
|
30
|
+
expect(JSON.parse(saved)).toHaveLength(1);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('never throws from a broken sink or store', async () => {
|
|
34
|
+
const d = createDiagnostics({ sink: () => { throw new Error('x'); }, persist: async () => { throw new Error('y'); } });
|
|
35
|
+
expect(() => d.log('x', {})).not.toThrow();
|
|
36
|
+
await expect(d.flush()).resolves.toBeUndefined();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('never logs secrets: password/token/authorization fields are redacted', () => {
|
|
40
|
+
const d = createDiagnostics({ sink: vi.fn() });
|
|
41
|
+
d.log('x', { password: 'p', accessToken: 'a', Authorization: 'Bearer z', ok: 1 });
|
|
42
|
+
expect(JSON.stringify(d.entries())).not.toMatch(/Bearer z|"p"|"a"/);
|
|
43
|
+
expect(d.entries()[0].ok).toBe(1);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('keeps entries from earlier launches: the persisted log is loaded before the first write', async () => {
|
|
47
|
+
const writes: string[] = [];
|
|
48
|
+
const d = createDiagnostics({
|
|
49
|
+
sink: vi.fn(),
|
|
50
|
+
now: () => 2,
|
|
51
|
+
load: async () => JSON.stringify([{ t: 1, event: 'old' }]),
|
|
52
|
+
persist: async (v) => { writes.push(v); },
|
|
53
|
+
});
|
|
54
|
+
d.log('new');
|
|
55
|
+
await d.flush();
|
|
56
|
+
expect(JSON.parse(writes[writes.length - 1]).map((e: { event: string }) => e.event)).toEqual(['old', 'new']);
|
|
57
|
+
expect(d.entries().map((e) => e.event)).toEqual(['old', 'new']);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('a missing, corrupt or failing persisted log never breaks logging', async () => {
|
|
61
|
+
for (const load of [async () => null, async () => 'not json', async () => { throw new Error('io'); }]) {
|
|
62
|
+
const writes: string[] = [];
|
|
63
|
+
const d = createDiagnostics({ sink: vi.fn(), load, persist: async (v) => { writes.push(v); } });
|
|
64
|
+
d.log('x');
|
|
65
|
+
await d.flush();
|
|
66
|
+
expect(JSON.parse(writes[writes.length - 1])).toHaveLength(1);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('respects max across old and new entries', async () => {
|
|
71
|
+
const d = createDiagnostics({
|
|
72
|
+
sink: vi.fn(), max: 3,
|
|
73
|
+
load: async () => JSON.stringify([{ t: 1, event: 'a' }, { t: 2, event: 'b' }, { t: 3, event: 'c' }]),
|
|
74
|
+
persist: async () => undefined,
|
|
75
|
+
});
|
|
76
|
+
d.log('d');
|
|
77
|
+
await d.flush();
|
|
78
|
+
expect(d.entries().map((e) => e.event)).toEqual(['b', 'c', 'd']);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** jest-expo's FormData is Node's; the device has React Native's. A fake that records appended parts. */
|
|
2
|
+
export class FakeForm {
|
|
3
|
+
parts: Array<{ fieldName: string; string?: string; uri?: string; type?: string; name?: string }> = [];
|
|
4
|
+
append(name: string, value: unknown, filename?: string) {
|
|
5
|
+
if (filename !== undefined) this.parts.push({ fieldName: name, name: filename, blob: value } as never);
|
|
6
|
+
else if (typeof value === 'string') this.parts.push({ fieldName: name, string: value });
|
|
7
|
+
else this.parts.push({ fieldName: name, ...(value as object) });
|
|
8
|
+
}
|
|
9
|
+
getParts() { return this.parts; }
|
|
10
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createUploadQueue } from '@startsimpli/utils';
|
|
3
|
+
import { createNotes } from '../notes';
|
|
4
|
+
import { createRecorder } from '../recorder';
|
|
5
|
+
import { FakeForm } from './fakeForm';
|
|
6
|
+
|
|
7
|
+
// Recorder + real shared queue + notes.upload with a flaky network: the same
|
|
8
|
+
// noteId is sent on every attempt, the file is deleted once, after the 2xx.
|
|
9
|
+
describe('offline then online', () => {
|
|
10
|
+
it('queues while offline and sends exactly once with the same noteId', async () => {
|
|
11
|
+
let online = false;
|
|
12
|
+
const seenIds: string[] = [];
|
|
13
|
+
const authorizedFetch = vi.fn(async (_url: string, init: { body: { getParts(): Array<{ fieldName: string; string?: string }> } }) => {
|
|
14
|
+
if (!online) throw new TypeError('Network request failed');
|
|
15
|
+
seenIds.push(init.body.getParts().find((p) => p.fieldName === 'noteId')!.string!);
|
|
16
|
+
return { ok: true, status: 202, json: async () => ({}) } as Response;
|
|
17
|
+
});
|
|
18
|
+
const notes = createNotes({ tandemUrl: 'http://t', authorizedFetch: authorizedFetch as never, createForm: () => new FakeForm() as never });
|
|
19
|
+
let saved: string | null = null;
|
|
20
|
+
const removed: string[] = [];
|
|
21
|
+
let now = 0;
|
|
22
|
+
const queue = createUploadQueue({
|
|
23
|
+
store: { read: async () => saved, write: async (v) => { saved = v; } },
|
|
24
|
+
upload: (job) => notes.upload({ id: job.id, uri: job.uri, durationMs: job.durationMs ?? 0 }),
|
|
25
|
+
removeFile: async (job) => { removed.push(job.uri); },
|
|
26
|
+
now: () => now,
|
|
27
|
+
});
|
|
28
|
+
const recorder = createRecorder({
|
|
29
|
+
audio: { start: async () => undefined, stop: async () => ({ uri: 'file:///d/x.m4a', durationMs: 900 }) },
|
|
30
|
+
send: (file) => queue.enqueue(file),
|
|
31
|
+
newId: () => 'fixed-note-id',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
await recorder.go();
|
|
35
|
+
await recorder.stop();
|
|
36
|
+
expect(recorder.getState().phase).toBe('queued');
|
|
37
|
+
expect(removed).toEqual([]);
|
|
38
|
+
|
|
39
|
+
online = true;
|
|
40
|
+
now += 60_000;
|
|
41
|
+
await queue.drain();
|
|
42
|
+
await queue.drain();
|
|
43
|
+
expect(seenIds).toEqual(['fixed-note-id']);
|
|
44
|
+
expect(removed).toEqual(['file:///d/x.m4a']);
|
|
45
|
+
expect(await queue.pending()).toEqual([]);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createLevelTracker, meterFraction, NO_AUDIO_FLOOR_DB, isSilent } from '../levels';
|
|
3
|
+
|
|
4
|
+
describe('levels', () => {
|
|
5
|
+
it('tracks peak and RMS (RMS averaged in linear power, not in dB)', () => {
|
|
6
|
+
const t = createLevelTracker();
|
|
7
|
+
[-60, -20, -10].forEach((db) => t.push(db));
|
|
8
|
+
const s = t.summary();
|
|
9
|
+
expect(s.peakDb).toBe(-10);
|
|
10
|
+
const lin = (db: number) => 10 ** (db / 10);
|
|
11
|
+
const expected = 10 * Math.log10((lin(-60) + lin(-20) + lin(-10)) / 3);
|
|
12
|
+
expect(s.rmsDb).toBeCloseTo(expected, 5);
|
|
13
|
+
expect(s.samples).toBe(3);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('no samples = floor values, flagged silent', () => {
|
|
17
|
+
const s = createLevelTracker().summary();
|
|
18
|
+
expect(s.samples).toBe(0);
|
|
19
|
+
expect(isSilent(s)).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('silent when the peak never rises above the floor; speech is not silent', () => {
|
|
23
|
+
const quiet = createLevelTracker();
|
|
24
|
+
[-80, -70, NO_AUDIO_FLOOR_DB - 1].forEach((d) => quiet.push(d));
|
|
25
|
+
expect(isSilent(quiet.summary())).toBe(true);
|
|
26
|
+
const talk = createLevelTracker();
|
|
27
|
+
[-80, -25, -40].forEach((d) => talk.push(d));
|
|
28
|
+
expect(isSilent(talk.summary())).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('meterFraction maps dB to 0..1 and clamps', () => {
|
|
32
|
+
expect(meterFraction(0)).toBe(1);
|
|
33
|
+
expect(meterFraction(-160)).toBe(0);
|
|
34
|
+
expect(meterFraction(-200)).toBe(0);
|
|
35
|
+
expect(meterFraction(10)).toBe(1);
|
|
36
|
+
expect(meterFraction(-30)).toBeGreaterThan(meterFraction(-50));
|
|
37
|
+
});
|
|
38
|
+
});
|