import pytest import asyncio from playwright.async_api import expect @pytest.mark.asyncio class TestPhotoGallery: async def test_01_upload_image_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 an image file await page.set_input_files('input[type="file"]', { 'name': 'test-image.jpg', 'mimeType': 'image/jpeg', 'buffer': b'fake image data' # In real test, use actual image bytes }) await page.click('button:has-text("Upload")') await page.wait_for_timeout(2000) await expect(page.locator('text=test-image.jpg')).to_be_visible() async def test_02_navigate_to_photo_gallery(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) await page.click('a.nav-link[data-view="photos"]') await page.wait_for_timeout(1000) await expect(page.locator('photo-gallery')).to_be_visible() async def test_03_view_image_in_gallery(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) await page.click('a.nav-link[data-view="photos"]') await page.wait_for_timeout(1000) # Should show uploaded image await expect(page.locator('.photo-item')).to_be_visible() async def test_04_click_on_photo_to_preview(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) await page.click('a.nav-link[data-view="photos"]') await page.wait_for_timeout(1000) # Click on photo await page.click('.photo-item img') await page.wait_for_timeout(1000) # Should open preview await expect(page.locator('file-preview')).to_be_visible() async def test_05_close_photo_preview(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) await page.click('a.nav-link[data-view="photos"]') await page.wait_for_timeout(1000) # Click on photo await page.click('.photo-item img') await page.wait_for_timeout(1000) # Close preview await page.click('.preview-close-btn') await page.wait_for_timeout(500) # Preview should be closed await expect(page.locator('file-preview')).not_to_be_visible() async def test_06_upload_multiple_images(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 multiple images await page.set_input_files('input[type="file"]', [ { 'name': 'image1.jpg', 'mimeType': 'image/jpeg', 'buffer': b'fake image 1' }, { 'name': 'image2.png', 'mimeType': 'image/png', 'buffer': b'fake image 2' } ]) await page.click('button:has-text("Upload")') await page.wait_for_timeout(2000) # Go to gallery await page.click('a.nav-link[data-view="photos"]') await page.wait_for_timeout(1000) # Should show multiple photos photo_count = await page.locator('.photo-item').count() assert photo_count >= 2 async def test_07_filter_photos_by_date(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) await page.click('a.nav-link[data-view="photos"]') await page.wait_for_timeout(1000) # Click date filter await page.click('.date-filter-btn') await page.wait_for_timeout(500) # Select today await page.click('text=Today') await page.wait_for_timeout(1000) # Should filter photos await expect(page.locator('.photo-item')).to_be_visible() async def test_08_search_photos(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) await page.click('a.nav-link[data-view="photos"]') await page.wait_for_timeout(1000) # Type in gallery search await page.fill('.gallery-search-input', 'image1') await page.wait_for_timeout(1000) # Should show filtered results await expect(page.locator('text=image1.jpg')).to_be_visible() await expect(page.locator('text=image2.png')).not_to_be_visible() async def test_09_create_album(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) await page.click('a.nav-link[data-view="photos"]') await page.wait_for_timeout(1000) # Click create album await page.click('button:has-text("Create Album")') await page.wait_for_timeout(500) # Fill album name await page.fill('input[name="album-name"]', 'Test Album') await page.click('button:has-text("Create")') await page.wait_for_timeout(1000) # Should show album await expect(page.locator('text=Test Album')).to_be_visible() async def test_10_add_photos_to_album(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) await page.click('a.nav-link[data-view="photos"]') await page.wait_for_timeout(1000) # Select photos await page.click('.photo-item .photo-checkbox', { force: True }) await page.wait_for_timeout(500) # Click add to album await page.click('button:has-text("Add to Album")') await page.wait_for_timeout(500) # Select album await page.click('text=Test Album') await page.click('button:has-text("Add")') await page.wait_for_timeout(1000) # Should show success await expect(page.locator('text=Photos added to album')).to_be_visible()