From 9a3269806020cc0dd0849a4b097ae13f37e67e62 Mon Sep 17 00:00:00 2001 From: Christian Toney Date: Fri, 27 Jun 2025 14:12:52 -0400 Subject: [PATCH] Add test: DialogueGroupContainer refreshes the selected dialogue group if a dialogue script's static content is changed --- .../DialogueGroupContainer.test.luau | 42 ++++++++++++++++--- .../components/DialogueItem/init.luau | 18 +++++++- .../DialogueGroupContainer/init.luau | 5 +-- 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/DialogueGroupContainer.test.luau b/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/DialogueGroupContainer.test.luau index 03d7dfe..2b0fffe 100644 --- a/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/DialogueGroupContainer.test.luau +++ b/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/DialogueGroupContainer.test.luau @@ -200,10 +200,9 @@ return { expect(#getDialogueItems(screenGui)).toBe(#dialogueFolder:GetChildren()); -- Delete a new dialogue script and verify that it is not rendered. - assert(dialogueGroup); - + local dialogueItem = getDialogueItems(screenGui)[1] dialogueFolder:GetChildren()[1]:Destroy(); - dialogueGroup.ChildRemoved:Wait(); + dialogueItem.Destroying:Wait(); verifyReactStatus(); expect(#getDialogueItems(screenGui)).toBe(#dialogueFolder:GetChildren()); @@ -211,6 +210,38 @@ return { end); + it("refreshes the selected dialogue group if a dialogue script's static content is changed", function() + + expect(function() + + -- Render the component and wait for it to finish rendering. + assert(screenGui, "ScreenGui should be initialized before running tests."); + local dialogueFolder, selectedScript = initializeDialogueFolder(4); + VirtualService.mocks.services.Selection:Set({selectedScript}); + render(); + verifyReactStatus(); + + local dialogueItem = getDialogueItems(screenGui)[1]; + local viewButton = dialogueItem:FindFirstChild("ViewButton"); + assert(viewButton, "ViewButton should be present in the dialogue item."); + + local informationFrame = viewButton:FindFirstChild("InformationFrame"); + assert(informationFrame, "InformationFrame should be present in the ViewButton."); + + local descriptionLabel = informationFrame:FindFirstChild("DescriptionLabel"); + assert(descriptionLabel and descriptionLabel:IsA("TextLabel"), "DescriptionLabel should be present in the InformationFrame."); + + -- Verify that there are no dialogue items rendered. + local messageContent = "New content"; + dialogueFolder:GetChildren()[1]:SetAttribute("DialogueContent", messageContent); + verifyReactStatus(); + descriptionLabel:GetPropertyChangedSignal("Text"):Wait(); + expect(descriptionLabel.Text).toBe(messageContent); + + end).toFinishBeforeSeconds(1); + + end); + it("refreshes the conversation group if a conversation is added", function() expect(function() @@ -266,13 +297,12 @@ return { assert(screenGui, "ScreenGui should be initialized before running tests."); render(); verifyReactStatus(); - expect(#getDialogueItems(screenGui)).toBe(#conversationsFolder:GetChildren()); + local dialogueItem = getDialogueItems(screenGui)[1]; -- Delete the conversation script and verify that it is not rendered. - assert(dialogueGroup); conversationScript:Destroy(); + dialogueItem.Destroying:Wait(); verifyReactStatus(); - dialogueGroup.ChildRemoved:Wait(); expect(#getDialogueItems(screenGui)).toBe(#conversationsFolder:GetChildren()); end).toFinishBeforeSeconds(1); diff --git a/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/components/DialogueItem/init.luau b/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/components/DialogueItem/init.luau index d20877a..97d5b0e 100644 --- a/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/components/DialogueItem/init.luau +++ b/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/components/DialogueGroup/components/DialogueItem/init.luau @@ -33,7 +33,7 @@ local function DialogueItem(props: DialogueItemProperties) local colors = useStudioColors(); local beginHistoryRecording, finishHistoryRecording = useChangeHistory(); - local dialogueContent = dialogueScript:GetAttribute("DialogueContent"); + local dialogueContent, setDialogueContent = React.useState(dialogueScript:GetAttribute("DialogueContent")); local incrementPriority = React.useCallback(function(increment: number) @@ -150,6 +150,22 @@ local function DialogueItem(props: DialogueItemProperties) end, {increasePriority, decreasePriority, viewDialogue}); + React.useEffect(function() + + local dialogueContentChangedConnection = dialogueScript:GetAttributeChangedSignal("DialogueContent"):Connect(function() + + setDialogueContent(dialogueScript:GetAttribute("DialogueContent")); + + end); + + return function() + + dialogueContentChangedConnection:Disconnect(); + + end; + + end, {dialogueScript}); + return React.createElement("Frame", { AutomaticSize = Enum.AutomaticSize.Y; BackgroundTransparency = 1; diff --git a/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/init.luau b/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/init.luau index 2e264c1..479335f 100644 --- a/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/init.luau +++ b/src/DialogueEditor/components/Explorer/components/DialogueGroupContainer/init.luau @@ -200,17 +200,16 @@ local function DialogueGroupContainer(props: DialogueTableBodyProperties) errorBoundary.showBoundary(errorMessage); end; + + table.insert(contentScriptConnections, Selection.SelectionChanged:Connect(refreshTable)) end; - - local selectionChangedConnection = Selection.SelectionChanged:Connect(refreshTable); task.spawn(refreshTable); return function() cleanupConnections(); - selectionChangedConnection:Disconnect(); end;