import { fireEvent, render, screen } from '@testing-library/react'; import { MemoryRouter, Route, Routes, useLocation, useNavigate } from 'react-router-dom'; import { describe, expect, it } from 'vitest'; import { LegacyPluginRedirect, PluginWorkspaceRedirect, PROJECT_SETTINGS_PLUGINS_PATH, } from '@/pages/Plugins/legacy-plugin-redirect'; import { getGuardedAiModuleForPath, isProgrammingProviderRoute } from '@/lib/ai-modules'; function LocationProbe() { const location = useLocation(); const navigate = useNavigate(); return (
{location.pathname}{location.search}
); } describe('plugin navigation cutover', () => { it.each([ ['/plugin-marketplace', `${PROJECT_SETTINGS_PLUGINS_PATH}?scope=all&source=all&state=available`], ['/my-plugins', `${PROJECT_SETTINGS_PLUGINS_PATH}?scope=all&state=mine`], ['/project-plugins', `${PROJECT_SETTINGS_PLUGINS_PATH}?scope=project&state=mine`], ] as const)('replace-redirects %s to %s', async (legacy, canonical) => { render( } /> } /> previous} /> , ); expect(await screen.findByTestId('location')).toHaveTextContent(canonical); fireEvent.click(screen.getByRole('button', { name: '返回' })); expect(await screen.findByTestId('previous')).toBeVisible(); }); it('moves the former canonical URL into project settings without losing its query', async () => { render( } /> } /> previous} /> , ); expect(await screen.findByTestId('location')).toHaveTextContent( `${PROJECT_SETTINGS_PLUGINS_PATH}?scope=all&state=mine`, ); fireEvent.click(screen.getByRole('button', { name: '返回' })); expect(await screen.findByTestId('previous')).toBeVisible(); }); it('classifies the project-settings plugin page as Code without making it provider-gated', () => { expect(getGuardedAiModuleForPath(PROJECT_SETTINGS_PLUGINS_PATH)).toBe('programming'); expect(isProgrammingProviderRoute(PROJECT_SETTINGS_PLUGINS_PATH)).toBe(false); }); });