Snooze notifications, morning summary, ICS import, data folder sync
- Windows toast notifications with snooze (10 min / 1 h / tomorrow) and done buttons; balloon fallback; works when Windows starts the app - Recurring entries snooze via SnoozedUntil without moving their date; lead reminders keep the real date - Morning summary once a day from a chosen hour (pure DailySummary) - iCalendar import incl. Google birthday calendar, folded lines, UTC, alarms, own export round trip, duplicates skipped by UID, undo - Data folder selectable (location.json pointer), file watcher reloads changes from another PC (own writes ignored) - Themed date picker calendar, WPF tray menu, arrow/Home/End/Space keys - 90 tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
159
Tests/ImportSnoozeTests.cs
Normal file
159
Tests/ImportSnoozeTests.cs
Normal file
@@ -0,0 +1,159 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ReminderOrganizer.Core;
|
||||
using ReminderOrganizer.Models;
|
||||
using ReminderOrganizer.Services;
|
||||
using Xunit;
|
||||
|
||||
namespace ReminderOrganizer.Tests
|
||||
{
|
||||
public class SnoozeTests
|
||||
{
|
||||
private static readonly DateTime Now = new(2026, 11, 29, 10, 0, 0);
|
||||
|
||||
[Fact]
|
||||
public void One_off_task_moves_its_date()
|
||||
{
|
||||
var t = new ReminderTask("Call", "", Now.AddMinutes(-1)) { IsNotified = true };
|
||||
t.Snooze(Now.AddMinutes(10));
|
||||
Assert.False(t.IsNotified);
|
||||
Assert.Equal(Now.AddMinutes(10), t.ReminderDate);
|
||||
Assert.Null(t.SnoozedUntil);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Recurring_task_keeps_date_and_fires_once_more()
|
||||
{
|
||||
var next = new DateTime(2027, 11, 29, 9, 0, 0);
|
||||
var t = new ReminderTask("Oma", "", next) { IsRecurring = true, RecurrenceType = RecurrenceType.Yearly, IsAnniversary = true };
|
||||
var f = new Folder("f");
|
||||
f.Tasks.Add(t);
|
||||
|
||||
t.Snooze(Now.AddHours(1));
|
||||
Assert.Equal(next, t.ReminderDate);
|
||||
|
||||
Assert.Empty(ReminderTask.ProcessDue(new[] { f }, Now.AddMinutes(30)));
|
||||
var due = ReminderTask.ProcessDue(new[] { f }, Now.AddHours(1));
|
||||
Assert.Single(due);
|
||||
Assert.Null(t.SnoozedUntil);
|
||||
Assert.Equal(next, t.ReminderDate);
|
||||
Assert.Empty(ReminderTask.ProcessDue(new[] { f }, Now.AddHours(2)));
|
||||
}
|
||||
}
|
||||
|
||||
public class DailySummaryTests
|
||||
{
|
||||
private static readonly DateTime Now = new(2026, 11, 29, 8, 0, 0);
|
||||
|
||||
[Fact]
|
||||
public void Collects_today_overdue_and_upcoming_anniversaries()
|
||||
{
|
||||
var tasks = new[]
|
||||
{
|
||||
new ReminderTask("Dentist", "", Now.Date.AddHours(10)),
|
||||
new ReminderTask("Tax", "", Now.AddDays(-2)),
|
||||
new ReminderTask("Done", "", Now.AddDays(-2)) { IsNotified = true },
|
||||
new ReminderTask("Oma", "", Now.Date.AddDays(1).AddHours(9)) { IsAnniversary = true, IsRecurring = true },
|
||||
new ReminderTask("Later", "", Now.Date.AddDays(10).AddHours(9)) { IsAnniversary = true, IsRecurring = true },
|
||||
};
|
||||
var s = DailySummary.Build(tasks, Now)!;
|
||||
Assert.Equal(new[] { "Dentist" }, s.Today.Select(t => t.Name));
|
||||
Assert.Equal(new[] { "Tax" }, s.Overdue.Select(t => t.Name));
|
||||
Assert.Equal(new[] { "Oma" }, s.AnniversariesSoon.Select(t => t.Name));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Nothing_to_say_is_null()
|
||||
{
|
||||
Assert.Null(DailySummary.Build(new[] { new ReminderTask("x", "", Now.AddDays(20)) }, Now));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Once_per_day_from_the_hour()
|
||||
{
|
||||
Assert.False(DailySummary.IsDue(Now.Date.AddHours(7), 8, null));
|
||||
Assert.True(DailySummary.IsDue(Now.Date.AddHours(8), 8, null));
|
||||
Assert.False(DailySummary.IsDue(Now.Date.AddHours(9), 8, Now.Date.AddHours(8)));
|
||||
Assert.True(DailySummary.IsDue(Now.Date.AddDays(1).AddHours(9), 8, Now.Date.AddHours(8)));
|
||||
}
|
||||
}
|
||||
|
||||
public class IcsImportTests
|
||||
{
|
||||
private static readonly DateTime Now = new(2026, 11, 29, 10, 0, 0);
|
||||
|
||||
[Fact]
|
||||
public void Round_trip_with_own_export()
|
||||
{
|
||||
var data = new AppData();
|
||||
var f = new Folder("F");
|
||||
f.Tasks.Add(new ReminderTask("Oma", "Kuchen; Blumen", new DateTime(2027, 1, 27, 9, 0, 0))
|
||||
{ IsAnniversary = true, IsRecurring = true, RecurrenceType = RecurrenceType.Yearly, BirthYear = 1941, LeadDays = 1 });
|
||||
f.Tasks.Add(new ReminderTask("Team", "", new DateTime(2026, 12, 7, 9, 30, 0))
|
||||
{ IsRecurring = true, RecurrenceType = RecurrenceType.Weekly, LeadDays = 2 });
|
||||
data.Folders.Add(f);
|
||||
var ics = IcsExport.Build(data, DateTime.UtcNow);
|
||||
|
||||
var r = IcsImport.Parse(ics, new HashSet<string>(), Now);
|
||||
Assert.Equal(0, r.Skipped);
|
||||
var oma = r.Tasks.Single(t => t.Name == "Oma");
|
||||
Assert.True(oma.IsAnniversary);
|
||||
Assert.Equal(1941, oma.BirthYear);
|
||||
Assert.Equal(1, oma.LeadDays);
|
||||
Assert.Equal("Kuchen; Blumen", oma.Description);
|
||||
Assert.Equal(new DateTime(2027, 1, 27, 9, 0, 0), oma.ReminderDate);
|
||||
var team = r.Tasks.Single(t => t.Name == "Team");
|
||||
Assert.Equal(RecurrenceType.Weekly, team.RecurrenceType);
|
||||
Assert.Equal(new DateTime(2026, 12, 7, 9, 30, 0), team.ReminderDate);
|
||||
Assert.Equal(2, team.LeadDays);
|
||||
|
||||
// importing the same file again changes nothing
|
||||
var ids = new HashSet<string>(r.Tasks.Select(t => t.Id));
|
||||
var again = IcsImport.Parse(ics, ids, Now);
|
||||
Assert.Empty(again.Tasks);
|
||||
Assert.Equal(2, again.Skipped);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Google_birthday_calendar()
|
||||
{
|
||||
var ics = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:19860319\r\nRRULE:FREQ=YEARLY\r\n" +
|
||||
"SUMMARY:Michael's birthday\r\nUID:abc@google.com\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";
|
||||
var t = IcsImport.Parse(ics, new HashSet<string>(), Now).Tasks.Single();
|
||||
Assert.Equal("Michael", t.Name);
|
||||
Assert.True(t.IsAnniversary);
|
||||
Assert.Equal(Category.BirthdayId, t.CategoryId);
|
||||
Assert.Equal(1986, t.BirthYear);
|
||||
Assert.Equal(new DateTime(2027, 3, 19, 9, 0, 0), t.ReminderDate);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Wedding_folded_lines_utc_and_past_events()
|
||||
{
|
||||
var ics = string.Join("\r\n",
|
||||
"BEGIN:VCALENDAR",
|
||||
"BEGIN:VEVENT", "DTSTART;VALUE=DATE:20010812", "RRULE:FREQ=YEARLY", "SUMMARY:Hochzeitstag Lea + Max", "END:VEVENT",
|
||||
"BEGIN:VEVENT", "DTSTART:20261215T130000Z", "SUMMARY:Arzt mit einem sehr langen", " Namen", "END:VEVENT",
|
||||
"BEGIN:VEVENT", "DTSTART:20200101T100000", "SUMMARY:Alt", "END:VEVENT",
|
||||
"END:VCALENDAR", "");
|
||||
var r = IcsImport.Parse(ics, new HashSet<string>(), Now);
|
||||
Assert.Equal(1, r.Skipped);
|
||||
Assert.Equal(Category.WeddingId, r.Tasks[0].CategoryId);
|
||||
Assert.Equal(2001, r.Tasks[0].BirthYear);
|
||||
// RFC 5545: the continuation's single leading space is removed
|
||||
Assert.Equal("Arzt mit einem sehr langenNamen", r.Tasks[1].Name);
|
||||
Assert.Equal(DateTimeKind.Unspecified, r.Tasks[1].ReminderDate.Kind);
|
||||
Assert.Equal(new DateTime(2026, 12, 15, 13, 0, 0, DateTimeKind.Utc).ToLocalTime().Hour, r.Tasks[1].ReminderDate.Hour);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("-P1D", false, 1)]
|
||||
[InlineData("-PT15H", true, 1)]
|
||||
[InlineData("-PT15H", false, 0)]
|
||||
[InlineData("-P1W", false, 7)]
|
||||
[InlineData("PT9H", true, 0)]
|
||||
public void Lead_days(string trigger, bool allDay, int expected) =>
|
||||
Assert.Equal(expected, IcsImport.LeadDaysFrom(trigger, allDay));
|
||||
}
|
||||
}
|
||||
66
Tests/SyncTests.cs
Normal file
66
Tests/SyncTests.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using ReminderOrganizer.Models;
|
||||
using ReminderOrganizer.Services;
|
||||
using Xunit;
|
||||
|
||||
namespace ReminderOrganizer.Tests
|
||||
{
|
||||
public class SyncTests : IDisposable
|
||||
{
|
||||
private readonly string _root = Path.Combine(Path.GetTempPath(), "ro-sync-" + Guid.NewGuid().ToString("N"));
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
try { Directory.Delete(_root, true); } catch { }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Pointer_file_round_trip()
|
||||
{
|
||||
var app = Path.Combine(_root, "app");
|
||||
var cloud = Path.Combine(_root, "OneDrive", "Reminders");
|
||||
Directory.CreateDirectory(cloud);
|
||||
|
||||
Assert.Null(DataService.ReadPointer(app));
|
||||
DataService.WritePointer(app, cloud);
|
||||
Assert.Equal(cloud, DataService.ReadPointer(app));
|
||||
|
||||
DataService.WritePointer(app, app); // back to the app folder = no pointer
|
||||
Assert.Null(DataService.ReadPointer(app));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Pointer_to_missing_folder_is_ignored()
|
||||
{
|
||||
var app = Path.Combine(_root, "app");
|
||||
DataService.WritePointer(app, Path.Combine(_root, "gone"));
|
||||
Directory.CreateDirectory(Path.Combine(_root, "gone"));
|
||||
Directory.Delete(Path.Combine(_root, "gone"));
|
||||
Assert.Null(DataService.ReadPointer(app));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Own_writes_are_not_external_but_other_writes_are()
|
||||
{
|
||||
var ds = new DataService(Path.Combine(_root, "data"));
|
||||
await ds.SaveAsync(new AppData());
|
||||
Assert.False(ds.IsExternalChange());
|
||||
|
||||
await Task.Delay(30);
|
||||
File.WriteAllText(ds.DataFilePath, "{\"Folders\":[]}"); // "another PC"
|
||||
File.SetLastWriteTimeUtc(ds.DataFilePath, DateTime.UtcNow.AddSeconds(2));
|
||||
Assert.True(ds.IsExternalChange());
|
||||
Assert.False(ds.IsExternalChange()); // reported once
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Switching_folder_uses_new_file()
|
||||
{
|
||||
var ds = new DataService(Path.Combine(_root, "a"));
|
||||
ds.SwitchTo(Path.Combine(_root, "b"));
|
||||
Assert.Equal(Path.Combine(_root, "b", "tasks.json"), ds.DataFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user