final home desing

This commit is contained in:
2026-08-05 17:40:33 -05:00
parent cf78128284
commit 344cb524e3
5 changed files with 186 additions and 24 deletions
+57
View File
@@ -8,6 +8,63 @@ from django.core.cache import cache
from django.test import TestCase
from django.urls import reverse
from library.models import Project
class HomeSectionsTests(TestCase):
def setUp(self):
self.user = get_user_model().objects.create_user(username='Owner', password='pw')
def _home(self):
session = self.client.session
session['authorized'] = True
session.save()
self.client.force_login(self.user)
return self.client.get(reverse('landing:home')).content.decode()
def test_empty_categories_skipped(self):
Project.objects.create(slug='only-mod', title='Only Mod', category='mod', owner=self.user)
html = self._home()
self.assertIn('>Mod</h2>', html)
self.assertNotIn('>Skin</h2>', html)
self.assertNotIn('>Guide</h2>', html)
def test_popular_ordered_by_rating(self):
Project.objects.create(slug='m0', title='Mod 0', category='mod', owner=self.user, rating_score=0)
Project.objects.create(slug='m2', title='Mod 2', category='mod', owner=self.user, rating_score=2)
Project.objects.create(slug='m1', title='Mod 1', category='mod', owner=self.user, rating_score=1)
html = self._home()
sections = html.split('class="home-cat-block"')[1:]
mod = next(s for s in sections if '>Mod</h2>' in s)
popular = mod.split('home-cat-divider')[0]
self.assertLess(popular.index('Mod 2'), popular.index('Mod 1'))
self.assertLess(popular.index('Mod 1'), popular.index('Mod 0'))
def test_columns_capped_at_six(self):
for i in range(8):
Project.objects.create(slug=f'm{i}', title=f'Mod {i}', category='mod', owner=self.user, rating_score=i)
html = self._home()
sections = html.split('class="home-cat-block"')[1:]
mod = next(s for s in sections if '>Mod</h2>' in s)
popular = mod.split('home-cat-divider')[0]
recent = mod.split('home-cat-divider')[1]
self.assertEqual(popular.count('class="pack-card-row"'), 6)
self.assertEqual(recent.count('class="pack-card-row"'), 6)
def test_recent_column_orders_by_creation(self):
Project.objects.create(slug='s0', title='High', category='skin', owner=self.user, rating_score=5)
Project.objects.create(slug='s1', title='Mid', category='skin', owner=self.user, rating_score=3)
Project.objects.create(slug='s2', title='Low', category='skin', owner=self.user, rating_score=0)
html = self._home()
sections = html.split('class="home-cat-block"')[1:]
skin = next(s for s in sections if '>Skin</h2>' in s)
popular = skin.split('home-cat-divider')[0]
recent = skin.split('home-cat-divider')[1]
# Popular leads with the top-rated pack.
self.assertLess(popular.index('High'), popular.index('Low'))
# Recent leads with the newest (created last -> 'Low').
self.assertLess(recent.index('Low'), recent.index('High'))
class ServerStatsTests(TestCase):
def setUp(self):