mirror of
https://github.com/RWejlgaard/org.git
synced 2026-09-02 01:15:35 +00:00
* feat: add configurable done flag to TODO states * feat: stamp CLOSED for any configured done state * feat: add DONE state option and done marker to settings * chore: remove unused Item.CycleState * chore: drop vestigial state constants, mention DONE add in settings help * feat: add state form model and commit logic * feat: wire state form update/view into settings dispatch * feat: replace state add/edit with unified form, toggle done after creation * consolidate AddState and AddDoneState * add findState() helper
73 lines
2.1 KiB
Go
73 lines
2.1 KiB
Go
package config
|
|
|
|
import "testing"
|
|
|
|
func TestIsDoneState(t *testing.T) {
|
|
c := &Config{States: StatesConfig{States: []StateConfig{
|
|
{Name: "TODO", Color: "202"},
|
|
{Name: "DONE", Color: "34", Done: true},
|
|
{Name: "CANCELLED", Color: "240", Done: true},
|
|
}}}
|
|
|
|
cases := map[string]bool{"TODO": false, "DONE": true, "CANCELLED": true, "": false, "NOPE": false}
|
|
for name, want := range cases {
|
|
if got := c.IsDoneState(name); got != want {
|
|
t.Errorf("IsDoneState(%q) = %v, want %v", name, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFillDefaultsMarksLastStateDoneWhenNoneFlagged(t *testing.T) {
|
|
c := &Config{States: StatesConfig{States: []StateConfig{
|
|
{Name: "TODO", Color: "202"},
|
|
{Name: "DONE", Color: "34"},
|
|
}}}
|
|
c.fillDefaults()
|
|
|
|
if c.States.States[len(c.States.States)-1].Name != "DONE" {
|
|
t.Fatalf("states reordered unexpectedly")
|
|
}
|
|
if !c.States.States[len(c.States.States)-1].Done {
|
|
t.Error("expected last state (DONE) to be flagged Done after migration")
|
|
}
|
|
if c.States.States[0].Done {
|
|
t.Error("expected first state (TODO) to remain not-done")
|
|
}
|
|
}
|
|
|
|
func TestFillDefaultsLeavesExplicitDoneFlagsAlone(t *testing.T) {
|
|
c := &Config{States: StatesConfig{States: []StateConfig{
|
|
{Name: "DONE", Color: "34", Done: true},
|
|
{Name: "TODO", Color: "202"},
|
|
}}}
|
|
c.fillDefaults()
|
|
|
|
if c.States.States[0].Name != "DONE" || !c.States.States[0].Done {
|
|
t.Error("explicit done flag on DONE should be preserved")
|
|
}
|
|
if c.States.States[1].Done {
|
|
t.Error("last state (TODO) must NOT be auto-flagged when a done state already exists")
|
|
}
|
|
}
|
|
|
|
func TestAddDoneState(t *testing.T) {
|
|
c := &Config{}
|
|
c.AddState("CANCELLED", "240", true)
|
|
|
|
if len(c.States.States) != 1 {
|
|
t.Fatalf("expected 1 state, got %d", len(c.States.States))
|
|
}
|
|
s := c.States.States[0]
|
|
if s.Name != "CANCELLED" || s.Color != "240" || !s.Done {
|
|
t.Fatalf("unexpected state: %+v", s)
|
|
}
|
|
|
|
// Adding an existing name upgrades it to done.
|
|
c.AddState("REVIEW", "99", false)
|
|
c.AddState("REVIEW", "99", true)
|
|
for _, st := range c.States.States {
|
|
if st.Name == "REVIEW" && !st.Done {
|
|
t.Fatal("expected REVIEW upgraded to done")
|
|
}
|
|
}
|
|
}
|