Skip to content

Commit f55966c

Browse files
Add test: DynamicContentCheckbox can toggle "IsDisabled" attribute on ContentScript (#189)
1 parent e534ce3 commit f55966c

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

src/DialogueEditor/components/Checkbox/init.luau

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,28 @@ local function Checkbox(properties: CheckboxProperties)
2424
local colors = useStudioColors();
2525
local icons = useStudioIcons();
2626
local buttonRef = React.useRef(nil :: TextButton?);
27-
28-
React.useEffect(function()
27+
28+
React.useEffect(function(): ()
2929

3030
local button = buttonRef.current;
3131
assert(button, "Button reference should not be nil.");
3232

33-
if isDisabled then return end;
33+
local activatedConnection: RBXScriptConnection? = nil;
3434

35-
local activatedConnection = VirtualService.events.GuiButton.Activated:getSignal(button):Connect(function()
35+
if not isDisabled then
3636

37-
onChanged(not isChecked);
37+
activatedConnection = VirtualService.events.GuiButton.Activated:getSignal(button):Connect(function()
3838

39-
end);
39+
onChanged(not isChecked);
40+
41+
end);
42+
43+
end;
44+
45+
button:SetAttribute("IsChecked", isChecked);
4046

4147
return function()
42-
48+
4349
if activatedConnection then
4450

4551
activatedConnection:Disconnect();
@@ -48,7 +54,7 @@ local function Checkbox(properties: CheckboxProperties)
4854

4955
end;
5056

51-
end, {onChanged :: unknown, isDisabled});
57+
end, {onChanged :: unknown, isDisabled, isChecked});
5258

5359
return React.createElement("Frame", {
5460
AutomaticSize = Enum.AutomaticSize.XY;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ local function DialogueTypeDropdown(properties: DialogueTypeDropdownProperties)
7070

7171
end;
7272

73-
task.wait();
7473
Selection:Set({selectedScript});
7574

7675
finishHistoryRecording(historyIdentifier);

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,39 @@ return {
125125
end).toFinishBeforeSeconds(1);
126126

127127
end);
128+
129+
it(`can toggle "IsDisabled" attribute on ContentScript`, function()
130+
131+
expect(function()
132+
133+
local selectedScript = render("Message");
134+
135+
assert(screenGui, "ScreenGui should be initialized before running tests.");
136+
local dynamicContentCheckbox = screenGui:FindFirstChildOfClass("Frame");
137+
assert(dynamicContentCheckbox, "DynamicContentCheckbox should be rendered.");
138+
139+
local checkbox = dynamicContentCheckbox:FindFirstChild("Checkbox");
140+
assert(checkbox and checkbox:IsA("TextButton"), "Checkbox should be rendered inside DynamicContentCheckbox.");
141+
142+
VirtualService.events.GuiButton.Activated:fireEvent(checkbox);
143+
local contentScript = selectedScript:WaitForChild("ContentScript");
144+
verifyReactStatus();
145+
checkbox:GetAttributeChangedSignal("IsChecked"):Wait();
146+
expect(contentScript:GetAttribute("IsDisabled")).toBe(false);
147+
148+
VirtualService.events.GuiButton.Activated:fireEvent(checkbox);
149+
checkbox:GetAttributeChangedSignal("IsChecked"):Wait();
150+
verifyReactStatus();
151+
expect(contentScript:GetAttribute("IsDisabled")).toBe(true);
152+
153+
VirtualService.events.GuiButton.Activated:fireEvent(checkbox);
154+
checkbox:GetAttributeChangedSignal("IsChecked"):Wait();
155+
verifyReactStatus();
156+
expect(contentScript:GetAttribute("IsDisabled")).toBe(false);
157+
158+
end).toFinishBeforeSeconds(1);
159+
160+
end);
128161

129162
}
130163

src/DialogueEditor/components/Explorer/components/Preview/hooks/useDialogueContentScript.luau

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ local function useDialogueContentScript(dialogueScript: ModuleScript): (ModuleSc
3131

3232
local childAddedConnection = dialogueScript.ChildAdded:Connect(updateDialogueContentScript);
3333
local childRemovedConnection = dialogueScript.ChildRemoved:Connect(updateDialogueContentScript);
34-
updateDialogueContentScript();
34+
task.spawn(updateDialogueContentScript);
3535

3636
return function()
3737

0 commit comments

Comments
 (0)