from django.test import TestCase
from django.urls import reverse
from django.utils import timezone

from .models import Category, MomentumEntry


class MomentumViewsTests(TestCase):
    def setUp(self):
        self.category = Category.objects.create(
            name="Learning",
            slug="learning",
            description="Tracking study sessions",
            accent_color="#0F766E",
        )

    def test_home_page_loads(self):
        response = self.client.get(reverse("home"))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Momentum Atlas")

    def test_post_creates_entry_and_redirects(self):
        response = self.client.post(
            reverse("home"),
            {
                "title": "Finished a Python kata",
                "category": self.category.pk,
                "entry_date": timezone.localdate().isoformat(),
                "focus_score": 8,
                "energy_score": 7,
                "deep_work_minutes": 90,
                "takeaway": "Made steady progress with functions today.",
                "reflection": "Felt strong after removing distractions.",
            },
        )
        self.assertEqual(response.status_code, 302)
        self.assertEqual(MomentumEntry.objects.count(), 1)
