Skip to content

Commit

Permalink
hide pagination when not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienReuiller committed Aug 4, 2023
1 parent 8ba4299 commit 69894d2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
46 changes: 46 additions & 0 deletions event/tests/test_views_participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,29 @@ def test_events_are_sorted_alphabetically_by_theme_and_subject(self):
self.assertEqual(events_list[4], self.event5)


class EventListViewPaginationTest(TestCase):
def setUp(self):
self.url = reverse("event_list")

def test_list_page_pagination_visibility(self):
response = self.client.get(self.url)
self.assertNotContains(response, "Page suivante")

EventFactory.create_batch(10, pub_status=Event.PubStatus.PUB)
response = self.client.get(self.url)
self.assertNotContains(response, "Page suivante")

# Paginate by 10
EventFactory(pub_status=Event.PubStatus.PUB)
response = self.client.get(self.url)
self.assertContains(response, "Page suivante")
self.assertContains(response, "?page=2")

response = self.client.get(f"{self.url}?page=2")
self.assertContains(response, "Page précédente")
self.assertContains(response, self.url)


class EventRegistrationViewTest(TestCase):
def setUp(self):
respx.post(settings.BREVO_SMTP_URL).mock(return_value=httpx.Response(200, json={"message": "OK"}))
Expand Down Expand Up @@ -267,6 +290,29 @@ def test_contributions_are_sorted_alphabetically_by_theme_and_title(self):
self.assertEqual(contributions_list[4], self.contribution5)


class ContributionListViewPaginationTest(TestCase):
def setUp(self):
self.url = reverse("contribution_list")

def test_list_page_pagination_visibility(self):
response = self.client.get(self.url)
self.assertNotContains(response, "Page suivante")

ContributionFactory.create_batch(10, public=True, event__pub_status=Event.PubStatus.PUB)
response = self.client.get(self.url)
self.assertNotContains(response, "Page suivante")

# Paginate by 10
ContributionFactory(public=True, event__pub_status=Event.PubStatus.PUB)
response = self.client.get(self.url)
self.assertContains(response, "Page suivante")
self.assertContains(response, "?page=2")

response = self.client.get(f"{self.url}?page=2")
self.assertContains(response, "Page précédente")
self.assertContains(response, self.url)


class ContributionDetailViewTest(TestCase):
def test_anonymous_user_cannot_see_not_public_contribution(self):
contribution = ContributionFactory(public=False)
Expand Down
8 changes: 5 additions & 3 deletions templates/event/contribution_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ <h2 class="fr-h4">{{ paginator.count }} résultat{{ paginator.count|pluralizefr
</div>
</div>
</div>
<div class="fr-grid-row fr-grid-row--gutters fr-grid-row--right fr-mt-6v fr-mb-6v">
{% dsfr_pagination page_obj %}
</div>
{% if page_obj.paginator.num_pages > 1 %}
<div class="fr-grid-row fr-grid-row--gutters fr-grid-row--right fr-mt-6v fr-mb-6v">
{% dsfr_pagination page_obj %}
</div>
{% endif %}
</div>
{% endblock %}
8 changes: 5 additions & 3 deletions templates/event/event_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ <h2 class="fr-h4">{{ paginator.count }} résultat{{ paginator.count|pluralizefr
</div>
</div>
</div>
<div class="fr-grid-row fr-grid-row--gutters fr-grid-row--right fr-mt-6v fr-mb-6v">
{% dsfr_pagination page_obj %}
</div>
{% if page_obj.paginator.num_pages > 1 %}
<div class="fr-grid-row fr-grid-row--gutters fr-grid-row--right fr-mt-6v fr-mb-6v">
{% dsfr_pagination page_obj %}
</div>
{% endif %}
</div>
{% endblock %}

0 comments on commit 69894d2

Please sign in to comment.