From f27af15b9767335a9d6fbe1b8a397b973e68f237 Mon Sep 17 00:00:00 2001 From: Christian Toney Date: Sun, 29 Jun 2025 16:47:17 -0400 Subject: [PATCH] Add test: DynamicContentCheckbox can toggle "IsDisabled" attribute on ContentScript --- .../components/Checkbox/init.luau | 22 ++++++++----- .../components/DialogueTypeDropdown/init.luau | 1 - .../DynamicContentCheckbox.test.luau | 33 +++++++++++++++++++ .../hooks/useDialogueContentScript.luau | 2 +- 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/DialogueEditor/components/Checkbox/init.luau b/src/DialogueEditor/components/Checkbox/init.luau index 7077e86a..d0cb4a9e 100644 --- a/src/DialogueEditor/components/Checkbox/init.luau +++ b/src/DialogueEditor/components/Checkbox/init.luau @@ -24,22 +24,28 @@ local function Checkbox(properties: CheckboxProperties) local colors = useStudioColors(); local icons = useStudioIcons(); local buttonRef = React.useRef(nil :: TextButton?); - - React.useEffect(function() + + React.useEffect(function(): () local button = buttonRef.current; assert(button, "Button reference should not be nil."); - if isDisabled then return end; + local activatedConnection: RBXScriptConnection? = nil; - local activatedConnection = VirtualService.events.GuiButton.Activated:getSignal(button):Connect(function() + if not isDisabled then - onChanged(not isChecked); + activatedConnection = VirtualService.events.GuiButton.Activated:getSignal(button):Connect(function() - end); + onChanged(not isChecked); + + end); + + end; + + button:SetAttribute("IsChecked", isChecked); return function() - + if activatedConnection then activatedConnection:Disconnect(); @@ -48,7 +54,7 @@ local function Checkbox(properties: CheckboxProperties) end; - end, {onChanged :: unknown, isDisabled}); + end, {onChanged :: unknown, isDisabled, isChecked}); return React.createElement("Frame", { AutomaticSize = Enum.AutomaticSize.XY; diff --git a/src/DialogueEditor/components/Explorer/components/Preview/components/DialogueTypeDropdown/init.luau b/src/DialogueEditor/components/Explorer/components/Preview/components/DialogueTypeDropdown/init.luau index 654528d6..621994e5 100644 --- a/src/DialogueEditor/components/Explorer/components/Preview/components/DialogueTypeDropdown/init.luau +++ b/src/DialogueEditor/components/Explorer/components/Preview/components/DialogueTypeDropdown/init.luau @@ -70,7 +70,6 @@ local function DialogueTypeDropdown(properties: DialogueTypeDropdownProperties) end; - task.wait(); Selection:Set({selectedScript}); finishHistoryRecording(historyIdentifier); diff --git a/src/DialogueEditor/components/Explorer/components/Preview/components/DynamicContentCheckbox/DynamicContentCheckbox.test.luau b/src/DialogueEditor/components/Explorer/components/Preview/components/DynamicContentCheckbox/DynamicContentCheckbox.test.luau index 88f29c51..4ba3a268 100644 --- a/src/DialogueEditor/components/Explorer/components/Preview/components/DynamicContentCheckbox/DynamicContentCheckbox.test.luau +++ b/src/DialogueEditor/components/Explorer/components/Preview/components/DynamicContentCheckbox/DynamicContentCheckbox.test.luau @@ -125,6 +125,39 @@ return { end).toFinishBeforeSeconds(1); end); + + it(`can toggle "IsDisabled" attribute on ContentScript`, function() + + expect(function() + + local selectedScript = render("Message"); + + assert(screenGui, "ScreenGui should be initialized before running tests."); + local dynamicContentCheckbox = screenGui:FindFirstChildOfClass("Frame"); + assert(dynamicContentCheckbox, "DynamicContentCheckbox should be rendered."); + + local checkbox = dynamicContentCheckbox:FindFirstChild("Checkbox"); + assert(checkbox and checkbox:IsA("TextButton"), "Checkbox should be rendered inside DynamicContentCheckbox."); + + VirtualService.events.GuiButton.Activated:fireEvent(checkbox); + local contentScript = selectedScript:WaitForChild("ContentScript"); + verifyReactStatus(); + checkbox:GetAttributeChangedSignal("IsChecked"):Wait(); + expect(contentScript:GetAttribute("IsDisabled")).toBe(false); + + VirtualService.events.GuiButton.Activated:fireEvent(checkbox); + checkbox:GetAttributeChangedSignal("IsChecked"):Wait(); + verifyReactStatus(); + expect(contentScript:GetAttribute("IsDisabled")).toBe(true); + + VirtualService.events.GuiButton.Activated:fireEvent(checkbox); + checkbox:GetAttributeChangedSignal("IsChecked"):Wait(); + verifyReactStatus(); + expect(contentScript:GetAttribute("IsDisabled")).toBe(false); + + end).toFinishBeforeSeconds(1); + + end); } diff --git a/src/DialogueEditor/components/Explorer/components/Preview/hooks/useDialogueContentScript.luau b/src/DialogueEditor/components/Explorer/components/Preview/hooks/useDialogueContentScript.luau index cb970d6b..863757b7 100644 --- a/src/DialogueEditor/components/Explorer/components/Preview/hooks/useDialogueContentScript.luau +++ b/src/DialogueEditor/components/Explorer/components/Preview/hooks/useDialogueContentScript.luau @@ -31,7 +31,7 @@ local function useDialogueContentScript(dialogueScript: ModuleScript): (ModuleSc local childAddedConnection = dialogueScript.ChildAdded:Connect(updateDialogueContentScript); local childRemovedConnection = dialogueScript.ChildRemoved:Connect(updateDialogueContentScript); - updateDialogueContentScript(); + task.spawn(updateDialogueContentScript); return function()