diff --git a/src/DialogueEditor/components/DropdownOption/init.luau b/src/DialogueEditor/components/DropdownOption/init.luau index 8e592db4..b23eb55e 100644 --- a/src/DialogueEditor/components/DropdownOption/init.luau +++ b/src/DialogueEditor/components/DropdownOption/init.luau @@ -3,6 +3,7 @@ local root = script.Parent.Parent.Parent; local React = require(root.roblox_packages.react); local useStudioColors = require(root.DialogueEditor.hooks.useStudioColors); +local VirtualService = require(root.VirtualService); export type DropdownOptionProperties = { layoutOrder: number; @@ -14,15 +15,34 @@ export type DropdownOptionProperties = { local function DropdownOption(props: DropdownOptionProperties) local colors = useStudioColors(); + local buttonRef = React.useRef(nil); + + React.useEffect(function() + local button = buttonRef.current; + assert(button and button:IsA("TextButton"), "Button reference is not a TextButton"); + + local connection = VirtualService.events.GuiButton.Activated:getSignal(button):Connect(function() + + props.onClick(); + + end); + + return function() + + connection:Disconnect(); + + end; + end, {props.onClick}); return React.createElement("TextButton", { LayoutOrder = props.layoutOrder; Size = UDim2.new(1, 0, 0, 25); BackgroundColor3 = colors.backgroundTableRow; Text = ""; - [React.Event.Activated] = function() + ref = buttonRef; + [React.Event.Activated] = function(self) - props.onClick(); + VirtualService.events.GuiButton.Activated:fireEvent(self); end; BorderSizePixel = 0; diff --git a/src/DialogueEditor/components/Explorer/components/Preview/components/DialogueOptions/DialogueOptions.test.luau b/src/DialogueEditor/components/Explorer/components/Preview/components/DialogueOptions/DialogueOptions.test.luau index c48fb2fb..3dcf4581 100644 --- a/src/DialogueEditor/components/Explorer/components/Preview/components/DialogueOptions/DialogueOptions.test.luau +++ b/src/DialogueEditor/components/Explorer/components/Preview/components/DialogueOptions/DialogueOptions.test.luau @@ -221,6 +221,35 @@ return { end).toFinishBeforeSeconds(1); end); + + it("can initialize action scripts", function() + + expect(function() + + local selectedScript = render("Message"); + + assert(screenGui, "ScreenGui should be initialized before running tests."); + local dialogueOptions = screenGui:FindFirstChildOfClass("Frame"); + assert(dialogueOptions, "DialogueOptions should be rendered."); + + local actionsDropdown = dialogueOptions:FindFirstChild("ActionsDropdown"); + assert(actionsDropdown, "Actions dropdown should be present in the DialogueOptions."); + + local toggleButton = actionsDropdown:FindFirstChild("ToggleButton"); + assert(toggleButton and toggleButton:IsA("TextButton"), "Toggle button should be present in the ActionsDropdown."); + + VirtualService.events.GuiButton.Activated:fireEvent(toggleButton); + + local optionsFrame = actionsDropdown:WaitForChild("OptionsFrame"); + local initializationButton = optionsFrame:FindFirstChild("InitializationButton"); + assert(initializationButton and initializationButton:IsA("TextButton"), "Initialization button should be present in the ActionsDropdown options."); + + VirtualService.events.GuiButton.Activated:fireEvent(initializationButton); + selectedScript:WaitForChild("InitializationActionScript"); + + end).toFinishBeforeSeconds(1); + + end); } diff --git a/test.project.json b/test.project.json index 4bdc0cba..a79ae3dc 100644 --- a/test.project.json +++ b/test.project.json @@ -19,6 +19,9 @@ "roblox_packages": { "$path": "roblox_packages" } + }, + "runTests": { + "$path": "runTests.luau" } } }