import pytest import asyncio from playwright.async_api import expect @pytest.mark.asyncio class TestFileManagement: async def test_01_upload_file(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'e2etestuser') await page.fill('#login-form input[name="password"]', 'testpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) # Upload a file await page.set_input_files('input[type="file"]', { 'name': 'test-file.txt', 'mimeType': 'text/plain', 'buffer': b'This is a test file for e2e testing.' }) await page.click('button:has-text("Upload")') await page.wait_for_timeout(2000) await expect(page.locator('text=test-file.txt')).to_be_visible() async def test_02_create_folder(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'e2etestuser') await page.fill('#login-form input[name="password"]', 'testpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) # Click create folder button await page.click('button:has-text("New Folder")') await page.wait_for_timeout(500) # Fill folder name await page.fill('input[placeholder="Folder name"]', 'Test Folder') await page.click('button:has-text("Create")') await page.wait_for_timeout(1000) await expect(page.locator('text=Test Folder')).to_be_visible() async def test_03_navigate_into_folder(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'e2etestuser') await page.fill('#login-form input[name="password"]', 'testpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) # Click on the folder await page.click('text=Test Folder') await page.wait_for_timeout(1000) # Should be in the folder, breadcrumb should show it await expect(page.locator('.breadcrumb')).to_contain_text('Test Folder') async def test_04_upload_file_in_folder(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'e2etestuser') await page.fill('#login-form input[name="password"]', 'testpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) # Navigate to folder await page.click('text=Test Folder') await page.wait_for_timeout(1000) # Upload file in folder await page.set_input_files('input[type="file"]', { 'name': 'folder-file.txt', 'mimeType': 'text/plain', 'buffer': b'This file is in a folder.' }) await page.click('button:has-text("Upload")') await page.wait_for_timeout(2000) await expect(page.locator('text=folder-file.txt')).to_be_visible() async def test_05_navigate_back_from_folder(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'e2etestuser') await page.fill('#login-form input[name="password"]', 'testpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) # Navigate to folder await page.click('text=Test Folder') await page.wait_for_timeout(1000) # Click breadcrumb to go back await page.click('.breadcrumb a:first-child') await page.wait_for_timeout(1000) # Should be back in root await expect(page.locator('text=Test Folder')).to_be_visible() await expect(page.locator('text=test-file.txt')).to_be_visible() async def test_06_select_and_delete_file(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'e2etestuser') await page.fill('#login-form input[name="password"]', 'testpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) # Select file await page.click('.file-item:has-text("test-file.txt") .file-checkbox') await page.wait_for_timeout(500) # Click delete await page.click('button:has-text("Delete")') await page.wait_for_timeout(500) # Confirm delete await page.click('button:has-text("Confirm")') await page.wait_for_timeout(1000) # File should be gone await expect(page.locator('text=test-file.txt')).not_to_be_visible() async def test_07_restore_deleted_file(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'e2etestuser') await page.fill('#login-form input[name="password"]', 'testpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) # Go to deleted files await page.click('a.nav-link[data-view="deleted"]') await page.wait_for_timeout(1000) # Select deleted file await page.click('.file-item:has-text("test-file.txt") .file-checkbox') await page.wait_for_timeout(500) # Click restore await page.click('button:has-text("Restore")') await page.wait_for_timeout(1000) # Go back to files await page.click('a.nav-link[data-view="files"]') await page.wait_for_timeout(1000) # File should be back await expect(page.locator('text=test-file.txt')).to_be_visible() async def test_08_rename_folder(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'e2etestuser') await page.fill('#login-form input[name="password"]', 'testpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) # Right-click on folder or use context menu await page.click('.folder-item:has-text("Test Folder")', button='right') await page.wait_for_timeout(500) # Click rename await page.click('text=Rename') await page.wait_for_timeout(500) # Fill new name await page.fill('input[placeholder="New name"]', 'Renamed Folder') await page.click('button:has-text("Rename")') await page.wait_for_timeout(1000) await expect(page.locator('text=Renamed Folder')).to_be_visible() await expect(page.locator('text=Test Folder')).not_to_be_visible() async def test_09_star_file(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'e2etestuser') await page.fill('#login-form input[name="password"]', 'testpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) # Click star on file await page.click('.file-item:has-text("test-file.txt") .star-btn') await page.wait_for_timeout(1000) # Go to starred await page.click('a.nav-link[data-view="starred"]') await page.wait_for_timeout(1000) await expect(page.locator('text=test-file.txt')).to_be_visible() async def test_10_search_files(self, page, base_url): await page.goto(f"{base_url}/") await page.wait_for_load_state("networkidle") await page.fill('#login-form input[name="username"]', 'e2etestuser') await page.fill('#login-form input[name="password"]', 'testpassword123') await page.click('#login-form button[type="submit"]') await page.wait_for_timeout(2000) # Type in search await page.fill('#search-input', 'test-file') await page.wait_for_timeout(1000) # Should show search results await expect(page.locator('.search-results')).to_be_visible() await expect(page.locator('text=test-file.txt')).to_be_visible()