test(e2e): add TC-E2E-003/004/005/007/008/009/010 — delete, pagination, errors, profile, theme
- test_post_deletion.py: user delete own, admin delete any, 403 for other's - test_pagination.py: navigation across pages, boundary on last page - test_errors.py: 404 nonexistent post, 404 for other user's draft - test_post_lifecycle.py: draft-to-publish via edit flow - test_post_ownership.py: user can edit own post - test_profile_and_theme.py: profile page rendering, theme toggle with localStorage - fix(web): remove infinite pagination for USER role (routes.py) - fix(e2e): stabilize all publish() calls with expect_navigation - fix(e2e): add _unique_title() to avoid slug collisions at scale - docs: update FEATURE_POST_LIFECYCLE.md and TEST_MODEL.md coverage
This commit is contained in:
111
tests/e2e/test_pagination.py
Normal file
111
tests/e2e/test_pagination.py
Normal file
@@ -0,0 +1,111 @@
|
||||
"""End-to-end tests for pagination on the home and posts listing pages.
|
||||
|
||||
Tests that pagination controls appear when there are more posts than the
|
||||
page size, that navigation between pages works, and that boundary controls
|
||||
are correctly disabled on the first and last pages.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from playwright.sync_api import Page
|
||||
|
||||
from tests.e2e.pages import HomePage
|
||||
|
||||
|
||||
def _seed_posts(page: Page, base_url: str, count: int) -> None:
|
||||
"""Create published posts via form POST to ensure pagination exists.
|
||||
|
||||
Args:
|
||||
page: Authenticated Playwright page.
|
||||
base_url: Application base URL.
|
||||
count: Number of posts to create.
|
||||
"""
|
||||
for idx in range(count):
|
||||
response = page.request.post(
|
||||
f"{base_url}/web/posts/new",
|
||||
form={
|
||||
"title": f"Pagination Seed {idx:03d}",
|
||||
"content": f"Content for seed post {idx}.",
|
||||
"tags": "pagination",
|
||||
"action": "publish",
|
||||
},
|
||||
)
|
||||
assert response.ok, f"Failed to create post {idx}: {response.status}"
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
def test_pagination_navigation_across_pages(
|
||||
user_page: Page,
|
||||
base_url: str,
|
||||
) -> None:
|
||||
"""Test pagination navigation between pages.
|
||||
|
||||
Steps:
|
||||
1. Ensure enough posts exist for pagination.
|
||||
2. Open home page and verify page 1 boundary state.
|
||||
3. Click "Next" and verify page advances.
|
||||
4. Click "Previous" and verify back on page 1.
|
||||
|
||||
Args:
|
||||
user_page: Playwright page authenticated as regular user.
|
||||
base_url: Application base URL.
|
||||
"""
|
||||
home = HomePage(user_page, base_url)
|
||||
home.open()
|
||||
|
||||
if not home.can_go_next():
|
||||
_seed_posts(user_page, base_url, 12)
|
||||
home.open()
|
||||
|
||||
assert home.get_current_page() == 1
|
||||
assert not home.can_go_prev()
|
||||
assert home.can_go_next()
|
||||
assert home.count_posts() <= 10
|
||||
|
||||
with user_page.expect_navigation(wait_until="networkidle"):
|
||||
home.go_to_next_page()
|
||||
|
||||
assert home.get_current_page() == 2
|
||||
assert home.can_go_prev()
|
||||
assert home.count_posts() <= 10
|
||||
|
||||
with user_page.expect_navigation(wait_until="networkidle"):
|
||||
home.go_to_prev_page()
|
||||
|
||||
assert home.get_current_page() == 1
|
||||
assert not home.can_go_prev()
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
def test_pagination_boundary_on_last_page(
|
||||
user_page: Page,
|
||||
base_url: str,
|
||||
) -> None:
|
||||
"""Test that the last page has "Next" disabled and "Previous" enabled.
|
||||
|
||||
Steps:
|
||||
1. Ensure enough posts exist for pagination.
|
||||
2. Navigate through all pages to the last one.
|
||||
3. Verify boundary controls on the last page.
|
||||
|
||||
Args:
|
||||
user_page: Playwright page authenticated as regular user.
|
||||
base_url: Application base URL.
|
||||
"""
|
||||
home = HomePage(user_page, base_url)
|
||||
home.open()
|
||||
|
||||
if not home.can_go_next():
|
||||
_seed_posts(user_page, base_url, 12)
|
||||
home.open()
|
||||
|
||||
assert home.can_go_next()
|
||||
|
||||
while home.can_go_next():
|
||||
with user_page.expect_navigation(wait_until="networkidle"):
|
||||
home.go_to_next_page()
|
||||
|
||||
assert home.can_go_prev()
|
||||
assert not home.can_go_next()
|
||||
assert home.count_posts() <= 10
|
||||
Reference in New Issue
Block a user