('react-router-dom');
+ return {
+ ...actual,
+ useNavigate: () => navigateMock,
+ };
+});
+
+vi.mock('../context/AppContext', () => ({
+ useAppContext: () => ({
+ botState: {
+ symbols: {},
+ alerts: [],
+ positions: [],
+ orders: [],
+ history: [],
+ settings: {
+ executionMode: 'Paper',
+ riskPerTrade: 0.01,
+ totalCapital: 1000,
+ maxOpenTrades: 3,
+ isAlgoEnabled: true,
+ enabledRules: [],
+ },
+ uptime: 1000,
+ },
+ }),
+}));
+
+vi.mock('../tabs/PositionsTab', () => ({
+ PositionsTab: ({ onManageHolding }: any) => (
+
+
+
+
+ ),
+}));
+
+vi.mock('../tabs/HistoryTab', () => ({
+ HistoryTab: () => History tab
,
+}));
+
+describe('PortfolioView navigation', () => {
+ it('navigates to the canonical plans route for exact plan drill-in and new exit plans', async () => {
+ const user = userEvent.setup();
+ render(
+
+
+ ,
+ );
+
+ await user.click(screen.getByRole('button', { name: 'open linked plan' }));
+ expect(navigateMock).toHaveBeenCalledWith('/plans?setupId=setup-aapl');
+
+ await user.click(screen.getByRole('button', { name: 'create exit plan' }));
+ expect(navigateMock).toHaveBeenCalledWith('/plans?mode=sell&symbol=MSFT&tradeId=TRD-MSFT');
+ });
+});