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 @@ -11,6 +11,7 @@ local IJW = require(root.roblox_packages.ijw);
local expect = IJW.expect;
local describe = IJW.describe;
local it = IJW.it;
local VirtualSelection = require(root.DialogueEditor.mocks.Selection);

local screenGui: ScreenGui?;
local reactRoot: ReactRoblox.RootType?;
Expand Down Expand Up @@ -44,7 +45,7 @@ return {
}, {
React.createElement(DialogueGroupContainer, {
name = dialogueType;
plugin = VirtualService.mocks.globals.plugin;
plugin = VirtualService.globals.plugin;
layoutOrder = 1;
})
});
Expand Down Expand Up @@ -158,7 +159,7 @@ return {
assert(dialogueGroupContainer);

local dialogueFolder, selectedScript = initializeDialogueFolder(4);
VirtualService.mocks.services.Selection:Set({selectedScript});
VirtualService.globals.game:GetService("Selection"):Set({selectedScript});
dialogueGroupContainer.ChildAdded:Wait();
verifyReactStatus();
expect(#getDialogueItems(screenGui)).toBe(#dialogueFolder:GetChildren());
Expand Down Expand Up @@ -194,7 +195,7 @@ return {
assert(dialogueGroupContainer);

local dialogueFolder, selectedScript = initializeDialogueFolder(4);
VirtualService.mocks.services.Selection:Set({selectedScript});
VirtualService.globals.game:GetService("Selection"):Set({selectedScript});
dialogueGroupContainer.ChildAdded:Wait();
verifyReactStatus();
expect(#getDialogueItems(screenGui)).toBe(#dialogueFolder:GetChildren());
Expand All @@ -217,7 +218,7 @@ return {
-- 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});
VirtualService.globals.game:GetService("Selection"):Set({selectedScript});
render();
verifyReactStatus();

Expand Down Expand Up @@ -257,7 +258,7 @@ return {
conversationsFolder.Name = "Conversations";
conversationsFolder.Parent = conversationsFolderParent;

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

Expand Down Expand Up @@ -291,7 +292,7 @@ return {
local conversationScript = Instance.new("ModuleScript");
conversationScript:AddTag("DialogueMakerConversationScript");
conversationScript.Parent = conversationsFolder;
VirtualService.mocks.services.Selection:Set({conversationsFolderParent});
VirtualService.globals.game:GetService("Selection"):Set({conversationsFolderParent});

-- Render the component and wait for it to finish rendering.
assert(screenGui, "ScreenGui should be initialized before running tests.");
Expand All @@ -313,18 +314,29 @@ return {

end, {
beforeEach = function()

VirtualService.mocks.isEnabled = true;

local newScreenGui = Instance.new("ScreenGui");
screenGui = newScreenGui;
reactRoot = ReactRoblox.createRoot(newScreenGui);

local virtualSelection = VirtualSelection.new();
VirtualService.globals.game = {
GetService = function(self, serviceName: string)

if serviceName == "Selection" then

return virtualSelection;

end;

return game:GetService(serviceName);

end;
}

end;
afterEach = function()

VirtualService.mocks.isEnabled = false;

if reactRoot then

reactRoot:unmount();
Expand All @@ -337,12 +349,13 @@ return {

end;

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

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

end;
})
});

};
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ return {

return React.createElement(DialogueGroup, {
name = dialogueType;
plugin = VirtualService.mocks.globals.plugin;
plugin = VirtualService.globals.plugin;
dialogueScripts = dialogueScripts;
layoutOrder = layoutOrder;
});
Expand Down Expand Up @@ -113,8 +113,6 @@ return {

end, {
beforeEach = function()

VirtualService.mocks.isEnabled = true;

local newScreenGui = Instance.new("ScreenGui");
screenGui = newScreenGui;
Expand All @@ -123,8 +121,6 @@ return {
end;
afterEach = function()

VirtualService.mocks.isEnabled = false;

if reactRoot then

reactRoot:unmount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
local root = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent;
local DialogueItem = require(script.Parent);
local VirtualService = require(root.VirtualService);
local VirtualSelection = require(root.DialogueEditor.mocks.Selection);
local VirtualChangeHistoryService = require(root.DialogueEditor.mocks.ChangeHistoryService);
local React = require(root.roblox_packages.react);
local ReactErrorBoundary = require(root.roblox_packages.ReactErrorBoundary);
local ErrorBoundary = ReactErrorBoundary.ErrorBoundary;
Expand Down Expand Up @@ -110,7 +112,7 @@ return {
assert(viewButton and viewButton:IsA("GuiButton"), "ViewButton should be present in the DialogueItem.");

local didSelectionChange = false;
VirtualService.mocks.services.Selection.SelectionChanged:Once(function()
VirtualService.globals.game:GetService("Selection").SelectionChanged:Once(function()

didSelectionChange = true;

Expand Down Expand Up @@ -305,17 +307,35 @@ return {

end, {
beforeEach = function()

VirtualService.mocks.isEnabled = true;

local newScreenGui = Instance.new("ScreenGui");
screenGui = newScreenGui;
reactRoot = ReactRoblox.createRoot(newScreenGui);

local virtualSelection = VirtualSelection.new();
local virtualChangeHistoryService = VirtualChangeHistoryService.new();
VirtualService.globals.game = {
GetService = function(self, serviceName: string): unknown

if serviceName == "Selection" then

return virtualSelection;

elseif serviceName == "ChangeHistoryService" then

return virtualChangeHistoryService;

end;

return VirtualService.globals.game:GetService(serviceName);

end;
}

end;
afterEach = function()

VirtualService.mocks.isEnabled = false;
VirtualService.globals.game = game;

if reactRoot then

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
--!strict

local Selection = game:GetService("Selection");

local root = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent;
local VirtualService = require(root.VirtualService);
local React = require(root.roblox_packages.react);
Expand All @@ -22,7 +20,8 @@ local function DialogueItem(props: DialogueItemProperties)

-- Replace services with VirtualService services for testing.
-- VirtualService services are used to mock specific Roblox services in tests.
Selection = if VirtualService.mocks.isEnabled then VirtualService.mocks.services.Selection else Selection;
local game = VirtualService.globals.game;
local Selection = game:GetService("Selection");

local dialogueType = props.type;
local dialogueScript = props.dialogueScript;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
local root = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent;
local React = require(root.roblox_packages.react);
local DialogueItem = require(script.components.DialogueItem);
local VirtualService = require(root.VirtualService);

export type DialogueItemType = DialogueItem.DialogueItemType;

Expand All @@ -19,7 +18,7 @@ local function DialogueGroup(properties: DialogueGroupProperties)
local groupName = properties.name;
local dialogueScripts = properties.dialogueScripts;
local layoutOrder = properties.layoutOrder;
local plugin = if VirtualService.mocks.isEnabled then VirtualService.mocks.globals.plugin else properties.plugin;
local plugin = properties.plugin;

local scriptComponents = {};
for index, dialogueScript in dialogueScripts do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
--!strict

local Selection = game:GetService("Selection");

local root = script.Parent.Parent.Parent.Parent.Parent;
local VirtualService = require(root.VirtualService);
local React = require(root.roblox_packages.react);
Expand All @@ -22,7 +20,8 @@ export type DialogueTableBodyProperties = {

local function DialogueGroupContainer(props: DialogueTableBodyProperties)

Selection = if VirtualService.mocks.isEnabled then VirtualService.mocks.services.Selection else Selection;
local game = VirtualService.globals.game;
local Selection = game:GetService("Selection");

local layoutOrder = props.layoutOrder;
local selectedScript = useDialogueMakerScriptSelection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local StarterPlayer = game:GetService("StarterPlayer");
local root = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent;
local AutoTriggerCheckbox = require(script.Parent);
local VirtualService = require(root.VirtualService);
local VirtualChangeHistoryService = require(root.DialogueEditor.mocks.ChangeHistoryService);
local React = require(root.roblox_packages.react);
local ReactErrorBoundary = require(root.roblox_packages.ReactErrorBoundary);
local ErrorBoundary = ReactErrorBoundary.ErrorBoundary;
Expand Down Expand Up @@ -197,6 +198,21 @@ return {
screenGui = newScreenGui;
reactRoot = ReactRoblox.createRoot(newScreenGui);

local virtualChangeHistoryService = VirtualChangeHistoryService.new();
VirtualService.globals.game = {
GetService = function(self, serviceName: string): unknown

if serviceName == "ChangeHistoryService" then

return virtualChangeHistoryService;

end;

return game:GetService(serviceName);

end;
};

end;
afterEach = function()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ local IJW = require(root.roblox_packages.ijw);
local expect = IJW.expect;
local describe = IJW.describe;
local it = IJW.it;
local VirtualSelection = require(root.DialogueEditor.mocks.Selection);
local VirtualChangeHistoryService = require(root.DialogueEditor.mocks.ChangeHistoryService);

local screenGui: ScreenGui?;
local reactRoot: ReactRoblox.RootType?;
local propagatedErrorMessage;
local eventConnection: RBXScriptConnection?;
local didOpenScript = false;

return {

Expand All @@ -39,7 +42,7 @@ return {
}, {
React.createElement(DialogueOptions, {
selectedScript = selectedScript;
plugin = VirtualService.mocks.globals.plugin;
plugin = VirtualService.globals.plugin;
selectedDialogueType = selectedScript:GetAttribute("DialogueType") or "Conversation";
layoutOrder = 1;
})
Expand Down Expand Up @@ -250,6 +253,25 @@ return {
end).toFinishBeforeSeconds(1);

end);

it("can request to open condition script in Roblox script editor", function()

expect(function()

render("Message");

assert(screenGui, "ScreenGui should be initialized before running tests.");
local dialogueOptions = screenGui:FindFirstChildOfClass("Frame");
assert(dialogueOptions, "DialogueOptions should be rendered.");

local conditionButton = dialogueOptions:FindFirstChild("ConditionButton");
assert(conditionButton and conditionButton:IsA("TextButton"), "Condition button should be present in the DialogueOptions.");
VirtualService.events.GuiButton.Activated:fireEvent(conditionButton);
repeat task.wait() until didOpenScript or propagatedErrorMessage;

end).toFinishBeforeSeconds(1);

end);

}

Expand All @@ -259,7 +281,34 @@ return {
local newScreenGui = Instance.new("ScreenGui");
screenGui = newScreenGui;
reactRoot = ReactRoblox.createRoot(newScreenGui);
VirtualService.mocks.isEnabled = true;

local virtualSelection = VirtualSelection.new();
local virtualChangeHistoryService = VirtualChangeHistoryService.new();
VirtualService.globals.game = {
GetService = function(self, serviceName: string): unknown

if serviceName == "Selection" then

return virtualSelection;

elseif serviceName == "ChangeHistoryService" then

return virtualChangeHistoryService;

end;

return game:GetService(serviceName);

end;
};

VirtualService.globals.plugin = {
OpenScript = function(script)

didOpenScript = true;

end
} :: any;

end;
afterEach = function()
Expand All @@ -286,7 +335,9 @@ return {
end;

propagatedErrorMessage = nil;
VirtualService.mocks.isEnabled = false;
VirtualService.globals.game = game;
VirtualService.globals.plugin = plugin;
didOpenScript = false;

end;
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
--!strict

local Selection = game:GetService("Selection");

local root = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent;
local React = require(root.roblox_packages.react);
local Button = require(root.DialogueEditor.components.Button);
Expand All @@ -23,7 +21,7 @@ export type DialogueOptionsProperties = {

local function DialogueOptions(properties: DialogueOptionsProperties)

Selection = if VirtualService.mocks.isEnabled then VirtualService.mocks.services.Selection else Selection;
local Selection = VirtualService.globals.game:GetService("Selection");

local selectedScript = properties.selectedScript;
local selectedDialogueType = properties.selectedDialogueType;
Expand Down
Loading