Tests that, when a change of style occurs, the prompt will have the appropriate color when active
(t *testing.T)
| 142 | |
| 143 | // Tests that, when a change of style occurs, the prompt will have the appropriate color when active |
| 144 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…