Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/+task-typed-timer-kept.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A timer typed for an Aufgabe now survives a change of Dringlichkeit, and the next Aufgabe starts from the Dringlichkeit default again instead of silently reusing it (#658).
12 changes: 10 additions & 2 deletions src/LageBuch.AppLogic/ViewModels/TaskDialogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,15 @@ public TaskDialogViewModel(
[NotifyPropertyChangedFor(nameof(TimerMinutesError))]
private int? _timerMinutes;

partial void OnUrgencyChanged(TaskUrgency value) =>
TimerMinutes = IncidentTask.DefaultTimerMinutes(value);
// Follows the urgency's default while it still holds it (or nothing); a typed timer
// survives an urgency change (#658).
partial void OnUrgencyChanged(TaskUrgency oldValue, TaskUrgency newValue)
{
if (TimerMinutes is null || TimerMinutes == IncidentTask.DefaultTimerMinutes(oldValue))
{
TimerMinutes = IncidentTask.DefaultTimerMinutes(newValue);
}
}

public IReadOnlyList<ImportanceOption> ImportanceOptions { get; }

Expand Down Expand Up @@ -98,6 +105,7 @@ private void SaveAndCreateAnother()
_session.AddTask(Text, Assignee, Importance, Urgency, TimerMinutes!.Value);
_onChanged();
Text = string.Empty; // fields besides the text stay sticky for the next entry
TimerMinutes = IncidentTask.DefaultTimerMinutes(Urgency); // ...except a typed timer (#658)
ShowErrors(false); // ...and the cleared text must not read as a fresh complaint
}

Expand Down
14 changes: 10 additions & 4 deletions src/LageBuch.AppLogic/ViewModels/TasksViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,15 @@ public bool IsAllFilter
[NotifyPropertyChangedFor(nameof(ErrorSummary))]
private int? _newTimerMinutes = IncidentTask.DefaultTimerMinutes(TaskUrgency.Medium);

// The minutes field follows the urgency's default; an explicit override survives until the
// urgency selection itself changes again.
partial void OnNewUrgencyChanged(TaskUrgency value) =>
NewTimerMinutes = IncidentTask.DefaultTimerMinutes(value);
// The minutes field follows the urgency's default while it still holds it (or nothing); a
// typed timer survives an urgency change (#658).
partial void OnNewUrgencyChanged(TaskUrgency oldValue, TaskUrgency newValue)
{
if (NewTimerMinutes is null || NewTimerMinutes == IncidentTask.DefaultTimerMinutes(oldValue))
{
NewTimerMinutes = IncidentTask.DefaultTimerMinutes(newValue);
}
}

/// <summary>Whether the Aufgabe is still missing, once the operator has asked (#412).</summary>
/// <summary>Everything this form is still waiting on, on one line beneath its fields (#412).</summary>
Expand Down Expand Up @@ -256,6 +261,7 @@ private void AddTask()

_session.AddTask(NewText, NewAssignee, NewImportance, NewUrgency, NewTimerMinutes!.Value);
NewText = string.Empty; // priorities stay sticky for rapid follow-up entries
NewTimerMinutes = IncidentTask.DefaultTimerMinutes(NewUrgency); // a typed timer does not (#658)
ShowErrors(false); // ...and the cleared text must not read as a fresh complaint

// Reached only on success, so this is where the phone's form closes again.
Expand Down
53 changes: 53 additions & 0 deletions tests/LageBuch.AppLogic.Tests/TaskDialogViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,59 @@ public void Prefills_text_from_the_etb_entry_and_defaults_from_medium_urgency()
Assert.True(closed); // SPEICHERN closes the dialog
}

[Fact]
public void An_untouched_timer_follows_the_urgency_default()
{
var (session, _) = NewSession();
var dialog = new TaskDialogViewModel(session, MasterData(), "Auftrag", () => { });

dialog.Urgency = TaskUrgency.High;
Assert.Equal(5, dialog.TimerMinutes);
dialog.Urgency = TaskUrgency.Low;
Assert.Equal(30, dialog.TimerMinutes);
}

