diff --git a/HellionChat/SelfTests/ColorEditorBufferStep.cs b/HellionChat/SelfTests/ColorEditorBufferStep.cs index d840193..db9fdd8 100644 --- a/HellionChat/SelfTests/ColorEditorBufferStep.cs +++ b/HellionChat/SelfTests/ColorEditorBufferStep.cs @@ -1,27 +1,67 @@ using Dalamud.Bindings.ImGui; using Dalamud.Plugin.SelfTest; +using HellionChat.Themes; namespace HellionChat.SelfTests; -// Placeholder. The real working-buffer test (Cancel discards, Save -// persists) lands once the ColorPicker component arrives in a later -// cycle. Listed in the registry today so /xlperf shows the slot as -// pending instead of silently missing. internal sealed class ColorEditorBufferStep : ISelfTestStep { + private readonly Plugin _plugin; + public ColorEditorBufferStep(Plugin plugin) { - _ = plugin; + _plugin = plugin; } - public string Name => "Hellion Chat - Color editor buffer (pending)"; + public string Name => "Hellion Chat - Color editor buffer"; public SelfTestStepResult RunStep() { - ImGui.TextDisabled( - "Pending ColorEditor integration — placeholder selftest, no probe runs." - ); - return SelfTestStepResult.Pass; + var registry = _plugin.ThemeRegistry; + var originalActive = registry.Active; + var fired = 0; + Action handler = () => fired++; + + try + { + registry.OnEditingBufferChanged += handler; + registry.BeginEditing(originalActive); + + if (registry.EditingThemeBuffer is null) + { + ImGui.Text("EditingThemeBuffer should not be null after BeginEditing"); + return SelfTestStepResult.Fail; + } + + var mutatedColors = registry.EditingThemeBuffer.Colors with { Primary = 0xFF112233 }; + registry.UpdateEditingBuffer(mutatedColors); + + if (fired != 1) + { + ImGui.Text($"Expected OnEditingBufferChanged once, got {fired}"); + return SelfTestStepResult.Fail; + } + + registry.DiscardEditingBuffer(); + + if (registry.EditingThemeBuffer is not null) + { + ImGui.Text("EditingThemeBuffer should be null after Discard"); + return SelfTestStepResult.Fail; + } + + if (registry.Active != originalActive) + { + ImGui.Text("Active theme should be unchanged after Discard"); + return SelfTestStepResult.Fail; + } + + return SelfTestStepResult.Pass; + } + finally + { + registry.OnEditingBufferChanged -= handler; + } } public void CleanUp() { }