Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ local it = IJW.it;

local screenGui: ScreenGui?;
local reactRoot: ReactRoblox.RootType?;
local propagatedErrorMessage;
local dialogueGroupContainer;
local dialogueGroup;

return {

describe("DialogueGroupContainer", function()

local function MockComponent(properties: any)

local dialogueType = properties.type or "Message";
local onRendered = properties.onRendered;
local selectedScript = properties.selectedScript;
local onErrored = properties.onErrored or function() end;

React.useEffect(function()
Expand All @@ -42,189 +45,203 @@ return {
React.createElement(DialogueGroupContainer, {
name = dialogueType;
plugin = VirtualService.mocks.globals.plugin;
selectedScript = selectedScript;
layoutOrder = 1;
})
});

end;

return {
local function verifyReactStatus()

it("refreshes the selected dialogue group if a dialogue script is added to a dialogue folder", function()
if propagatedErrorMessage then

expect(function()
error(propagatedErrorMessage);

-- Render the component and wait for it to finish rendering.
assert(screenGui, "ScreenGui should be initialized before running tests.");
assert(reactRoot, "React root should be initialized before running tests.");
end;

local messageCount = 4;
local dialogueFolder = Instance.new("Folder");
dialogueFolder.Name = "Messages";
end;

for i = 1, messageCount do
local function getDialogueItems(screenGui: ScreenGui): {Frame}

local dialogueScript = Instance.new("ModuleScript");
dialogueScript.Name = tostring(i);
dialogueScript:SetAttribute("DialogueType", "Message");
dialogueScript:AddTag("DialogueMakerDialogueScript");
dialogueScript.Parent = dialogueFolder;
dialogueGroupContainer = screenGui:FindFirstChildOfClass("Frame");
assert(dialogueGroupContainer, "DialogueGroupContainer should be rendered in the ScreenGui.");

end;
dialogueGroup = dialogueGroupContainer:FindFirstChild("DialogueGroup");
if not dialogueGroup then

local selectedScript = Instance.new("ModuleScript");
selectedScript:SetAttribute("DialogueType", "Message");
selectedScript:AddTag("DialogueMakerDialogueScript");
dialogueFolder.Parent = selectedScript;
return {};

local propagatedErrorMessage;
local didRender = false;
local element = React.createElement(MockComponent, {
selectedScript = selectedScript;
onErrored = function(errorMessage)
end;

propagatedErrorMessage = errorMessage;
local dialogueItems = {};
for _, child in dialogueGroup:GetChildren() do

end;
onRendered = function()

didRender = true;
if child:IsA("Frame") then

table.insert(dialogueItems, child);

end;

end;
});
end;

reactRoot:render(element);
repeat task.wait() until didRender or propagatedErrorMessage;
if propagatedErrorMessage then
return dialogueItems;

error(propagatedErrorMessage);
end;

end;
local function createDialogueScript(name: string)

-- Verify that there are four dialogue items rendered.
local dialogueGroupContainer = screenGui:FindFirstChildOfClass("Frame");
assert(dialogueGroupContainer, "DialogueGroupContainer should be rendered in the ScreenGui.");
local dialogueScript = Instance.new("ModuleScript");
dialogueScript.Name = name;
dialogueScript:SetAttribute("DialogueType", "Message");
dialogueScript:AddTag("DialogueMakerDialogueScript");
return dialogueScript;

local dialogueGroup = dialogueGroupContainer:FindFirstChild("DialogueGroup");
assert(dialogueGroup, "DialogueGroup should be rendered in the DialogueGroupContainer.");
end;

local function getDialogueItems()
local function initializeDialogueFolder(messageCount: number)

local dialogueItems = {};
for _, child in dialogueGroup:GetChildren() do
local dialogueFolder = Instance.new("Folder");
dialogueFolder.Name = "Messages";

if child:IsA("Frame") then

table.insert(dialogueItems, child);

end;
for i = 1, messageCount do

end;
local dialogueScript = createDialogueScript(tostring(i));
dialogueScript.Parent = dialogueFolder;

return dialogueItems;
end;

end;
local selectedScript = Instance.new("ModuleScript");
selectedScript:SetAttribute("DialogueType", "Message");
selectedScript:AddTag("DialogueMakerDialogueScript");
dialogueFolder.Parent = selectedScript;

expect(#getDialogueItems()).toBe(4);
return dialogueFolder, selectedScript;

-- Add a new dialogue script to the folder and verify that the component refreshes.
local newDialogueScript = Instance.new("ModuleScript");
newDialogueScript.Name = tostring(messageCount + 1);
newDialogueScript:SetAttribute("DialogueType", "Message");
newDialogueScript:AddTag("DialogueMakerDialogueScript");
newDialogueScript.Parent = dialogueFolder;
dialogueGroup.ChildAdded:Wait();
expect(#getDialogueItems()).toBe(5);
end;

end).toFinishBeforeSeconds(1);
local function render()

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

it("refreshes the selected dialogue group if a dialogue script is removed from a dialogue folder", function()
local didRender = false;
local element = React.createElement(MockComponent, {
onErrored = function(errorMessage)

expect(function()
propagatedErrorMessage = errorMessage;

-- Render the component and wait for it to finish rendering.
assert(screenGui, "ScreenGui should be initialized before running tests.");
assert(reactRoot, "React root should be initialized before running tests.");
end;
onRendered = function()

didRender = true;

local messageCount = 4;
local dialogueFolder = Instance.new("Folder");
dialogueFolder.Name = "Messages";
end;
});

local scriptToDestroy;
reactRoot:render(element);
repeat task.wait() until didRender or propagatedErrorMessage;

for i = 1, messageCount do
end;

local dialogueScript = Instance.new("ModuleScript");
dialogueScript.Name = tostring(i);
dialogueScript:SetAttribute("DialogueType", "Message");
dialogueScript:AddTag("DialogueMakerDialogueScript");
dialogueScript.Parent = dialogueFolder;
scriptToDestroy = dialogueScript;
return {

end;
it("refreshes the selected dialogue group if a dialogue script is added to a dialogue folder", function()

local selectedScript = Instance.new("ModuleScript");
selectedScript:SetAttribute("DialogueType", "Message");
selectedScript:AddTag("DialogueMakerDialogueScript");
dialogueFolder.Parent = selectedScript;
expect(function()

local propagatedErrorMessage;
local didRender = false;
local element = React.createElement(MockComponent, {
selectedScript = selectedScript;
onErrored = function(errorMessage)
-- Render the component and wait for it to finish rendering.
assert(screenGui, "ScreenGui should be initialized before running tests.");
render();
verifyReactStatus();

propagatedErrorMessage = errorMessage;
-- Verify that there are no dialogue items rendered.
expect(#getDialogueItems(screenGui)).toBe(0);
assert(dialogueGroupContainer);

end;
onRendered = function()

didRender = true;
local dialogueFolder, selectedScript = initializeDialogueFolder(4);
VirtualService.mocks.services.Selection:Set({selectedScript});
dialogueGroupContainer.ChildAdded:Wait();
verifyReactStatus();
expect(#getDialogueItems(screenGui)).toBe(#dialogueFolder:GetChildren());

end;
});
-- Create a new dialogue script, but verify that it is not rendered yet.
assert(dialogueGroup);

reactRoot:render(element);
repeat task.wait() until didRender or propagatedErrorMessage;
if propagatedErrorMessage then
local newDialogueScript = createDialogueScript(tostring(#dialogueFolder:GetChildren() + 1));
verifyReactStatus();
expect(#getDialogueItems(screenGui)).toBe(#dialogueFolder:GetChildren());

error(propagatedErrorMessage);
-- Add the new dialogue script to the folder and verify that it is rendered.
newDialogueScript.Parent = dialogueFolder;
dialogueGroup.ChildAdded:Wait();
verifyReactStatus();
expect(#getDialogueItems(screenGui)).toBe(#dialogueFolder:GetChildren());

end).toFinishBeforeSeconds(1);

end);

it("refreshes the selected dialogue group if a dialogue script is removed from a dialogue folder", function()

end;
expect(function()

-- Verify that there are four dialogue items rendered.
local dialogueGroupContainer = screenGui:FindFirstChildOfClass("Frame");
assert(dialogueGroupContainer, "DialogueGroupContainer should be rendered in the ScreenGui.");
-- Render the component and wait for it to finish rendering.
assert(screenGui, "ScreenGui should be initialized before running tests.");
render();
verifyReactStatus();

local dialogueGroup = dialogueGroupContainer:FindFirstChild("DialogueGroup");
assert(dialogueGroup, "DialogueGroup should be rendered in the DialogueGroupContainer.");
-- Verify that there are no dialogue items rendered.
expect(#getDialogueItems(screenGui)).toBe(0);
assert(dialogueGroupContainer);

local function getDialogueItems()
local dialogueFolder, selectedScript = initializeDialogueFolder(4);
VirtualService.mocks.services.Selection:Set({selectedScript});
dialogueGroupContainer.ChildAdded:Wait();
verifyReactStatus();
expect(#getDialogueItems(screenGui)).toBe(#dialogueFolder:GetChildren());

local dialogueItems = {};
for _, child in dialogueGroup:GetChildren() do
-- Delete a new dialogue script and verify that it is not rendered.
assert(dialogueGroup);

if child:IsA("Frame") then

table.insert(dialogueItems, child);

end;
dialogueFolder:GetChildren()[1]:Destroy();
dialogueGroup.ChildRemoved:Wait();
verifyReactStatus();
expect(#getDialogueItems(screenGui)).toBe(#dialogueFolder:GetChildren());

end;
end).toFinishBeforeSeconds(1);

return dialogueItems;
end);

end;
it("refreshes the conversation group if a conversation is added", function()

expect(#getDialogueItems()).toBe(4);
expect(function()

-- Remove a dialogue script to the folder and verify that the component refreshes.
scriptToDestroy:Destroy();
dialogueGroup.ChildRemoved:Wait();
expect(#getDialogueItems()).toBe(3);
-- Render the component and wait for it to finish rendering.
assert(screenGui, "ScreenGui should be initialized before running tests.");
render();
verifyReactStatus();

-- Select the conversations folder parent and verify that there are no conversations rendered.
local conversationsFolderParent = Instance.new("Folder");
local conversationsFolder = Instance.new("Folder");
conversationsFolder.Name = "Conversations";
conversationsFolder.Parent = conversationsFolderParent;

VirtualService.mocks.services.Selection:Set({conversationsFolderParent});
verifyReactStatus();
expect(#getDialogueItems(screenGui)).toBe(#conversationsFolder:GetChildren());

-- Create a new conversation script, but verify that it is not rendered yet.
local conversationScript = Instance.new("ModuleScript");
conversationScript:AddTag("DialogueMakerConversationScript");
verifyReactStatus();
expect(#getDialogueItems(screenGui)).toBe(#conversationsFolder:GetChildren());

-- Add the conversation script to the conversations folder and verify that it is rendered.
conversationScript.Parent = conversationsFolder;
verifyReactStatus();
assert(dialogueGroup);
dialogueGroup.ChildAdded:Wait();
expect(#getDialogueItems(screenGui)).toBe(#conversationsFolder:GetChildren());

end).toFinishBeforeSeconds(1);

Expand Down Expand Up @@ -258,6 +275,12 @@ return {

end;

VirtualService.mocks.services.Selection:Set({});

propagatedErrorMessage = nil;
dialogueGroupContainer = nil;
dialogueGroup = nil;

end;
})
};
Loading