created testing for activity page

This commit is contained in:
Beverly Nguyen
2024-07-25 17:09:17 -07:00
parent b37b95cdcf
commit 8461c6156b
4 changed files with 210 additions and 16 deletions

View File

@@ -1,4 +1,10 @@
from app.utils.pagination import generate_next_dict, generate_previous_dict
import pytest
from app.utils.pagination import (
generate_next_dict,
generate_pagination_pages,
generate_previous_dict,
)
def test_generate_previous_dict(client_request):
@@ -20,3 +26,20 @@ def test_generate_previous_next_dict_adds_other_url_args(client_request):
"main.view_notifications", "foo", 2, {"message_type": "blah"}
)
assert "notifications/blah" in result["url"]
@pytest.mark.parametrize(
("total_items", "page_size", "current_page", "expected"),
[
(100, 50, 1, {"current": 1, "pages": [1, 2], "last": 2}),
(450, 50, 1, {"current": 1, "pages": [1, 2, 3, 4, 5, 6, 7, 8, 9], "last": 9}),
(500, 50, 1, {"current": 1, "pages": [1, 2, 3, 4, 5, 6, 7, 8, 9], "last": 10}),
(500, 50, 5, {"current": 5, "pages": [1, 2, 3, 4, 5, 6, 7, 8, 9], "last": 10}),
(500, 50, 6, {"current": 6, "pages": [2, 3, 4, 5, 6, 7, 8, 9, 10], "last": 10}),
(500, 50, 10, {"current": 10, "pages": [2, 3, 4, 5, 6, 7, 8, 9, 10], "last": 10}),
(950, 50, 15, {"current": 15, "pages": [11, 12, 13, 14, 15, 16, 17, 18, 19], "last": 19}),
],
)
def test_generate_pagination_pages(total_items, page_size, current_page, expected):
result = generate_pagination_pages(total_items, page_size, current_page)
assert result == expected