Birthday entry type, relative dates, list/compact/cards views
- Task dialog: Appointment | Birthday switch. Birthday = name + "19.03." or "19.03.1986" (no time), live preview with weekday, age and days left - Birthday folders open the birthday form; yearly tasks in such folders are migrated once - Birthdays show "19. Maerz" instead of date + time; every task shows "in 15 days" / "3 days ago" (red when overdue) - View switch: list, compact (one line), cards (calendar tiles), persisted - ICS: birthdays as all-day events - 59 tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
98
Tests/BirthdayTests.cs
Normal file
98
Tests/BirthdayTests.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using ReminderOrganizer.Core;
|
||||
using ReminderOrganizer.Models;
|
||||
using ReminderOrganizer.Services;
|
||||
using Xunit;
|
||||
|
||||
namespace ReminderOrganizer.Tests
|
||||
{
|
||||
public class BirthdayTests
|
||||
{
|
||||
private static readonly DateTime Today = new(2026, 11, 29);
|
||||
|
||||
[Theory]
|
||||
[InlineData("19.03.", 19, 3, null)]
|
||||
[InlineData("19.3", 19, 3, null)]
|
||||
[InlineData("19.03.1986", 19, 3, 1986)]
|
||||
[InlineData("19.3.86", 19, 3, 1986)]
|
||||
[InlineData("1.1.05", 1, 1, 2005)]
|
||||
[InlineData("1986-03-19", 19, 3, 1986)]
|
||||
[InlineData(" 29.02. ", 29, 2, null)]
|
||||
public void Parses_quick_input(string input, int day, int month, int? year)
|
||||
{
|
||||
Assert.True(BirthdayInput.TryParse(input, Today, out var d, out var m, out var y));
|
||||
Assert.Equal((day, month, year), (d, m, y));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData("32.01.")]
|
||||
[InlineData("10.13.")]
|
||||
[InlineData("29.02.2023")] // not a leap year
|
||||
[InlineData("01.01.2030")] // future
|
||||
[InlineData("abc")]
|
||||
public void Rejects_bad_input(string input)
|
||||
{
|
||||
Assert.False(BirthdayInput.TryParse(input, Today, out _, out _, out _));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Next_birthday_this_year_or_next()
|
||||
{
|
||||
Assert.Equal(new DateTime(2026, 12, 14, 9, 0, 0), ReminderTask.NextBirthday(14, 12, Today));
|
||||
Assert.Equal(new DateTime(2027, 3, 19, 9, 0, 0), ReminderTask.NextBirthday(19, 3, Today));
|
||||
Assert.Equal(new DateTime(2026, 11, 29, 9, 0, 0), ReminderTask.NextBirthday(29, 11, Today)); // today counts
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Leap_day_birthday_falls_back_to_28th()
|
||||
{
|
||||
Assert.Equal(new DateTime(2027, 2, 28, 9, 0, 0), ReminderTask.NextBirthday(29, 2, Today));
|
||||
Assert.Equal(new DateTime(2028, 2, 29, 9, 0, 0), ReminderTask.NextBirthday(29, 2, new DateTime(2027, 3, 1)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Migration_marks_yearly_tasks_in_birthday_folders_once()
|
||||
{
|
||||
var data = new AppData();
|
||||
var bday = new Folder("Geburtstage");
|
||||
bday.Tasks.Add(new ReminderTask("Oma", "", new DateTime(2027, 1, 27)) { IsRecurring = true, RecurrenceType = RecurrenceType.Yearly });
|
||||
bday.Tasks.Add(new ReminderTask("Einmalig", "", new DateTime(2027, 1, 27)));
|
||||
var work = new Folder("Arbeit");
|
||||
work.Tasks.Add(new ReminderTask("Jahresbericht", "", new DateTime(2027, 1, 27)) { IsRecurring = true, RecurrenceType = RecurrenceType.Yearly });
|
||||
data.Folders.Add(bday);
|
||||
data.Folders.Add(work);
|
||||
|
||||
Assert.Equal(1, data.MigrateBirthdays());
|
||||
Assert.True(bday.Tasks[0].IsBirthday);
|
||||
Assert.False(bday.Tasks[1].IsBirthday);
|
||||
Assert.False(work.Tasks[0].IsBirthday);
|
||||
Assert.Equal(0, data.MigrateBirthdays());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Birthday_display_has_no_time()
|
||||
{
|
||||
ReminderTask.DisplayCulture = () => new System.Globalization.CultureInfo("de-DE");
|
||||
var t = new ReminderTask("x", "", new DateTime(2027, 3, 19, 9, 0, 0)) { IsBirthday = true };
|
||||
Assert.Equal("19. März", t.DisplayDate);
|
||||
Assert.Equal("MÄR", t.MonthText);
|
||||
t.IsBirthday = false;
|
||||
Assert.Equal("19.03.2027 09:00", t.DisplayDate);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ics_birthday_is_all_day()
|
||||
{
|
||||
var data = new AppData();
|
||||
var f = new Folder("Geburtstage");
|
||||
f.Tasks.Add(new ReminderTask("Oma", "", new DateTime(2027, 1, 27, 9, 0, 0))
|
||||
{ IsBirthday = true, IsRecurring = true, RecurrenceType = RecurrenceType.Yearly, LeadDays = 1 });
|
||||
data.Folders.Add(f);
|
||||
var ics = IcsExport.Build(data, DateTime.UtcNow);
|
||||
Assert.Contains("DTSTART;VALUE=DATE:20270127", ics);
|
||||
Assert.DoesNotContain("DURATION", ics);
|
||||
Assert.Contains("TRIGGER:-P0DT15H", ics); // 09:00 the day before
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user