feat: unify plugin workspace navigation
This commit is contained in:
43
tests/unit/plugin-navigation.test.tsx
Normal file
43
tests/unit/plugin-navigation.test.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
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 } from '@/pages/Plugins/legacy-plugin-redirect';
|
||||
import { getGuardedAiModuleForPath, isProgrammingProviderRoute } from '@/lib/ai-modules';
|
||||
|
||||
function LocationProbe() {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
return (
|
||||
<div>
|
||||
<output data-testid="location">{location.pathname}{location.search}</output>
|
||||
<button type="button" onClick={() => navigate(-1)}>返回</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
describe('plugin navigation cutover', () => {
|
||||
it.each([
|
||||
['/plugin-marketplace', '/plugins?scope=all&source=official'],
|
||||
['/my-plugins', '/plugins?scope=all&state=mine'],
|
||||
['/project-plugins', '/plugins?scope=project'],
|
||||
] as const)('replace-redirects %s to %s', async (legacy, canonical) => {
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/previous', legacy]} initialIndex={1}>
|
||||
<Routes>
|
||||
<Route path={legacy} element={<LegacyPluginRedirect from={legacy} />} />
|
||||
<Route path="/plugins" element={<LocationProbe />} />
|
||||
<Route path="/previous" element={<output data-testid="previous">previous</output>} />
|
||||
</Routes>
|
||||
</MemoryRouter>,
|
||||
);
|
||||
|
||||
expect(await screen.findByTestId('location')).toHaveTextContent(canonical);
|
||||
fireEvent.click(screen.getByRole('button', { name: '返回' }));
|
||||
expect(await screen.findByTestId('previous')).toBeVisible();
|
||||
});
|
||||
|
||||
it('classifies the canonical page as Code without making it provider-gated', () => {
|
||||
expect(getGuardedAiModuleForPath('/plugins')).toBe('programming');
|
||||
expect(isProgrammingProviderRoute('/plugins')).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user