Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(brain-redirect): add test for redirect when brain is missing

Steven Enamakela29bc0247c6c
diff --git a/app/src/components/routing/BrainRedirect.test.tsx b/app/src/components/routing/BrainRedirect.test.tsx
new file mode 100644
index 0000000000..fdb86e8f08
--- /dev/null
+++ b/app/src/components/routing/BrainRedirect.test.tsx
@@ -0,0 +1,38 @@
+import { render, screen } from '@testing-library/react';
+import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
+import { describe, expect, it } from 'vitest';
+
+import BrainRedirect from './BrainRedirect';
+
+function Where() {
+ const { pathname, search, hash } = useLocation();
+ return <div data-testid="where">{`${pathname}${search}${hash}`}</div>;
+}
+
+function renderAt(entry: string) {
+ render(
+ <MemoryRouter initialEntries={[entry]}>
+ <Routes>
+ <Route path="/brain" element={<BrainRedirect />} />
+ <Route path="/connections" element={<Where />} />
+ </Routes>
+ </MemoryRouter>
+ );
+ return screen.getByTestId('where').textContent;
+}
+
+describe('BrainRedirect', () => {
+ it('lands bare /brain on the Brain tab of Connections', () => {
+ expect(renderAt('/brain')).toBe('/connections?tab=brain');
+ });
+
+ it('moves the old ?tab= sub-tab to ?brain=', () => {
+ expect(renderAt('/brain?tab=sources')).toBe('/connections?tab=brain&brain=sources');
+ });
+
+ it('keeps other params and the hash', () => {
+ expect(renderAt('/brain?tab=sync&view=history#x')).toBe(
+ '/connections?tab=brain&brain=sync&view=history#x'
+ );
+ });
+});