diff --git a/Editor/MCPTestWindow.cs b/Editor/MCPTestWindow.cs index 61ba84f..be33c69 100644 --- a/Editor/MCPTestWindow.cs +++ b/Editor/MCPTestWindow.cs @@ -9,7 +9,7 @@ namespace UnityMCP.Editor /// /// /// The window builds a TextField, Button, and Label with stable names. Verification helpers show the window, reset state, - /// send UI automation JSON-RPC calls, and assert that UI callbacks update the static test state. + /// send UI automation JSON-RPC calls, and assert that UI callbacks update this window's test state. /// public class MCPTestWindow : EditorWindow { @@ -18,15 +18,15 @@ public class MCPTestWindow : EditorWindow /// /// Stores the last input value for verification. /// - public static string LastInputValue = ""; + public string LastInputValue { get; private set; } = ""; /// /// Tracks if the test button has been clicked. /// - public static bool ButtonClicked = false; + public bool ButtonClicked { get; private set; } /// - /// Resets static test flags and clears the UI Toolkit input/label elements in the current visual tree. + /// Resets this window's test state and clears the UI Toolkit input/label elements in the current visual tree. /// public void ResetState() { @@ -58,7 +58,7 @@ private void OnEnable() /// Creates named UI Toolkit controls and event handlers used by Nexus Unity UI automation smoke tests. /// /// - /// This method mutates , resets static test state, registers a text-change + /// This method mutates , preserves instance test state, registers a text-change /// callback, and wires the button click to update the label and . /// public void CreateGUI() @@ -66,9 +66,6 @@ public void CreateGUI() NexusEditorUi.SetupRoot(rootVisualElement); rootVisualElement.name = "NexusTestWindowRoot"; - LastInputValue = ""; - ButtonClicked = false; - var header = NexusEditorUi.Panel("TestWindowHeader"); header.Add(NexusEditorUi.Label("UI Automation Test", 16, true)); header.Add(NexusEditorUi.Label("Named controls used by Nexus Unity UI automation checks.", 11, false, NexusEditorUi.Muted)); @@ -76,7 +73,7 @@ public void CreateGUI() var panel = NexusEditorUi.Panel("TestWindowControls"); - var label = new Label("Initial State"); + var label = new Label(ButtonClicked ? "Button Clicked!" : "Initial State"); label.name = "TestLabel"; label.style.marginBottom = 8; label.style.unityFontStyleAndWeight = FontStyle.Bold; @@ -85,8 +82,7 @@ public void CreateGUI() var textField = new TextField("Input:"); textField.name = "TestInput"; textField.style.marginBottom = 8; - textField.value = ""; - LastInputValue = textField.value; + textField.value = LastInputValue; textField.RegisterValueChangedCallback(evt => LastInputValue = evt.newValue); panel.Add(textField); diff --git a/Editor/UIVerification.cs b/Editor/UIVerification.cs index 80c5680..848e882 100644 --- a/Editor/UIVerification.cs +++ b/Editor/UIVerification.cs @@ -26,7 +26,7 @@ public static void Verify() wnd.ResetState(); TestListAndHierarchy(); - TestInputAndClick(); + TestInputAndClick(wnd); NexusEditorLog.Log(NexusLogCategory.Diagnostics, "VERIFICATION SUCCESS", true); } @@ -38,13 +38,13 @@ private static void TestListAndHierarchy() if (!hier.Contains("TestButton")) throw new System.Exception("Hierarchy failed"); } - private static void TestInputAndClick() + private static void TestInputAndClick(MCPTestWindow wnd) { string txt = "Test"; Call("ui_input_text", new JObject { ["window_title"] = MCPTestWindow.WindowTitle, ["element_name"] = "TestInput", ["text"] = txt }); - if (MCPTestWindow.LastInputValue != txt) throw new System.Exception($"Input failed: expected '{txt}' but got '{MCPTestWindow.LastInputValue}'"); + if (wnd.LastInputValue != txt) throw new System.Exception($"Input failed: expected '{txt}' but got '{wnd.LastInputValue}'"); Call("ui_click", new JObject { ["window_title"] = MCPTestWindow.WindowTitle, ["element_name"] = "TestButton" }); - if (!MCPTestWindow.ButtonClicked) throw new System.Exception("Click failed"); + if (!wnd.ButtonClicked) throw new System.Exception("Click failed"); } private static string Call(string m, JObject p) diff --git a/Tests~/Editor/EditorWindowUiToolkitTests.cs b/Tests~/Editor/EditorWindowUiToolkitTests.cs index 5a8fbb4..a0cc5a8 100644 --- a/Tests~/Editor/EditorWindowUiToolkitTests.cs +++ b/Tests~/Editor/EditorWindowUiToolkitTests.cs @@ -130,6 +130,29 @@ public void TestWindowPreservesAutomationElementNames() } } + [Test] + public void TestWindowPreservesVerificationStateWhenRebuilt() + { + var window = ScriptableObject.CreateInstance(); + try + { + window.CreateGUI(); + window.rootVisualElement.Q("TestInput").value = "Persisted"; + window.rootVisualElement.Q