fix: make target progress reflect fresh state
This commit is contained in:
@@ -107,12 +107,68 @@ func TestHelpListsEveryTargetAndMainListsOnlyAvailableTargets(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRefreshKeyDispatchesDetectionRefresh(t *testing.T) {
|
||||
module := &targetModule{snapshot: app.Snapshot{}, result: app.Result{Snapshot: app.Snapshot{Targets: []app.TargetSnapshot{{ID: "apt", Description: target.Description{Name: "APT"}, Available: true, State: target.External}}}}}
|
||||
func TestRefreshKeyRunsAsynchronouslyAndRendersRefreshingThenCompleted(t *testing.T) {
|
||||
module := &targetModule{snapshot: app.Snapshot{}, result: app.Result{Snapshot: app.Snapshot{Targets: []app.TargetSnapshot{{ID: "apt", Description: target.Description{Name: "APT"}, Available: true, State: target.External}}}, Notice: "Refreshed Target availability and state"}}
|
||||
model := NewModel(module)
|
||||
model = updateKey(model, "r")
|
||||
if len(module.intents) != 1 || module.intents[0].Kind != app.RefreshTargets || !strings.Contains(model.View(), "External") {
|
||||
t.Fatalf("refresh = intents %#v\n%s", module.intents, model.View())
|
||||
updated, command := model.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'r'}})
|
||||
model = updated.(Model)
|
||||
if command == nil || len(module.intents) != 0 || !strings.Contains(model.View(), "Refreshing Target availability and state") {
|
||||
t.Fatalf("refresh did not start asynchronously: intents %#v\n%s", module.intents, model.View())
|
||||
}
|
||||
message := command()
|
||||
if len(module.intents) != 1 || module.intents[0].Kind != app.RefreshTargets {
|
||||
t.Fatalf("refresh command intents = %#v", module.intents)
|
||||
}
|
||||
updated, command = model.Update(message)
|
||||
model = updated.(Model)
|
||||
if command != nil || !strings.Contains(model.View(), "External") || !strings.Contains(model.View(), "Refreshed Target availability and state") {
|
||||
t.Fatalf("refresh completion:\n%s", model.View())
|
||||
}
|
||||
}
|
||||
|
||||
func TestTargetPanelNavigationKeysAndQuitCombinations(t *testing.T) {
|
||||
module := &targetModule{snapshot: app.Snapshot{Targets: []app.TargetSnapshot{
|
||||
{ID: "first", Description: target.Description{Name: "First", Summary: "first summary"}, Available: true},
|
||||
{ID: "second", Description: target.Description{Name: "Second", Summary: "second summary"}, Available: true},
|
||||
}}}
|
||||
for _, down := range []tea.KeyMsg{{Type: tea.KeyDown}, {Type: tea.KeyRunes, Runes: []rune{'j'}}} {
|
||||
model := NewModel(module)
|
||||
updated, _ := model.Update(down)
|
||||
model = updated.(Model)
|
||||
if !strings.Contains(model.View(), "> [ ] Second") {
|
||||
t.Fatalf("down key %q did not select second Target:\n%s", down.String(), model.View())
|
||||
}
|
||||
for _, up := range []tea.KeyMsg{{Type: tea.KeyUp}, {Type: tea.KeyRunes, Runes: []rune{'k'}}} {
|
||||
updated, _ = model.Update(up)
|
||||
if !strings.Contains(updated.(Model).View(), "> [ ] First") {
|
||||
t.Fatalf("up key %q did not select first Target:\n%s", up.String(), updated.(Model).View())
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, quit := range []tea.KeyMsg{{Type: tea.KeyRunes, Runes: []rune{'q'}}, {Type: tea.KeyEsc}} {
|
||||
_, command := NewModel(module).Update(quit)
|
||||
if command == nil {
|
||||
t.Fatalf("quit key %q returned no command", quit.String())
|
||||
}
|
||||
if _, ok := command().(tea.QuitMsg); !ok {
|
||||
t.Fatalf("quit key %q command did not return tea.QuitMsg", quit.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestQAndEscapeReturnFromNestedPages(t *testing.T) {
|
||||
module := &targetModule{}
|
||||
for _, key := range []tea.KeyMsg{{Type: tea.KeyRunes, Runes: []rune{'q'}}, {Type: tea.KeyEsc}} {
|
||||
model := updateKey(NewModel(module), "?")
|
||||
updated, command := model.Update(key)
|
||||
if command != nil || !strings.Contains(updated.(Model).View(), "Target panel") {
|
||||
t.Fatalf("help key %q did not return to Target panel", key.String())
|
||||
}
|
||||
model = updateKey(NewModel(module), "p")
|
||||
updated, command = model.Update(key)
|
||||
if command != nil || !strings.Contains(updated.(Model).View(), "Target panel") {
|
||||
t.Fatalf("Profile key %q did not return to Target panel", key.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user