Skip to content

Commit 6af6e51

Browse files
Add test: DialogueOptions can initialize action scripts (#176)
1 parent 40da563 commit 6af6e51

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

src/DialogueEditor/components/DropdownOption/init.luau

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
local root = script.Parent.Parent.Parent;
44
local React = require(root.roblox_packages.react);
55
local useStudioColors = require(root.DialogueEditor.hooks.useStudioColors);
6+
local VirtualService = require(root.VirtualService);
67

78
export type DropdownOptionProperties = {
89
layoutOrder: number;
@@ -14,15 +15,34 @@ export type DropdownOptionProperties = {
1415
local function DropdownOption(props: DropdownOptionProperties)
1516

1617
local colors = useStudioColors();
18+
local buttonRef = React.useRef(nil);
19+
20+
React.useEffect(function()
21+
local button = buttonRef.current;
22+
assert(button and button:IsA("TextButton"), "Button reference is not a TextButton");
23+
24+
local connection = VirtualService.events.GuiButton.Activated:getSignal(button):Connect(function()
25+
26+
props.onClick();
27+
28+
end);
29+
30+
return function()
31+
32+
connection:Disconnect();
33+
34+
end;
35+
end, {props.onClick});
1736

1837
return React.createElement("TextButton", {
1938
LayoutOrder = props.layoutOrder;
2039
Size = UDim2.new(1, 0, 0, 25);
2140
BackgroundColor3 = colors.backgroundTableRow;
2241
Text = "";
23-
[React.Event.Activated] = function()
42+
ref = buttonRef;
43+
[React.Event.Activated] = function(self)
2444

25-
props.onClick();
45+
VirtualService.events.GuiButton.Activated:fireEvent(self);
2646

2747
end;
2848
BorderSizePixel = 0;

src/DialogueEditor/components/Explorer/components/Preview/components/DialogueOptions/DialogueOptions.test.luau

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,35 @@ return {
221221
end).toFinishBeforeSeconds(1);
222222

223223
end);
224+
225+
it("can initialize action scripts", function()
226+
227+
expect(function()
228+
229+
local selectedScript = render("Message");
230+
231+
assert(screenGui, "ScreenGui should be initialized before running tests.");
232+
local dialogueOptions = screenGui:FindFirstChildOfClass("Frame");
233+
assert(dialogueOptions, "DialogueOptions should be rendered.");
234+
235+
local actionsDropdown = dialogueOptions:FindFirstChild("ActionsDropdown");
236+
assert(actionsDropdown, "Actions dropdown should be present in the DialogueOptions.");
237+
238+
local toggleButton = actionsDropdown:FindFirstChild("ToggleButton");
239+
assert(toggleButton and toggleButton:IsA("TextButton"), "Toggle button should be present in the ActionsDropdown.");
240+
241+
VirtualService.events.GuiButton.Activated:fireEvent(toggleButton);
242+
243+
local optionsFrame = actionsDropdown:WaitForChild("OptionsFrame");
244+
local initializationButton = optionsFrame:FindFirstChild("InitializationButton");
245+
assert(initializationButton and initializationButton:IsA("TextButton"), "Initialization button should be present in the ActionsDropdown options.");
246+
247+
VirtualService.events.GuiButton.Activated:fireEvent(initializationButton);
248+
selectedScript:WaitForChild("InitializationActionScript");
249+
250+
end).toFinishBeforeSeconds(1);
251+
252+
end);
224253

225254
}
226255

test.project.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
"roblox_packages": {
2020
"$path": "roblox_packages"
2121
}
22+
},
23+
"runTests": {
24+
"$path": "runTests.luau"
2225
}
2326
}
2427
}

0 commit comments

Comments
 (0)