From 307228656c9af601b85195c1764e4863e71f8e68 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 4 Feb 2026 10:24:41 +0000
Subject: [PATCH] Add tests for auth-based conditional rendering in FileManager
Co-authored-by: cadtoolbox <12723486+cadtoolbox@users.noreply.github.com>
---
.../__tests__/pages/FileManagerPage.test.tsx | 111 ++++++++++++++++++
1 file changed, 111 insertions(+)
diff --git a/frontend/src/__tests__/pages/FileManagerPage.test.tsx b/frontend/src/__tests__/pages/FileManagerPage.test.tsx
index df89253da..66a166353 100644
--- a/frontend/src/__tests__/pages/FileManagerPage.test.tsx
+++ b/frontend/src/__tests__/pages/FileManagerPage.test.tsx
@@ -614,4 +614,115 @@ describe('FileManagerPage', () => {
});
});
});
+
+ describe('authentication-based UI changes', () => {
+ it('hides "Uploaded By" column and user filter when auth is disabled', async () => {
+ // Mock auth disabled (default)
+ server.use(
+ http.get('*/api/v1/auth/status', () => {
+ return HttpResponse.json({
+ auth_enabled: false,
+ requires_setup: false,
+ });
+ }),
+ http.get('/api/v1/library/files', () => {
+ return HttpResponse.json([
+ {
+ id: 1,
+ filename: 'test.3mf',
+ file_path: '/library/test.3mf',
+ file_size: 1048576,
+ file_type: '3mf',
+ folder_id: null,
+ thumbnail_path: null,
+ print_name: 'Test File',
+ print_time_seconds: 3600,
+ print_count: 0,
+ duplicate_count: 0,
+ created_at: '2024-01-01T00:00:00Z',
+ created_by_username: 'testuser',
+ },
+ ]);
+ })
+ );
+
+ render();
+
+ // Switch to list view to see the column headers
+ await waitFor(() => {
+ expect(screen.getByText('Test File')).toBeInTheDocument();
+ });
+
+ const user = userEvent.setup();
+ const listViewButton = screen.getByRole('button', { name: /list/i });
+ await user.click(listViewButton);
+
+ // "Uploaded By" column header should not be present
+ await waitFor(() => {
+ expect(screen.queryByText('Uploaded By')).not.toBeInTheDocument();
+ });
+
+ // User filter dropdown should not be present
+ expect(screen.queryByPlaceholderText('Filter by user')).not.toBeInTheDocument();
+ });
+
+ it('shows "Uploaded By" column and user filter when auth is enabled', async () => {
+ // Mock auth enabled
+ server.use(
+ http.get('*/api/v1/auth/status', () => {
+ return HttpResponse.json({
+ auth_enabled: true,
+ requires_setup: false,
+ });
+ }),
+ http.get('/api/v1/library/files', () => {
+ return HttpResponse.json([
+ {
+ id: 1,
+ filename: 'test.3mf',
+ file_path: '/library/test.3mf',
+ file_size: 1048576,
+ file_type: '3mf',
+ folder_id: null,
+ thumbnail_path: null,
+ print_name: 'Test File',
+ print_time_seconds: 3600,
+ print_count: 0,
+ duplicate_count: 0,
+ created_at: '2024-01-01T00:00:00Z',
+ created_by_username: 'testuser',
+ },
+ ]);
+ }),
+ http.get('/api/v1/users/', () => {
+ return HttpResponse.json([
+ { id: 1, username: 'testuser' },
+ { id: 2, username: 'admin' },
+ ]);
+ })
+ );
+
+ render();
+
+ // Switch to list view to see the column headers
+ await waitFor(() => {
+ expect(screen.getByText('Test File')).toBeInTheDocument();
+ });
+
+ const user = userEvent.setup();
+ const listViewButton = screen.getByRole('button', { name: /list/i });
+ await user.click(listViewButton);
+
+ // "Uploaded By" column header should be present
+ await waitFor(() => {
+ expect(screen.getByText('Uploaded By')).toBeInTheDocument();
+ });
+
+ // User filter dropdown should be present
+ expect(screen.getByPlaceholderText('Filter by user')).toBeInTheDocument();
+
+ // Username should be displayed in the column
+ expect(screen.getByText('testuser')).toBeInTheDocument();
+ });
+ });
});