fix: QoL change unread / read behaviour

This commit is contained in:
2026-07-30 14:08:08 +02:00
parent 033b0bb5be
commit 0d2af19c6d
4 changed files with 95 additions and 38 deletions

View File

@@ -1301,19 +1301,47 @@ func TestPollingMarksNewThreadCommentsUnread(t *testing.T) {
}
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("l")})
m = updated.(App)
if !m.unreadThreads["thread"] {
t.Fatal("focusing the thread detail marked the thread read")
if m.unreadThreads["thread"] || m.unreadComments["comment-2"] {
t.Fatal("focusing the thread detail did not mark the thread read")
}
m.unreadThreads["thread"] = true
m.unreadComments["comment-2"] = true
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("n")})
m = updated.(App)
if !m.unreadThreads["thread"] || m.focus != threadDetailPane ||
m.detailScrollAnchor() != "unread:comment-2" {
t.Fatal("next-unread did not preserve and position the unread update")
if m.unreadThreads["thread"] || m.unreadComments["comment-2"] ||
m.focus != threadDetailPane {
t.Fatal("next-unread did not open and mark the thread discussion read")
}
updated, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("j")})
}
func TestResolvingThreadMarksItRead(t *testing.T) {
service := &recordingService{}
m := NewApp(service, "o", "r", false, 50, time.Second)
m.screen, m.loading = threadScreen, false
m.details = PRDetails{
PullRequest: PullRequest{ID: "pr", Owner: "o", Repository: "r", Number: 1},
Threads: []ReviewThread{{
ID: "thread", ViewerCanResolve: true,
Comments: []ReviewComment{{ID: "comment"}},
}},
}
m.unreadThreads["thread"] = true
m.unreadComments["comment"] = true
updated, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("R")})
m = updated.(App)
if m.unreadThreads["thread"] || m.unreadComments["comment-2"] {
t.Fatal("scrolling the visible final unread comment did not mark the thread read")
updated, command := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("y")})
m = updated.(App)
updated, _ = m.Update(command())
m = updated.(App)
if m.unreadThreads["thread"] || m.unreadComments["comment"] {
t.Fatal("resolved thread remained unread")
}
state := m.readState.Data["pr"]
if !state.Threads["thread"] || !state.Comments["comment"] {
t.Fatalf("resolved thread read state was not persisted: %#v", state)
}
}