102 lines
3.9 KiB
Python
Raw Normal View History

2025-11-09 10:02:10 +01:00
import pytest
BASE_URL = "http://127.0.0.1:8080"
@pytest.mark.asyncio
async def test_file_operations(page):
# Login first
await page.goto(f"{BASE_URL}/login")
await page.fill("#email", "testuser@example.com")
await page.fill("#password", "password123")
await page.click("button[type=submit]")
await page.wait_for_url("**/dashboard")
# Navigate to My Files
await page.click("text=My Files")
await page.wait_for_url("**/files")
# Create a new folder
await page.click("#new-folder-btn")
await page.fill("input[name=folder_name]", "TestFolder")
await page.click("button[type=submit]")
await page.wait_for_load_state("networkidle")
assert "TestFolder" in await page.text_content()
# Upload multiple files
await page.click("#upload-btn")
await page.set_input_files("#file-input-multiple", ["testfile.txt", "testfile2.txt"])
await page.click("#start-upload-btn")
await page.wait_for_load_state("networkidle")
assert "testfile.txt" in await page.text_content()
assert "testfile2.txt" in await page.text_content()
# Add one file to favorites
await page.click("button.favorite-btn[data-name='testfile.txt']")
await page.wait_for_load_state("networkidle")
# Assert favorite icon changed or something, but hard, perhaps check in favorites later
# Share multiple files
await page.check("input[type=checkbox][data-name='testfile.txt']")
await page.check("input[type=checkbox][data-name='testfile2.txt']")
await page.click("#share-selected-btn")
await page.wait_for_selector("#share-modal", state="visible")
await page.wait_for_selector("#share-link-input")
share_link = await page.input_value("#share-link-input")
assert share_link.startswith(BASE_URL)
await page.click("#share-modal .close")
# Navigate to Shared
await page.click("text=Shared")
await page.wait_for_url("**/shared")
await page.wait_for_load_state("networkidle")
# Assert shared files are there
assert "testfile.txt" in await page.text_content()
assert "testfile2.txt" in await page.text_content()
# Navigate to Recent
await page.click("text=Recent")
await page.wait_for_url("**/recent")
await page.wait_for_load_state("networkidle")
# Assert recent files
assert "testfile.txt" in await page.text_content()
# Navigate to Favorites
await page.click("text=Favorites")
await page.wait_for_url("**/favorites")
await page.wait_for_selector("text=testfile.txt")
assert "testfile.txt" in await page.text_content()
# Move file to trash from favorites
await page.click("button.delete-file-btn[data-name='testfile.txt']")
await page.click("#delete-modal button[type=submit]")
await page.wait_for_load_state("networkidle")
# Should not be in favorites anymore
assert "testfile.txt" not in await page.text_content()
# Navigate to Trash
await page.click("text=Trash")
await page.wait_for_url("**/trash")
await page.wait_for_selector("text=testfile.txt")
assert "testfile.txt" in await page.text_content()
# Permanently delete from trash
await page.click("button.permanent-delete-btn[data-name='testfile.txt']")
await page.click("#delete-modal button[type=submit]")
await page.wait_for_load_state("networkidle")
assert "testfile.txt" not in await page.text_content()
# Navigate back to Files
await page.click("text=My Files")
await page.wait_for_url("**/files")
# Delete the remaining file
await page.click("button.delete-file-btn[data-name='testfile2.txt']")
await page.click("#delete-modal button[type=submit]")
await page.wait_for_load_state("networkidle")
assert "testfile2.txt" not in await page.text_content()
# Delete the folder
await page.click("button.delete-file-btn[data-name='TestFolder']")
await page.click("#delete-modal button[type=submit]")
await page.wait_for_load_state("networkidle")
assert "TestFolder" not in await page.text_content()