gloomberb 0.4.0 → 0.5.0
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 -2
- package/package.json +1 -1
- package/src/app.tsx +184 -69
- package/src/cli/commands/ticker.ts +45 -15
- package/src/cli/helpers.ts +4 -2
- package/src/cli/registry.test.ts +42 -35
- package/src/cli.test.ts +4 -2
- package/src/components/chart/chart-control-hint.tsx +39 -0
- package/src/components/chart/chart-controller.test.ts +110 -0
- package/src/components/chart/chart-controller.ts +364 -2
- package/src/components/chart/chart-data.ts +177 -29
- package/src/components/chart/chart-indicator-selector.tsx +53 -0
- package/src/components/chart/chart-pane-settings.ts +20 -0
- package/src/components/chart/chart-renderer.ts +220 -30
- package/src/components/chart/chart-resolution.test.ts +67 -0
- package/src/components/chart/chart-resolution.ts +74 -4
- package/src/components/chart/chart-scroll.test.ts +69 -0
- package/src/components/chart/chart-scroll.ts +104 -0
- package/src/components/chart/chart-types.ts +12 -0
- package/src/components/chart/chart-viewport.test.ts +5 -1
- package/src/components/chart/chart-viewport.ts +1 -1
- package/src/components/chart/chart.test.ts +249 -10
- package/src/components/chart/comparison-chart-renderer.test.ts +71 -1
- package/src/components/chart/comparison-chart-renderer.ts +40 -3
- package/src/components/chart/comparison-stock-chart.tsx +218 -123
- package/src/components/chart/indicators/bands.test.ts +50 -0
- package/src/components/chart/indicators/bands.ts +29 -0
- package/src/components/chart/indicators/moving-averages.test.ts +54 -0
- package/src/components/chart/indicators/moving-averages.ts +42 -0
- package/src/components/chart/indicators/options.test.ts +32 -0
- package/src/components/chart/indicators/options.ts +107 -0
- package/src/components/chart/indicators/oscillators.test.ts +79 -0
- package/src/components/chart/indicators/oscillators.ts +92 -0
- package/src/components/chart/indicators/types.ts +36 -0
- package/src/components/chart/native/chart-rasterizer.ts +51 -0
- package/src/components/chart/native/kitty.test.ts +68 -0
- package/src/components/chart/stock-chart-renderer-switch.test.tsx +740 -9
- package/src/components/chart/stock-chart.test.ts +239 -0
- package/src/components/chart/stock-chart.tsx +2257 -372
- package/src/components/command-bar/command-bar.test.tsx +337 -5
- package/src/components/command-bar/command-bar.tsx +296 -120
- package/src/components/command-bar/helpers.ts +1 -1
- package/src/components/command-bar/root-shortcuts.ts +33 -4
- package/src/components/command-bar/view-model.test.ts +3 -3
- package/src/components/command-bar/view-model.ts +4 -4
- package/src/components/command-bar/workflow-ops.ts +10 -0
- package/src/components/layout/floating-pane.tsx +3 -1
- package/src/components/layout/header.tsx +5 -4
- package/src/components/layout/pane-sizing.ts +6 -0
- package/src/components/layout/pane.tsx +5 -1
- package/src/components/layout/shell.test.tsx +263 -32
- package/src/components/layout/shell.tsx +10 -6
- package/src/components/layout/status-bar.test.tsx +16 -7
- package/src/components/layout/status-bar.tsx +4 -1
- package/src/components/markdown-editor.tsx +1 -0
- package/src/components/pane-settings-dialog.tsx +13 -152
- package/src/components/pane-template-wizard.tsx +1 -0
- package/src/components/price-selector-dialog.tsx +12 -7
- package/src/components/ticker-badge-text.test.tsx +50 -0
- package/src/components/ticker-badge-text.tsx +17 -2
- package/src/components/ticker-badge.tsx +2 -2
- package/src/components/ticker-list-table.tsx +62 -2
- package/src/components/toggle-list.tsx +15 -2
- package/src/components/ui/data-table.tsx +82 -5
- package/src/components/ui/external-link.tsx +48 -11
- package/src/components/ui/fields.tsx +2 -1
- package/src/components/ui/index.ts +8 -1
- package/src/components/ui/multi-select-chips.tsx +69 -0
- package/src/components/ui/multi-select-dialog.tsx +267 -0
- package/src/components/ui/multi-select.ts +78 -0
- package/src/components/ui/ui.test.tsx +343 -1
- package/src/data/plugin-state-store.ts +30 -19
- package/src/data/resource-store.ts +133 -103
- package/src/data/session-store.ts +19 -12
- package/src/data/sqlite-cache.test.ts +37 -2
- package/src/data/sqlite-database.ts +8 -2
- package/src/data/sqlite-retry.test.ts +63 -0
- package/src/data/sqlite-retry.ts +66 -0
- package/src/data/ticker-store.ts +29 -18
- package/src/index.tsx +6 -1
- package/src/market-data/coordinator.test.ts +114 -5
- package/src/market-data/coordinator.ts +70 -1
- package/src/market-data/hooks.test.tsx +73 -2
- package/src/market-data/hooks.tsx +16 -4
- package/src/notifications/app-notifier.test.ts +177 -0
- package/src/notifications/app-notifier.ts +241 -0
- package/src/pane-settings.test.ts +2 -0
- package/src/plugins/builtin/ai/index.test.tsx +1 -1
- package/src/plugins/builtin/ai/screener-pane.test.tsx +2 -0
- package/src/plugins/builtin/ai/screener-pane.tsx +1 -0
- package/src/plugins/builtin/ai/ticker-context.ts +3 -2
- package/src/plugins/builtin/alerts/alert-engine.test.ts +90 -0
- package/src/plugins/builtin/alerts/alert-engine.ts +55 -0
- package/src/plugins/builtin/alerts/index.test.tsx +357 -0
- package/src/plugins/builtin/alerts/index.tsx +519 -0
- package/src/plugins/builtin/alerts/types.ts +14 -0
- package/src/plugins/builtin/analytics/index.test.tsx +300 -0
- package/src/plugins/builtin/analytics/index.tsx +775 -0
- package/src/plugins/builtin/analytics/metrics.test.ts +125 -0
- package/src/plugins/builtin/analytics/metrics.ts +155 -0
- package/src/plugins/builtin/ask-ai.test.tsx +2 -0
- package/src/plugins/builtin/chat-controller.test.ts +92 -18
- package/src/plugins/builtin/chat-controller.ts +40 -11
- package/src/plugins/builtin/chat.test.tsx +715 -4
- package/src/plugins/builtin/chat.tsx +420 -119
- package/src/plugins/builtin/comparison-chart.test.tsx +97 -57
- package/src/plugins/builtin/comparison-chart.tsx +1 -2
- package/src/plugins/builtin/correlation/compute.test.ts +147 -0
- package/src/plugins/builtin/correlation/compute.ts +115 -0
- package/src/plugins/builtin/correlation/index.tsx +385 -0
- package/src/plugins/builtin/correlation/plugin.test.ts +44 -0
- package/src/plugins/builtin/correlation/settings.test.ts +34 -0
- package/src/plugins/builtin/correlation/settings.ts +95 -0
- package/src/plugins/builtin/debug.tsx +36 -50
- package/src/plugins/builtin/earnings/earnings-cache.test.ts +181 -0
- package/src/plugins/builtin/earnings/earnings-cache.ts +136 -0
- package/src/plugins/builtin/earnings/earnings-data.test.ts +59 -0
- package/src/plugins/builtin/earnings/earnings-data.ts +50 -0
- package/src/plugins/builtin/earnings/index.tsx +337 -0
- package/src/plugins/builtin/econ/calendar-source.test.ts +219 -0
- package/src/plugins/builtin/econ/calendar-source.ts +121 -0
- package/src/plugins/builtin/econ/fred-client.test.ts +63 -0
- package/src/plugins/builtin/econ/fred-client.ts +79 -0
- package/src/plugins/builtin/econ/fred-series-map.ts +88 -0
- package/src/plugins/builtin/econ/index.tsx +999 -0
- package/src/plugins/builtin/econ/types.ts +13 -0
- package/src/plugins/builtin/fred-settings.ts +10 -0
- package/src/plugins/builtin/fx-matrix/index.tsx +178 -0
- package/src/plugins/builtin/fx-matrix/pairs.ts +30 -0
- package/src/plugins/builtin/help.test.tsx +1 -5
- package/src/plugins/builtin/help.tsx +1 -16
- package/src/plugins/builtin/insider/index.tsx +417 -0
- package/src/plugins/builtin/insider/insider-data.test.ts +55 -0
- package/src/plugins/builtin/insider/insider-data.ts +49 -0
- package/src/plugins/builtin/layout-manager.tsx +33 -16
- package/src/plugins/builtin/market-movers/index.tsx +573 -0
- package/src/plugins/builtin/market-movers/screener.test.ts +143 -0
- package/src/plugins/builtin/market-movers/screener.ts +105 -0
- package/src/plugins/builtin/options.tsx +4 -3
- package/src/plugins/builtin/portfolio-list/cli/commands.ts +11 -6
- package/src/plugins/builtin/portfolio-list/command-bar.ts +6 -3
- package/src/plugins/builtin/portfolio-list/header.tsx +3 -2
- package/src/plugins/builtin/portfolio-list/metrics.ts +22 -11
- package/src/plugins/builtin/portfolio-list/pane.tsx +3 -9
- package/src/plugins/builtin/portfolio-list/settings.ts +9 -0
- package/src/plugins/builtin/portfolio-list/table.tsx +3 -0
- package/src/plugins/builtin/portfolio-list.test.tsx +3 -1
- package/src/plugins/builtin/portfolio-metrics.test.ts +13 -1
- package/src/plugins/builtin/sec.tsx +114 -7
- package/src/plugins/builtin/sectors/index.tsx +359 -0
- package/src/plugins/builtin/sectors/sector-data.ts +18 -0
- package/src/plugins/builtin/ticker-detail/chart-tab.tsx +75 -13
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +316 -80
- package/src/plugins/builtin/ticker-detail/quote-monitor.tsx +4 -6
- package/src/plugins/builtin/ticker-detail-chart-tab-switch.test.tsx +17 -12
- package/src/plugins/builtin/ticker-detail.test.tsx +3 -3
- package/src/plugins/builtin/world-indices/index.tsx +410 -0
- package/src/plugins/builtin/world-indices/indices.ts +52 -0
- package/src/plugins/builtin/yield-curve/index.tsx +242 -0
- package/src/plugins/builtin/yield-curve/treasury-data.test.ts +212 -0
- package/src/plugins/builtin/yield-curve/treasury-data.ts +107 -0
- package/src/plugins/catalog.ts +22 -0
- package/src/plugins/gridlock-notification.ts +15 -0
- package/src/plugins/ibkr/__snapshots__/trade-tab.test.tsx.snap +5 -5
- package/src/plugins/ibkr/gateway-service.test.ts +22 -0
- package/src/plugins/ibkr/gateway-service.ts +6 -0
- package/src/plugins/ibkr/index.test.tsx +1 -1
- package/src/plugins/ibkr/index.tsx +8 -2
- package/src/plugins/ibkr/trade-tab.tsx +23 -5
- package/src/plugins/ibkr/trade-utils.test.ts +1 -1
- package/src/plugins/ibkr/trade-utils.ts +7 -6
- package/src/plugins/ibkr/trading-pane.tsx +8 -7
- package/src/plugins/plugin-runtime.test.tsx +2 -0
- package/src/plugins/plugin-runtime.tsx +10 -0
- package/src/plugins/prediction-markets/controller-data.ts +129 -14
- package/src/plugins/prediction-markets/controller.ts +1 -1
- package/src/plugins/prediction-markets/detail/shared.tsx +7 -6
- package/src/plugins/prediction-markets/index.tsx +5 -1
- package/src/plugins/prediction-markets/pane.test.tsx +78 -0
- package/src/plugins/prediction-markets/pane.tsx +7 -3
- package/src/plugins/prediction-markets/plugin.test.tsx +48 -1
- package/src/plugins/prediction-markets/services/fetch.ts +17 -7
- package/src/plugins/prediction-markets/services/polymarket-adapter.ts +29 -11
- package/src/plugins/prediction-markets/services/polymarket-ws.ts +20 -0
- package/src/plugins/prediction-markets/test-helpers.tsx +22 -5
- package/src/plugins/registry.ts +45 -13
- package/src/sources/provider-router.test.ts +3 -2
- package/src/sources/sec-edgar.ts +13 -1
- package/src/sources/yahoo-finance.ts +75 -1
- package/src/state/app-context-selector.test.tsx +17 -1
- package/src/state/app-context.test.tsx +24 -0
- package/src/state/app-context.tsx +29 -6
- package/src/theme/colors.ts +5 -0
- package/src/theme/themes.ts +25 -0
- package/src/types/config.test.ts +107 -0
- package/src/types/config.ts +30 -1
- package/src/types/data-provider.ts +13 -0
- package/src/types/plugin.ts +35 -1
- package/src/updater.test.ts +2 -0
- package/src/utils/api-client.ts +12 -0
- package/src/utils/format.test.ts +11 -1
- package/src/utils/format.ts +86 -8
- package/src/utils/inline-content-tokenizer.test.ts +22 -0
- package/src/utils/inline-content-tokenizer.ts +76 -0
- package/src/utils/link-tokenizer.test.ts +27 -0
- package/src/utils/link-tokenizer.ts +93 -0
- package/src/utils/market-format.test.ts +109 -0
- package/src/utils/market-format.ts +299 -0
- package/src/utils/market-status.ts +3 -2
- package/src/utils/selection-clipboard.test.ts +43 -0
- package/src/utils/selection-clipboard.ts +88 -0
- package/src/utils/terminal-input-reset.test.ts +50 -0
- package/src/utils/terminal-input-reset.ts +24 -0
- package/src/utils/throttled-fetch.test.ts +145 -0
- package/src/utils/throttled-fetch.ts +212 -0
- package/src/utils/ticker-tokenizer.test.ts +31 -0
- package/src/utils/ticker-tokenizer.ts +7 -42
- package/src/version.ts +1 -1
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { act, useReducer } from "react";
|
|
3
|
+
import { testRender } from "@opentui/react/test-utils";
|
|
4
|
+
import {
|
|
5
|
+
AppContext,
|
|
6
|
+
PaneInstanceProvider,
|
|
7
|
+
appReducer,
|
|
8
|
+
createInitialState,
|
|
9
|
+
type AppState,
|
|
10
|
+
} from "../../../state/app-context";
|
|
11
|
+
import { cloneLayout, createDefaultConfig, type AppConfig } from "../../../types/config";
|
|
12
|
+
import { PluginRenderProvider, type PluginRuntimeAccess } from "../../plugin-runtime";
|
|
13
|
+
import { setSharedRegistryForTests } from "../../registry";
|
|
14
|
+
import { deserializeAlerts, serializeAlerts } from "./alert-engine";
|
|
15
|
+
import { AlertsPane, alertsPlugin } from "./index";
|
|
16
|
+
import type { AlertCondition, AlertRule, AlertStatus } from "./types";
|
|
17
|
+
|
|
18
|
+
const TEST_PANE_ID = "alerts:test";
|
|
19
|
+
|
|
20
|
+
let testSetup: Awaited<ReturnType<typeof testRender>> | undefined;
|
|
21
|
+
let harnessState: AppState | null = null;
|
|
22
|
+
let harnessDispatch: ((action: any) => void) | null = null;
|
|
23
|
+
|
|
24
|
+
function makeAlert(
|
|
25
|
+
id: string,
|
|
26
|
+
symbol: string,
|
|
27
|
+
condition: AlertCondition,
|
|
28
|
+
targetPrice: number,
|
|
29
|
+
status: AlertStatus = "active",
|
|
30
|
+
): AlertRule {
|
|
31
|
+
return {
|
|
32
|
+
id,
|
|
33
|
+
symbol,
|
|
34
|
+
condition,
|
|
35
|
+
targetPrice,
|
|
36
|
+
createdAt: 1_700_000_000_000,
|
|
37
|
+
status,
|
|
38
|
+
triggeredAt: status === "triggered" ? Date.now() - 30_000 : undefined,
|
|
39
|
+
lastCheckedPrice: status === "triggered" ? targetPrice + 1 : undefined,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function createAlertsConfig(alerts: AlertRule[]): AppConfig {
|
|
44
|
+
const baseConfig = createDefaultConfig("/tmp/gloomberb-alerts");
|
|
45
|
+
const layout: AppConfig["layout"] = {
|
|
46
|
+
dockRoot: { kind: "pane", instanceId: TEST_PANE_ID },
|
|
47
|
+
instances: [{
|
|
48
|
+
instanceId: TEST_PANE_ID,
|
|
49
|
+
paneId: "alerts",
|
|
50
|
+
binding: { kind: "none" },
|
|
51
|
+
}],
|
|
52
|
+
floating: [],
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
...baseConfig,
|
|
57
|
+
layout,
|
|
58
|
+
layouts: [{ name: "Default", layout: cloneLayout(layout) }],
|
|
59
|
+
pluginConfig: {
|
|
60
|
+
...baseConfig.pluginConfig,
|
|
61
|
+
alerts: {
|
|
62
|
+
alerts: serializeAlerts(alerts),
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function makeRuntime(): PluginRuntimeAccess {
|
|
69
|
+
const resumeState = new Map<string, unknown>();
|
|
70
|
+
const listeners = new Map<string, Set<() => void>>();
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
pinTicker() {},
|
|
74
|
+
navigateTicker() {},
|
|
75
|
+
subscribeResumeState(pluginId, key, listener) {
|
|
76
|
+
const storeKey = `${pluginId}:${key}`;
|
|
77
|
+
if (!listeners.has(storeKey)) listeners.set(storeKey, new Set());
|
|
78
|
+
listeners.get(storeKey)!.add(listener);
|
|
79
|
+
return () => listeners.get(storeKey)?.delete(listener);
|
|
80
|
+
},
|
|
81
|
+
getResumeState(pluginId, key) {
|
|
82
|
+
return (resumeState.get(`${pluginId}:${key}`) as any) ?? null;
|
|
83
|
+
},
|
|
84
|
+
setResumeState(pluginId, key, value) {
|
|
85
|
+
const storeKey = `${pluginId}:${key}`;
|
|
86
|
+
resumeState.set(storeKey, value);
|
|
87
|
+
for (const listener of listeners.get(storeKey) ?? []) listener();
|
|
88
|
+
},
|
|
89
|
+
deleteResumeState(pluginId, key) {
|
|
90
|
+
const storeKey = `${pluginId}:${key}`;
|
|
91
|
+
resumeState.delete(storeKey);
|
|
92
|
+
for (const listener of listeners.get(storeKey) ?? []) listener();
|
|
93
|
+
},
|
|
94
|
+
getConfigState(pluginId, key) {
|
|
95
|
+
return (harnessState?.config.pluginConfig[pluginId]?.[key] as any) ?? null;
|
|
96
|
+
},
|
|
97
|
+
async setConfigState(pluginId, key, value) {
|
|
98
|
+
const currentState = harnessState!;
|
|
99
|
+
harnessDispatch?.({
|
|
100
|
+
type: "SET_CONFIG",
|
|
101
|
+
config: {
|
|
102
|
+
...currentState.config,
|
|
103
|
+
pluginConfig: {
|
|
104
|
+
...currentState.config.pluginConfig,
|
|
105
|
+
[pluginId]: {
|
|
106
|
+
...(currentState.config.pluginConfig[pluginId] ?? {}),
|
|
107
|
+
[key]: value,
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
async deleteConfigState(pluginId, key) {
|
|
114
|
+
const currentState = harnessState!;
|
|
115
|
+
const currentPluginConfig = { ...(currentState.config.pluginConfig[pluginId] ?? {}) };
|
|
116
|
+
delete currentPluginConfig[key];
|
|
117
|
+
const pluginConfig = { ...currentState.config.pluginConfig };
|
|
118
|
+
if (Object.keys(currentPluginConfig).length === 0) delete pluginConfig[pluginId];
|
|
119
|
+
else pluginConfig[pluginId] = currentPluginConfig;
|
|
120
|
+
harnessDispatch?.({
|
|
121
|
+
type: "SET_CONFIG",
|
|
122
|
+
config: {
|
|
123
|
+
...currentState.config,
|
|
124
|
+
pluginConfig,
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
},
|
|
128
|
+
getConfigStateKeys(pluginId) {
|
|
129
|
+
return Object.keys(harnessState?.config.pluginConfig[pluginId] ?? {}).sort();
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function AlertsHarness({
|
|
135
|
+
alerts,
|
|
136
|
+
width = 110,
|
|
137
|
+
height = 12,
|
|
138
|
+
}: {
|
|
139
|
+
alerts: AlertRule[];
|
|
140
|
+
width?: number;
|
|
141
|
+
height?: number;
|
|
142
|
+
}) {
|
|
143
|
+
const initialState = createInitialState(createAlertsConfig(alerts));
|
|
144
|
+
initialState.focusedPaneId = TEST_PANE_ID;
|
|
145
|
+
const [state, dispatch] = useReducer(appReducer, initialState);
|
|
146
|
+
harnessState = state;
|
|
147
|
+
harnessDispatch = dispatch;
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<AppContext value={{ state, dispatch }}>
|
|
151
|
+
<PaneInstanceProvider paneId={TEST_PANE_ID}>
|
|
152
|
+
<PluginRenderProvider pluginId="alerts" runtime={makeRuntime()}>
|
|
153
|
+
<AlertsPane focused width={width} height={height} />
|
|
154
|
+
</PluginRenderProvider>
|
|
155
|
+
</PaneInstanceProvider>
|
|
156
|
+
</AppContext>
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function renderSettled(): Promise<void> {
|
|
161
|
+
await act(async () => {
|
|
162
|
+
await testSetup!.renderOnce();
|
|
163
|
+
await testSetup!.renderOnce();
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function clickFrameText(text: string): Promise<void> {
|
|
168
|
+
const frame = testSetup!.captureCharFrame();
|
|
169
|
+
const rows = frame.split("\n");
|
|
170
|
+
const row = rows.findIndex((line) => line.includes(text));
|
|
171
|
+
const col = row >= 0 ? rows[row]!.indexOf(text) : -1;
|
|
172
|
+
|
|
173
|
+
expect(row).toBeGreaterThanOrEqual(0);
|
|
174
|
+
expect(col).toBeGreaterThanOrEqual(0);
|
|
175
|
+
|
|
176
|
+
await act(async () => {
|
|
177
|
+
await testSetup!.mockMouse.click(col + 1, row);
|
|
178
|
+
await testSetup!.renderOnce();
|
|
179
|
+
await testSetup!.renderOnce();
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function storedAlerts(): AlertRule[] {
|
|
184
|
+
const value = (harnessState?.config.pluginConfig.alerts as any)?.alerts;
|
|
185
|
+
expect(typeof value).toBe("string");
|
|
186
|
+
return JSON.parse(value);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
afterEach(() => {
|
|
190
|
+
setSharedRegistryForTests(undefined);
|
|
191
|
+
harnessState = null;
|
|
192
|
+
harnessDispatch = null;
|
|
193
|
+
if (testSetup) {
|
|
194
|
+
testSetup.renderer.destroy();
|
|
195
|
+
testSetup = undefined;
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe("AlertsPane", () => {
|
|
200
|
+
test("renders alerts in a data table with action hints only in the footer", async () => {
|
|
201
|
+
testSetup = await testRender(
|
|
202
|
+
<AlertsHarness
|
|
203
|
+
alerts={[
|
|
204
|
+
makeAlert("alert-aapl", "AAPL", "above", 200),
|
|
205
|
+
makeAlert("alert-msft", "MSFT", "below", 300, "triggered"),
|
|
206
|
+
]}
|
|
207
|
+
/>,
|
|
208
|
+
{ width: 110, height: 12 },
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
await renderSettled();
|
|
212
|
+
const frame = testSetup.captureCharFrame();
|
|
213
|
+
|
|
214
|
+
expect(frame).toContain("Status");
|
|
215
|
+
expect(frame).toContain("Symbol");
|
|
216
|
+
expect(frame).toContain("Condition");
|
|
217
|
+
expect(frame).toContain("AAPL");
|
|
218
|
+
expect(frame).toContain("MSFT");
|
|
219
|
+
expect(frame).toContain("[a]dd alert");
|
|
220
|
+
expect(frame).toContain("[d]elete");
|
|
221
|
+
expect(frame).not.toContain("Add Alert");
|
|
222
|
+
expect(frame).not.toContain("Enter");
|
|
223
|
+
expect(frame).not.toContain("Esc");
|
|
224
|
+
expect(frame).not.toContain("move field");
|
|
225
|
+
expect(frame).not.toContain("change condition");
|
|
226
|
+
expect(frame).not.toContain("↑/↓");
|
|
227
|
+
expect(frame).not.toContain("←/→");
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test("keeps alert targets visible at the default floating pane width", async () => {
|
|
231
|
+
testSetup = await testRender(
|
|
232
|
+
<AlertsHarness
|
|
233
|
+
width={65}
|
|
234
|
+
height={8}
|
|
235
|
+
alerts={[makeAlert("alert-aapl", "AAPL", "above", 200)]}
|
|
236
|
+
/>,
|
|
237
|
+
{ width: 65, height: 8 },
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
await renderSettled();
|
|
241
|
+
const frame = testSetup.captureCharFrame();
|
|
242
|
+
|
|
243
|
+
expect(frame).toContain("Status");
|
|
244
|
+
expect(frame).toContain("Condition");
|
|
245
|
+
expect(frame).toContain("Target");
|
|
246
|
+
expect(frame).toContain("200");
|
|
247
|
+
expect(frame).toContain("[a]dd alert");
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test("opens the command-bar alert workflow from keyboard and mouse", async () => {
|
|
251
|
+
const workflowCalls: string[] = [];
|
|
252
|
+
setSharedRegistryForTests({
|
|
253
|
+
openPluginCommandWorkflow(commandId: string) {
|
|
254
|
+
workflowCalls.push(commandId);
|
|
255
|
+
},
|
|
256
|
+
} as any);
|
|
257
|
+
|
|
258
|
+
testSetup = await testRender(<AlertsHarness alerts={[]} />, {
|
|
259
|
+
width: 110,
|
|
260
|
+
height: 12,
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
await renderSettled();
|
|
264
|
+
await act(async () => {
|
|
265
|
+
await testSetup!.mockInput.typeText("a");
|
|
266
|
+
await testSetup!.renderOnce();
|
|
267
|
+
});
|
|
268
|
+
await clickFrameText("[a]");
|
|
269
|
+
|
|
270
|
+
expect(workflowCalls).toEqual(["set-alert", "set-alert"]);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test("updates alerts from table action clicks", async () => {
|
|
274
|
+
testSetup = await testRender(
|
|
275
|
+
<AlertsHarness
|
|
276
|
+
alerts={[
|
|
277
|
+
makeAlert("alert-aapl", "AAPL", "above", 200),
|
|
278
|
+
makeAlert("alert-msft", "MSFT", "below", 300, "triggered"),
|
|
279
|
+
]}
|
|
280
|
+
/>,
|
|
281
|
+
{ width: 110, height: 12 },
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
await renderSettled();
|
|
285
|
+
await clickFrameText("Re-arm");
|
|
286
|
+
|
|
287
|
+
expect(storedAlerts().find((alert) => alert.id === "alert-msft")?.status).toBe("active");
|
|
288
|
+
|
|
289
|
+
await clickFrameText("[d]");
|
|
290
|
+
|
|
291
|
+
expect(storedAlerts().map((alert) => alert.id)).toEqual(["alert-msft"]);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
describe("alertsPlugin command", () => {
|
|
296
|
+
test("registers a searchable add command with direct shortcut arguments", async () => {
|
|
297
|
+
const store = new Map<string, unknown>();
|
|
298
|
+
const commands: any[] = [];
|
|
299
|
+
const notifications: any[] = [];
|
|
300
|
+
const ctx = {
|
|
301
|
+
registerCommand(command: any) {
|
|
302
|
+
commands.push(command);
|
|
303
|
+
},
|
|
304
|
+
registerPane() {},
|
|
305
|
+
registerPaneTemplate() {},
|
|
306
|
+
configState: {
|
|
307
|
+
get(key: string) {
|
|
308
|
+
return store.get(key);
|
|
309
|
+
},
|
|
310
|
+
set(key: string, value: unknown) {
|
|
311
|
+
store.set(key, value);
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
dataProvider: {
|
|
315
|
+
getQuote: async () => null,
|
|
316
|
+
},
|
|
317
|
+
notify(notification: any) {
|
|
318
|
+
notifications.push(notification);
|
|
319
|
+
},
|
|
320
|
+
log: {
|
|
321
|
+
info() {},
|
|
322
|
+
warn() {},
|
|
323
|
+
error() {},
|
|
324
|
+
},
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
try {
|
|
328
|
+
alertsPlugin.setup(ctx as any);
|
|
329
|
+
const command = commands.find((entry) => entry.id === "set-alert");
|
|
330
|
+
|
|
331
|
+
expect(command?.label).toBe("Add Alert");
|
|
332
|
+
expect(command?.keywords).toContain("add");
|
|
333
|
+
expect(command?.shortcut).toBe("SA");
|
|
334
|
+
expect(command?.shortcutArg?.placeholder).toBe("symbol condition price");
|
|
335
|
+
expect(command?.shortcutArg?.parse("AMD")).toEqual({ symbol: "AMD" });
|
|
336
|
+
expect(command?.shortcutArg?.parse("AMD above 200")).toEqual({
|
|
337
|
+
symbol: "AMD",
|
|
338
|
+
condition: "above",
|
|
339
|
+
price: "200",
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
await command.execute({ shortcut: "AAPL above 200" });
|
|
343
|
+
|
|
344
|
+
const alerts = deserializeAlerts(String(store.get("alerts")));
|
|
345
|
+
expect(alerts).toHaveLength(1);
|
|
346
|
+
expect(alerts[0]).toMatchObject({
|
|
347
|
+
symbol: "AAPL",
|
|
348
|
+
condition: "above",
|
|
349
|
+
targetPrice: 200,
|
|
350
|
+
status: "active",
|
|
351
|
+
});
|
|
352
|
+
expect(notifications[0]?.body).toContain("AAPL");
|
|
353
|
+
} finally {
|
|
354
|
+
alertsPlugin.dispose?.();
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
});
|