MCPcopy
hub / github.com/derailed/k9s / TestPromptStyleChanged

Function TestPromptStyleChanged

internal/ui/prompt_test.go:144–188  ·  view source on GitHub ↗

Tests that, when a change of style occurs, the prompt will have the appropriate color when active

(t *testing.T)

Source from the content-addressed store, hash-verified

142
143// Tests that, when a change of style occurs, the prompt will have the appropriate color when active
144func TestPromptStyleChanged(t *testing.T) {
145 app := ui.App{}
146 styles := config.NewStyles()
147 newStyles := config.NewStyles()
148 newStyles.K9s.Prompt.Border = config.PromptBorder{
149 DefaultColor: "green",
150 CommandColor: "yellow",
151 }
152
153 // Check that the prompt won't change the border into the same style
154 assert.NotEqual(t, styles.Prompt().Border.CommandColor.Color(), newStyles.Prompt().Border.CommandColor.Color())
155 assert.NotEqual(t, styles.Prompt().Border.DefaultColor.Color(), newStyles.Prompt().Border.DefaultColor.Color())
156
157 testCases := []struct {
158 kind model.BufferKind
159 expectedColor tcell.Color
160 }{
161 // Command prompt case
162 {
163 kind: model.CommandBuffer,
164 expectedColor: newStyles.Prompt().Border.CommandColor.Color(),
165 },
166 // Any other prompt type case
167 {
168 // Simulate a different type of prompt since no particular constant exists
169 kind: model.CommandBuffer + 1,
170 expectedColor: newStyles.Prompt().Border.DefaultColor.Color(),
171 },
172 }
173
174 for _, testCase := range testCases {
175 m := model.NewFishBuff(':', testCase.kind)
176 prompt := ui.NewPrompt(&app, true, styles)
177
178 m.SetActive(true)
179
180 prompt.SetModel(m)
181 m.AddListener(prompt)
182
183 prompt.StylesChanged(newStyles)
184
185 m.SetActive(true)
186 assert.Equal(t, testCase.expectedColor, prompt.GetBorderColor())
187 }
188}

Callers

nothing calls this directly

Calls 9

PromptMethod · 0.95
SetModelMethod · 0.95
StylesChangedMethod · 0.95
NewStylesFunction · 0.92
NewFishBuffFunction · 0.92
NewPromptFunction · 0.92
ColorMethod · 0.80
SetActiveMethod · 0.65
AddListenerMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…