Skip to content

Commit 29a1d30

Browse files
authored
Merge pull request #225 from DevopsArtFactory/fix/209-inspector-workflow-refresh
fix: avoid redundant inspector workflow refresh
2 parents 86e86b8 + 242d652 commit 29a1d30

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

internal/app/screen_inspector.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ func (im *inspectorModel) refreshWorkflows() {
7979
func (im *inspectorModel) ensureWorkflows() {
8080
if len(im.workflows) == 0 {
8181
im.refreshWorkflows()
82-
return
8382
}
84-
im.refreshWorkflows()
8583
}
8684

8785
func (im *inspectorModel) Enter(m *Model) {

internal/app/screen_inspector_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,42 @@ package app
33
import (
44
"testing"
55
"unicode/utf8"
6+
7+
"unic/internal/inspector"
68
)
79

10+
func TestInspectorEnsureWorkflowsKeepsExistingWorkflows(t *testing.T) {
11+
im := inspectorModel{
12+
workflows: []inspector.Workflow{
13+
{
14+
Kind: inspector.WorkflowSecurity,
15+
Title: "Existing Workflow",
16+
Description: "already loaded",
17+
Available: true,
18+
},
19+
},
20+
}
21+
22+
im.ensureWorkflows()
23+
24+
if len(im.workflows) != 1 {
25+
t.Fatalf("expected existing workflow list to be preserved, got %d workflows", len(im.workflows))
26+
}
27+
if im.workflows[0].Title != "Existing Workflow" {
28+
t.Fatalf("expected existing workflow to be preserved, got %#v", im.workflows[0])
29+
}
30+
}
31+
32+
func TestInspectorEnsureWorkflowsRefreshesEmptyWorkflows(t *testing.T) {
33+
im := inspectorModel{}
34+
35+
im.ensureWorkflows()
36+
37+
if len(im.workflows) != 2 {
38+
t.Fatalf("expected empty workflow list to be populated with 2 workflows, got %d", len(im.workflows))
39+
}
40+
}
41+
842
func TestInspectorShortenHandlesUnicodeSafely(t *testing.T) {
943
tests := []struct {
1044
name string

0 commit comments

Comments
 (0)