Skip to content

Commit 1a3e592

Browse files
Add tests: DialogueOptions hides non-initialization actions for "Redirect"-type dialogue scripts (#174)
1 parent 99ec972 commit 1a3e592

File tree

3 files changed

+62
-17
lines changed

3 files changed

+62
-17
lines changed

src/DialogueEditor/components/Dropdown/init.luau

Lines changed: 29 additions & 7 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 DropdownProps = {
89
text: string;
@@ -25,6 +26,26 @@ local function Dropdown(props: DropdownProps)
2526
local isOpen = props.isOpen;
2627
local setIsOpen = props.setIsOpen;
2728
local layoutOrder = props.layoutOrder or 0;
29+
local toggleButtonRef = React.useRef(nil);
30+
31+
React.useEffect(function()
32+
33+
local toggleButton = toggleButtonRef.current;
34+
assert(toggleButton, "Toggle button reference is nil.");
35+
36+
local connection = VirtualService.events.GuiButton.Activated:getSignal(toggleButton):Connect(function()
37+
38+
setIsOpen(not isOpen);
39+
40+
end);
41+
42+
return function()
43+
44+
connection:Disconnect();
45+
46+
end;
47+
48+
end, {isOpen :: unknown, setIsOpen});
2849

2950
return React.createElement("Frame", {
3051
BackgroundTransparency = 1;
@@ -43,9 +64,10 @@ local function Dropdown(props: DropdownProps)
4364
Size = UDim2.fromScale(1, 1);
4465
BackgroundColor3 = if props.isDisabled then Color3.new(0.501961, 0.501961, 0.501961) else colors.input;
4566
BackgroundTransparency = if props.isDisabled then 0.75 else 0;
46-
[React.Event.Activated] = if props.isDisabled then nil else function()
67+
ref = toggleButtonRef;
68+
[React.Event.Activated] = if props.isDisabled then nil else function(self)
4769

48-
setIsOpen(not isOpen);
70+
VirtualService.events.GuiButton.Activated:fireEvent(self);
4971

5072
end;
5173
Text = "";
@@ -121,15 +143,15 @@ local function Dropdown(props: DropdownProps)
121143
AutomaticCanvasSize = Enum.AutomaticSize.Y;
122144
AutomaticSize = Enum.AutomaticSize.Y;
123145
CanvasSize = UDim2.fromScale(1, 1);
124-
[React.Event.InputEnded] = function(self, input)
146+
-- [React.Event.InputEnded] = function(self, input)
125147

126-
if input == Enum.UserInputType.MouseButton1 then
148+
-- if input == Enum.UserInputType.MouseButton1 then
127149

128-
setIsOpen(not isOpen);
150+
-- setIsOpen(not isOpen);
129151

130-
end;
152+
-- end;
131153

132-
end;
154+
-- end;
133155
}, {
134156
UIListLayout = React.createElement("UIListLayout", {
135157
SortOrder = Enum.SortOrder.LayoutOrder;

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

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,30 +57,26 @@ return {
5757

5858
end;
5959

60-
local function createDialogueScript(name: string, type: "Conversation" | "Dialogue")
60+
local function createDialogueScript(name: string, type: "Conversation" | "Message" | "Redirect")
6161

6262
local dialogueScript = Instance.new("ModuleScript");
6363

6464
if type == "Conversation" then
6565

6666
dialogueScript:AddTag("DialogueMakerConversationScript");
6767

68-
elseif type == "Dialogue" then
69-
70-
dialogueScript:AddTag("DialogueMakerDialogueScript");
71-
dialogueScript:SetAttribute("DialogueType", "Message");
72-
7368
else
7469

75-
error("Invalid dialogue script type: " .. tostring(type));
70+
dialogueScript:AddTag("DialogueMakerDialogueScript");
71+
dialogueScript:SetAttribute("DialogueType", type);
7672

7773
end;
7874

7975
return dialogueScript;
8076

8177
end;
8278

83-
local function render(type: "Conversation" | "Dialogue"): ModuleScript
79+
local function render(type: "Conversation" | "Message" | "Redirect"): ModuleScript
8480

8581
assert(reactRoot, "React root should be initialized before running tests.");
8682

@@ -164,7 +160,7 @@ return {
164160

165161
expect(function()
166162

167-
render("Dialogue");
163+
render("Message");
168164

169165
assert(screenGui, "ScreenGui should be initialized before running tests.");
170166
local dialogueOptions = screenGui:FindFirstChildOfClass("Frame");
@@ -179,6 +175,33 @@ return {
179175
end).toFinishBeforeSeconds(1);
180176

181177
end);
178+
179+
it(`hides non-initialization actions for "Redirect"-type dialogue scripts`, function()
180+
181+
expect(function()
182+
183+
render("Redirect");
184+
185+
assert(screenGui, "ScreenGui should be initialized before running tests.");
186+
local dialogueOptions = screenGui:FindFirstChildOfClass("Frame");
187+
assert(dialogueOptions, "DialogueOptions should be rendered.");
188+
189+
local actionsDropdown = dialogueOptions:FindFirstChild("ActionsDropdown");
190+
assert(actionsDropdown, "Actions dropdown should be present in the DialogueOptions.");
191+
192+
local toggleButton = actionsDropdown:FindFirstChild("ToggleButton");
193+
assert(toggleButton and toggleButton:IsA("TextButton"), "Toggle button should be present in the ActionsDropdown.");
194+
195+
VirtualService.events.GuiButton.Activated:fireEvent(toggleButton);
196+
197+
local optionsFrame = actionsDropdown:WaitForChild("OptionsFrame");
198+
expect(optionsFrame:FindFirstChild("InitializationButton")).toNotBe(nil);
199+
expect(optionsFrame:FindFirstChild("CompletionButton")).toBe(nil);
200+
expect(optionsFrame:FindFirstChild("CleanupButton")).toBe(nil);
201+
202+
end).toFinishBeforeSeconds(1);
203+
204+
end);
182205

183206
}
184207

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ local function DialogueOptions(properties: DialogueOptionsProperties)
7777
end;
7878

7979
local option = React.createElement(DropdownOption, {
80-
key = actionType :: string;
80+
key = `{actionType}Button`;
8181
text = actionType :: string;
8282
layoutOrder = index;
8383
onClick = function()

0 commit comments

Comments
 (0)