diff --git a/src/apps/billboard/tests/integrated/test_views.py b/src/apps/billboard/tests/integrated/test_views.py index b5ed60e..0d2938d 100644 --- a/src/apps/billboard/tests/integrated/test_views.py +++ b/src/apps/billboard/tests/integrated/test_views.py @@ -433,3 +433,51 @@ class SaveScrollPositionTest(TestCase): {"position": 100}, ) self.assertEqual(response.status_code, 302) + + +class PostLineRelativeTimestampTest(TestCase): + """post.html mirrors scroll.html's bucketed `relative_ts` time rendering: + same-day Lines show a time; older ones collapse to weekday / month-day / + month-day-year. Bypasses `auto_now_add` with a queryset .update() so the + test can backdate Lines.""" + + def setUp(self): + self.owner = User.objects.create(email="owner@post-ts.io", username="owner") + self.client.force_login(self.owner) + from apps.billboard.models import Line, Post + self.Line = Line + self.post = Post.objects.create(owner=self.owner, title="Stamp") + + def _backdate(self, line, **delta): + from apps.billboard.models import Line + Line.objects.filter(pk=line.pk).update( + created_at=timezone.now() - timezone.timedelta(**delta) + ) + + def test_recent_line_renders_clock_time(self): + self.Line.objects.create(post=self.post, text="now", author=self.owner) + response = self.client.get(reverse("billboard:view_post", args=[self.post.id])) + self.assertRegex( + response.content.decode(), + r'class="post-line-time"[^>]*>\s*\d+:\d{2}\s*[ap]\.m\.\s*<', + ) + + def test_two_day_old_line_renders_weekday(self): + line = self.Line.objects.create(post=self.post, text="old", author=self.owner) + self._backdate(line, days=2) + response = self.client.get(reverse("billboard:view_post", args=[self.post.id])) + import re + m = re.search( + r'class="post-line-time"[^>]*>\s*(\w+)\s*<', response.content.decode() + ) + self.assertIsNotNone(m, "no .post-line-time cell rendered") + self.assertIn(m.group(1), {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}) + + def test_thirty_day_old_line_renders_day_month(self): + line = self.Line.objects.create(post=self.post, text="oldr", author=self.owner) + self._backdate(line, days=30) + response = self.client.get(reverse("billboard:view_post", args=[self.post.id])) + self.assertRegex( + response.content.decode(), + r'class="post-line-time"[^>]*>\s*\d{2}\s\w{3}\s*<', + ) diff --git a/src/templates/apps/billboard/post.html b/src/templates/apps/billboard/post.html index abccf5f..0c42722 100644 --- a/src/templates/apps/billboard/post.html +++ b/src/templates/apps/billboard/post.html @@ -42,7 +42,7 @@