Skip to content

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

test: add test files for logout and account panel components

Steven Enamakel08649470430a
diff --git a/app/src/components/settings/__tests__/LogoutAndClearActions.test.tsx b/app/src/components/settings/__tests__/LogoutAndClearActions.test.tsx
index a3477f77cd..6bcf67b6da 100644
--- a/app/src/components/settings/__tests__/LogoutAndClearActions.test.tsx
+++ b/app/src/components/settings/__tests__/LogoutAndClearActions.test.tsx
@@ -34,12 +34,14 @@ describe('LogoutAndClearActions', () => {
mockClearAllAppData.mockReset().mockResolvedValue(undefined);
});
- it('renders log out as a row and clearing data as a separate destructive zone', () => {
+ it('renders log out in a Session card and clearing data in a separate danger zone', () => {
renderActions();
// The two used to be adjacent rows with the same amber, weight and icon.
- // Clearing data is now its own zone with its own button, so the assertion
+ // Clearing data is now its own card with its own button, so the assertion
// checks the split rather than just that both strings exist.
- expect(screen.getByText('Log out')).toBeInTheDocument();
+ expect(screen.getByText('Session')).toBeInTheDocument();
+ expect(screen.getByTestId('settings-nav-logout')).toHaveTextContent('Log out');
+ expect(screen.getByText('Danger zone')).toBeInTheDocument();
expect(screen.getByText('Clear app data')).toBeInTheDocument();
expect(screen.getByTestId('account-destructive-zone')).toBeInTheDocument();
expect(screen.getByTestId('settings-nav-logout-and-clear')).toHaveTextContent('Clear data');
@@ -94,10 +96,34 @@ describe('LogoutAndClearActions', () => {
mockClearSession.mockRejectedValueOnce(new Error('backend unreachable'));
renderActions();
- await user.click(screen.getByText('Log out').closest('button')!);
+ await user.click(screen.getByTestId('settings-nav-logout'));
const alert = await screen.findByTestId('logout-error');
- expect(alert).toHaveTextContent(/sign-in failed|failed to log out|/i); // tolerant
+ expect(alert).toHaveTextContent('Failed to log out. Please try again.');
expect(alert).toBeVisible();
});
+
+ it('closes the confirm dialog on Cancel without clearing anything', async () => {
+ const user = userEvent.setup();
+ renderActions();
+
+ await user.click(screen.getByTestId('settings-nav-logout-and-clear'));
+ expect(screen.getByRole('alertdialog')).toBeInTheDocument();
+ await user.click(screen.getByRole('button', { name: 'Cancel' }));
+
+ expect(screen.queryByRole('alertdialog')).not.toBeInTheDocument();
+ expect(mockClearAllAppData).not.toHaveBeenCalled();
+ });
+
+ it('keeps the confirm dialog open and shows the error when clearing fails', async () => {
+ const user = userEvent.setup();
+ mockClearAllAppData.mockRejectedValueOnce(new Error('disk busy'));
+ renderActions();
+
+ await user.click(screen.getByTestId('settings-nav-logout-and-clear'));
+ await user.click(screen.getByRole('button', { name: 'Clear app data' }));
+
+ expect(await screen.findByText('disk busy')).toBeInTheDocument();
+ expect(screen.getByRole('alertdialog')).toBeInTheDocument();
+ });
});
diff --git a/app/src/components/settings/panels/AccountPanel.test.tsx b/app/src/components/settings/panels/AccountPanel.test.tsx
index 3198589efa..067f89c550 100644
--- a/app/src/components/settings/panels/AccountPanel.test.tsx
+++ b/app/src/components/settings/panels/AccountPanel.test.tsx
@@ -12,6 +12,9 @@ vi.mock('../../../utils/openUrl', () => ({
const useCoreStateMock = vi.fn();
vi.mock('../../../providers/CoreStateProvider', () => ({ useCoreState: () => useCoreStateMock() }));
+const useUsageStateMock = vi.fn();
+vi.mock('../../../hooks/useUsageState', () => ({ useUsageState: () => useUsageStateMock() }));
+
vi.mock('../hooks/useSettingsNavigation', () => ({
useSettingsNavigation: () => ({
navigateBack: vi.fn(),
@@ -32,6 +35,7 @@ function renderPanel(currentUser: Record<string, unknown> | null) {
describe('AccountPanel', () => {
beforeEach(() => {
vi.clearAllMocks();
+ useUsageStateMock.mockReturnValue({ currentPlan: null });
});
it('renders the avatar initial and full name for a signed-in user', () => {
@@ -41,7 +45,7 @@ describe('AccountPanel', () => {
expect(screen.getByText('@ada')).toBeInTheDocument();
// Avatar fallback renders the first letter of the display name.
expect(screen.getByText('A')).toBeInTheDocument();
- fireEvent.click(screen.getByRole('button', { name: 'Billing' }));
+ fireEvent.click(screen.getByRole('button', { name: 'Open dashboard' }));
expect(openUrlMock).toHaveBeenCalledWith('https://tinyhumans.ai/dashboard?tab=billing');
});
@@ -56,6 +60,23 @@ describe('AccountPanel', () => {
renderPanel(null);
expect(screen.queryByText('@')).not.toBeInTheDocument();
- expect(screen.queryByRole('button', { name: 'Billing' })).not.toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: 'Open dashboard' })).not.toBeInTheDocument();
+ expect(screen.queryByTestId('account-profile')).not.toBeInTheDocument();
+ });
+
+ it('shows the live plan from billing, falling back to the snapshot subscription', () => {
+ useUsageStateMock.mockReturnValue({ currentPlan: { plan: 'PRO' } });
+ renderPanel({ firstName: 'Ada', username: 'ada', subscription: { plan: 'FREE' } });
+ expect(screen.getByTestId('account-plan')).toHaveTextContent('Pro');
+ });
+
+ it('uses the snapshot subscription plan until the live plan loads', () => {
+ renderPanel({ firstName: 'Ada', username: 'ada', subscription: { plan: 'BASIC' } });
+ expect(screen.getByTestId('account-plan')).toHaveTextContent('Basic');
+ });
+
+ it('omits the plan badge when no plan is known', () => {
+ renderPanel({ firstName: 'Ada', username: 'ada' });
+ expect(screen.queryByTestId('account-plan')).not.toBeInTheDocument();
});
});
diff --git a/app/src/components/settings/panels/__tests__/AccountPanel.test.tsx b/app/src/components/settings/panels/__tests__/AccountPanel.test.tsx
index aecc9d1226..cdd3d33853 100644
--- a/app/src/components/settings/panels/__tests__/AccountPanel.test.tsx
+++ b/app/src/components/settings/panels/__tests__/AccountPanel.test.tsx
@@ -17,6 +17,10 @@ vi.mock('../../../../providers/CoreStateProvider', () => ({
useCoreState: () => mockUseCoreState(),
}));
+vi.mock('../../../../hooks/useUsageState', () => ({
+ useUsageState: () => ({ currentPlan: null }),
+}));
+
// Isolate the panel from the destructive logout/clear actions (which pull in
// session + clear-data plumbing we don't exercise here).
vi.mock('../../LogoutAndClearActions', () => ({