// #658: a timer the Lagebuchführer typed is a decision, not a default to overwrite.
[Fact]
public void A_typed_timer_survives_an_urgency_change()
{
var (session, _) = NewSession();
var dialog = new TaskDialogViewModel(session, MasterData(), "Auftrag", () => { });

dialog.TimerMinutes = 7;
dialog.Urgency = TaskUrgency.High;

Assert.Equal(7, dialog.TimerMinutes);
}

[Fact]
public void An_emptied_timer_takes_the_new_urgency_default()
{
var (session, _) = NewSession();
var dialog = new TaskDialogViewModel(session, MasterData(), "Auftrag", () => { });

dialog.TimerMinutes = null;
dialog.Urgency = TaskUrgency.High;

Assert.Equal(5, dialog.TimerMinutes);
}

// #658: the next task starts from the sticky urgency's default, not the last typed timer.
[Fact]
public void Save_and_create_another_resets_a_typed_timer_to_the_urgency_default()
{
var (session, _) = NewSession();
var dialog = new TaskDialogViewModel(session, MasterData(), "Erster Auftrag", () => { });
dialog.Urgency = TaskUrgency.High;
dialog.TimerMinutes = 42;

dialog.SaveAndCreateAnotherCommand.Execute(null);

Assert.Single(session.Incident.Tasks);
Assert.Equal(TaskUrgency.High, dialog.Urgency);
Assert.Equal(5, dialog.TimerMinutes);
}

[Fact]
public void Save_and_create_another_keeps_dialog_open_with_cleared_text_and_sticky_fields()
{
Expand Down
50 changes: 46 additions & 4 deletions tests/LageBuch.AppLogic.Tests/TasksViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,58 @@ public void AddTask_clears_text_keeps_priorities_sticky_and_fires_onchanged()
}

[Fact]
public void Changing_urgency_resets_minutes_but_override_survives_until_next_change()
public void An_untouched_timer_follows_the_urgency_default()
{
var (session, clock, _) = NewSession();
var vm = NewVm(session, clock);
Assert.Equal(15, vm.NewTimerMinutes);

vm.NewUrgency = TaskUrgency.High;
Assert.Equal(5, vm.NewTimerMinutes);
vm.NewUrgency = TaskUrgency.Low;
Assert.Equal(30, vm.NewTimerMinutes);
vm.NewTimerMinutes = 7; // operator override
vm.NewUrgency = TaskUrgency.Medium; // changing urgency re-applies its default
Assert.Equal(15, vm.NewTimerMinutes);
}

// #658: a timer the Lagebuchführer typed is a decision, not a default to overwrite.
[Fact]
public void A_typed_timer_survives_an_urgency_change()
{
var (session, clock, _) = NewSession();
var vm = NewVm(session, clock);

vm.NewTimerMinutes = 7;
vm.NewUrgency = TaskUrgency.High;

Assert.Equal(7, vm.NewTimerMinutes);
}

[Fact]
public void An_emptied_timer_takes_the_new_urgency_default()
{
var (session, clock, _) = NewSession();
var vm = NewVm(session, clock);

vm.NewTimerMinutes = null;
vm.NewUrgency = TaskUrgency.High;

Assert.Equal(5, vm.NewTimerMinutes);
}

// #658: the next task starts from the sticky urgency's default, not the last typed timer.
[Fact]
public void Adding_a_task_resets_a_typed_timer_to_the_urgency_default()
{
var (session, clock, _) = NewSession();
var vm = NewVm(session, clock);
vm.NewUrgency = TaskUrgency.High;
vm.NewText = "Tür sichern";
vm.NewTimerMinutes = 42;

vm.AddTaskCommand.Execute(null);

Assert.Equal(T0.AddMinutes(42), Assert.Single(session.Incident.Tasks).DueAt);
Assert.Equal(TaskUrgency.High, vm.NewUrgency);
Assert.Equal(5, vm.NewTimerMinutes);
}

[Fact]
Expand Down
Loading