added gitea activity for fun
This commit is contained in:
@@ -9,6 +9,8 @@ from django.utils import timezone
|
||||
from django.urls import reverse
|
||||
|
||||
from .models import FastingPause, FastingPeriod, FastingSettings, SickDaySettings, Task
|
||||
from .models import UserSettings, WaterIntakeEntry
|
||||
from .services.hydration import hydration_context
|
||||
from .forms import DAILY_FASTING_DURATION_CHOICES, FastingSettingsForm
|
||||
from .services.deferrals import (
|
||||
apply_missed_task_deferrals,
|
||||
@@ -1511,3 +1513,48 @@ class TaskCompletionViewTests(TestCase):
|
||||
self.client.post(reverse('planner:task-toggle-completed', args=[foreign.pk])).status_code,
|
||||
404,
|
||||
)
|
||||
|
||||
class HydrationWidgetTests(TestCase):
|
||||
def setUp(self):
|
||||
self.user = get_user_model().objects.create_user(username='hydration-user', password='test-password')
|
||||
self.client.force_login(self.user)
|
||||
UserSettings.objects.update_or_create(user=self.user, defaults={'daily_water_goal_ml': 500})
|
||||
|
||||
def test_entries_total_and_over_goal_visual_cap(self):
|
||||
self.client.post(reverse('planner:hydration-add'), {'amount_ml': 250})
|
||||
self.client.post(reverse('planner:hydration-add'), {'amount_ml': 500})
|
||||
self.assertEqual(WaterIntakeEntry.objects.filter(user=self.user).count(), 2)
|
||||
context = hydration_context(self.user)
|
||||
self.assertEqual(context['hydration_total'], 750)
|
||||
self.assertEqual(context['hydration_percent'], 150)
|
||||
self.assertEqual(context['hydration_visual'], 100)
|
||||
self.assertEqual(next(day for day in context['hydration_days'] if day['today'])['state'], 'goal')
|
||||
|
||||
def test_health_page_reuses_widgets_and_live_hydration(self):
|
||||
response = self.client.get(reverse('planner:health'))
|
||||
self.assertContains(response, 'Health routines')
|
||||
self.assertContains(response, 'id="fasting-widget"')
|
||||
self.assertContains(response, 'id="hydration-widget"')
|
||||
self.client.post(reverse('planner:hydration-add'), {'amount_ml': 250})
|
||||
self.assertContains(self.client.get(reverse('planner:health')), '250 <span>/ 500 ml</span>', html=True)
|
||||
|
||||
def test_undo_only_current_user_current_day(self):
|
||||
other = get_user_model().objects.create_user(username='other-hydration-user')
|
||||
WaterIntakeEntry.objects.create(user=other, amount_ml=500)
|
||||
yesterday = timezone.now() - timedelta(days=1)
|
||||
WaterIntakeEntry.objects.create(user=self.user, amount_ml=250, recorded_at=yesterday)
|
||||
self.client.post(reverse('planner:hydration-add'), {'amount_ml': 500})
|
||||
self.client.post(reverse('planner:hydration-undo'))
|
||||
self.assertEqual(hydration_context(self.user)['hydration_total'], 0)
|
||||
self.assertEqual(WaterIntakeEntry.objects.filter(user=self.user).count(), 1)
|
||||
self.assertEqual(WaterIntakeEntry.objects.filter(user=other).count(), 1)
|
||||
|
||||
def test_week_rolls_forward_and_invalid_amount_is_rejected(self):
|
||||
monday = timezone.now().astimezone(ZoneInfo('Europe/Amsterdam'))
|
||||
monday = monday - timedelta(days=monday.weekday())
|
||||
prior_week = monday - timedelta(days=7)
|
||||
WaterIntakeEntry.objects.create(user=self.user, amount_ml=500, recorded_at=prior_week)
|
||||
self.assertTrue(all(day['state'] == 'none' for day in hydration_context(self.user)['hydration_days']))
|
||||
response = self.client.post(reverse('planner:hydration-add'), {'amount_ml': 3001})
|
||||
self.assertContains(response, 'Enter a whole amount')
|
||||
self.assertEqual(WaterIntakeEntry.objects.filter(user=self.user).count(), 1)
|
||||
|
||||
Reference in New Issue
Block a user