feat: add people sections and opt-in read more
This commit is contained in:
@@ -2,7 +2,8 @@ from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
|
||||
from apps.pages.models import BlogPost, HomepageSection
|
||||
from apps.core.models import SiteBranding
|
||||
from apps.pages.models import AboutSection, AboutSectionItem, BlogPost, BlogPostPartner, HomepageSection
|
||||
|
||||
|
||||
class HomeViewTest(TestCase):
|
||||
@@ -34,6 +35,28 @@ class AboutViewTest(TestCase):
|
||||
response = self.client.get(reverse("pages:about"))
|
||||
self.assertTemplateUsed(response, "pages/about.html")
|
||||
|
||||
def test_people_section_orders_roles_and_controls_read_more_per_text(self):
|
||||
section = AboutSection.objects.create(
|
||||
section_type=AboutSection.TYPE_PEOPLE,
|
||||
badge="Our team", title="People behind the work",
|
||||
content="Section introduction", read_more_content=True,
|
||||
)
|
||||
AboutSectionItem.objects.create(section=section, title="Advisor", role="Scientific advisor", content="Advisor profile", order=1)
|
||||
AboutSectionItem.objects.create(section=section, title="Collaborator", role="Collaborator", content="Collaboration profile", read_more_content=True, order=3)
|
||||
AboutSectionItem.objects.create(section=section, title="Organizer", role="Organizer", content="Organizer profile", order=9)
|
||||
html = self.client.get(reverse("pages:about")).content.decode()
|
||||
self.assertIn("People behind the work", html)
|
||||
self.assertIn("Scientific advisor", html)
|
||||
self.assertLess(html.index(">Organizer</h3>"), html.index(">Collaborator</h3>"))
|
||||
self.assertLess(html.index(">Collaborator</h3>"), html.index(">Advisor</h3>"))
|
||||
self.assertIn('data-readmore="200"', html)
|
||||
self.assertEqual(html.count('data-readmore="88"'), 1)
|
||||
|
||||
def test_empty_people_section_is_hidden(self):
|
||||
AboutSection.objects.create(section_type=AboutSection.TYPE_PEOPLE, title="Nobody yet")
|
||||
response = self.client.get(reverse("pages:about"))
|
||||
self.assertNotContains(response, "Nobody yet")
|
||||
|
||||
|
||||
class BlogViewTest(TestCase):
|
||||
def setUp(self):
|
||||
@@ -53,6 +76,8 @@ class BlogViewTest(TestCase):
|
||||
self.assertContains(listing, self.post.title)
|
||||
self.assertContains(detail, "<h2>Results</h2>")
|
||||
self.assertContains(detail, "<strong>Promising</strong>")
|
||||
self.assertNotContains(detail, "blog-partners")
|
||||
self.assertNotContains(detail, "blog-detail-layout--with-partners")
|
||||
|
||||
def test_draft_post_is_not_public(self):
|
||||
self.post.status = BlogPost.STATUS_DRAFT
|
||||
@@ -60,6 +85,76 @@ class BlogViewTest(TestCase):
|
||||
self.assertNotContains(self.client.get(reverse("pages:blog_list")), self.post.title)
|
||||
self.assertEqual(self.client.get(self.post.get_absolute_url()).status_code, 404)
|
||||
|
||||
def test_article_partners_render_with_roles_and_optional_details(self):
|
||||
BlogPostPartner.objects.create(
|
||||
post=self.post, role=BlogPostPartner.ORGANIZER, name="Research Group",
|
||||
description="Project lead", image="blog/partners/group.png",
|
||||
image_alt="Research Group logo", url="https://example.org",
|
||||
)
|
||||
BlogPostPartner.objects.create(
|
||||
post=self.post, role=BlogPostPartner.COLLABORATOR, name="Care Team"
|
||||
)
|
||||
detail = self.client.get(self.post.get_absolute_url())
|
||||
self.assertContains(detail, "Research Group")
|
||||
self.assertContains(detail, "Collaborator")
|
||||
self.assertContains(detail, "Research Group logo")
|
||||
self.assertContains(detail, "https://example.org")
|
||||
self.assertContains(detail, "Care Team")
|
||||
|
||||
def test_blog_read_more_is_opt_in(self):
|
||||
detail = self.client.get(self.post.get_absolute_url())
|
||||
self.assertNotContains(detail, 'data-readmore="600"')
|
||||
self.post.read_more_content = True
|
||||
self.post.save(update_fields=["read_more_content"])
|
||||
detail = self.client.get(self.post.get_absolute_url())
|
||||
self.assertContains(detail, 'data-readmore="600"')
|
||||
|
||||
def test_partners_follow_article_and_sort_by_role_then_number(self):
|
||||
BlogPostPartner.objects.create(post=self.post, role=BlogPostPartner.COLLABORATOR, name="Second collaborator", order=2)
|
||||
BlogPostPartner.objects.create(post=self.post, role=BlogPostPartner.COLLABORATOR, name="First collaborator", order=1)
|
||||
BlogPostPartner.objects.create(post=self.post, role=BlogPostPartner.ORGANIZER, name="Organizer", order=9)
|
||||
html = self.client.get(self.post.get_absolute_url()).content.decode()
|
||||
self.assertLess(html.index('class="blog-article rich-content'), html.index('class="blog-partners"'))
|
||||
self.assertLess(html.index('>Organizer</h3>'), html.index('>First collaborator</h3>'))
|
||||
self.assertLess(html.index('>First collaborator</h3>'), html.index('>Second collaborator</h3>'))
|
||||
|
||||
def test_partner_headings_are_shared_and_description_read_more_is_independent(self):
|
||||
branding = SiteBranding.load()
|
||||
branding.article_people_eyebrow = "Our team"
|
||||
branding.article_people_title = "Project contributors"
|
||||
branding.save(update_fields=["article_people_eyebrow", "article_people_title"])
|
||||
partner = BlogPostPartner.objects.create(
|
||||
post=self.post, role=BlogPostPartner.ORGANIZER,
|
||||
name="Coordinator", description="A detailed profile", read_more_description=True,
|
||||
)
|
||||
html = self.client.get(self.post.get_absolute_url()).content.decode()
|
||||
self.assertIn("Our team", html)
|
||||
self.assertIn("Project contributors", html)
|
||||
self.assertNotIn("The people behind this article", html)
|
||||
self.assertIn('data-readmore="88"', html)
|
||||
partner.read_more_description = False
|
||||
partner.save(update_fields=["read_more_description"])
|
||||
html = self.client.get(self.post.get_absolute_url()).content.decode()
|
||||
self.assertNotIn('data-readmore="88"', html)
|
||||
|
||||
other_post = BlogPost.objects.create(
|
||||
title="Another update", slug="another-update", content="Another article",
|
||||
status=BlogPost.STATUS_PUBLISHED, published_at=timezone.now(),
|
||||
)
|
||||
BlogPostPartner.objects.create(post=other_post, name="Contributor")
|
||||
other_html = self.client.get(other_post.get_absolute_url()).content.decode()
|
||||
self.assertIn("Our team", other_html)
|
||||
self.assertIn("Project contributors", other_html)
|
||||
|
||||
def test_custom_role_can_be_named_by_admin(self):
|
||||
BlogPostPartner.objects.create(post=self.post, role="Scientific advisor", name="Advisor", order=0)
|
||||
BlogPostPartner.objects.create(post=self.post, role=BlogPostPartner.COLLABORATOR, name="Partner", order=5)
|
||||
BlogPostPartner.objects.create(post=self.post, role=BlogPostPartner.ORGANIZER, name="Lead", order=9)
|
||||
html = self.client.get(self.post.get_absolute_url()).content.decode()
|
||||
self.assertIn("Scientific advisor", html)
|
||||
self.assertLess(html.index(">Lead</h3>"), html.index(">Partner</h3>"))
|
||||
self.assertLess(html.index(">Partner</h3>"), html.index(">Advisor</h3>"))
|
||||
|
||||
|
||||
class ContactViewTest(TestCase):
|
||||
def test_contact_returns_200(self):
|
||||
|
||||
Reference in New Issue
Block a user