1+ --!strict
2+
3+ local root = script .Parent .Parent .Parent .Parent .Parent .Parent .Parent .Parent ;
4+ local DialogueTypeDropdown = require (script .Parent );
5+ local VirtualService = require (root .VirtualService );
6+ local React = require (root .roblox_packages .react );
7+ local ReactErrorBoundary = require (root .roblox_packages .ReactErrorBoundary );
8+ local ErrorBoundary = ReactErrorBoundary .ErrorBoundary ;
9+ local ReactRoblox = require (root .roblox_packages ["react-roblox" ]);
10+ local IJW = require (root .roblox_packages .ijw );
11+ local expect = IJW .expect ;
12+ local describe = IJW .describe ;
13+ local it = IJW .it ;
14+ local VirtualSelection = require (root .DialogueEditor .mocks .Selection );
15+ local VirtualChangeHistoryService = require (root .DialogueEditor .mocks .ChangeHistoryService );
16+
17+ local screenGui : ScreenGui ? ;
18+ local reactRoot : ReactRoblox .RootType ? ;
19+ local propagatedErrorMessage ;
20+ local eventConnection : RBXScriptConnection ? ;
21+
22+ return {
23+
24+ describe ("DialogueTypeDropdown" , function ()
25+
26+ local function MockComponent (properties : any )
27+
28+ local selectedScript = properties .selectedScript ;
29+ local onErrored = properties .onErrored or function () end ;
30+ local onRendered = properties .onRendered or function () end ;
31+
32+ React .useEffect (function ()
33+
34+ onRendered ();
35+
36+ end , {onRendered });
37+
38+ return React .createElement (ErrorBoundary , {
39+ FallbackComponent = React .Fragment ;
40+ onError = onErrored ;
41+ }, {
42+ React .createElement (DialogueTypeDropdown , {
43+ selectedScript = selectedScript ;
44+ selectedDialogueType = selectedScript :GetAttribute ("DialogueType" ) or "Conversation" ;
45+ layoutOrder = 1 ;
46+ })
47+ });
48+
49+ end ;
50+
51+ local function verifyReactStatus ()
52+
53+ if propagatedErrorMessage then
54+
55+ error (propagatedErrorMessage );
56+
57+ end ;
58+
59+ end ;
60+
61+ local function createDialogueScript (name : string , type : "Conversation" | "Message" | "Redirect" )
62+
63+ local dialogueScript = Instance .new ("ModuleScript" );
64+
65+ if type == "Conversation" then
66+
67+ dialogueScript :AddTag ("DialogueMakerConversationScript" );
68+
69+ else
70+
71+ dialogueScript :AddTag ("DialogueMakerDialogueScript" );
72+ dialogueScript :SetAttribute ("DialogueType" , type );
73+
74+ end ;
75+
76+ return dialogueScript ;
77+
78+ end ;
79+
80+ local function render (type : "Conversation" | "Message" | "Redirect" ): ModuleScript
81+
82+ assert (reactRoot , "React root should be initialized before running tests." );
83+
84+ local selectedScript = createDialogueScript ("TestDialogueScript" , type );
85+ local didRender = false ;
86+ local element = React .createElement (MockComponent , {
87+ selectedScript = selectedScript ;
88+ onErrored = function (errorMessage )
89+
90+ propagatedErrorMessage = errorMessage ;
91+
92+ end ;
93+ onRendered = function ()
94+
95+ didRender = true ;
96+
97+ end ;
98+ });
99+
100+ reactRoot :render (element );
101+ repeat task.wait () until didRender or propagatedErrorMessage ;
102+ verifyReactStatus ();
103+
104+ return selectedScript ;
105+
106+ end ;
107+
108+ return {
109+
110+ it ("can show the selected type" , function ()
111+
112+ expect (function ()
113+
114+ local dialogueType = "Conversation" ;
115+ render (dialogueType :: any );
116+
117+ assert (screenGui , "ScreenGui should be initialized before running tests." );
118+ local dialogueTypeDropdown = screenGui :FindFirstChildOfClass ("Frame" );
119+ assert (dialogueTypeDropdown , "DialogueTypeDropdown should be rendered." );
120+
121+ local toggleButton = dialogueTypeDropdown :FindFirstChild ("ToggleButton" );
122+ assert (toggleButton , "ToggleButton should be present in DialogueTypeDropdown." );
123+
124+ local selectionFrame = toggleButton :FindFirstChild ("SelectionFrame" );
125+ assert (selectionFrame , "SelectionFrame should be present in ToggleButton." );
126+
127+ local textLabel = selectionFrame :FindFirstChild ("TextLabel" );
128+ assert (textLabel and textLabel :IsA ("TextLabel" ), "TextLabel should be present in SelectionFrame." );
129+ expect (textLabel .Text ).toBe (dialogueType );
130+
131+ end ).toFinishBeforeSeconds (1 );
132+
133+ end );
134+
135+ }
136+
137+ end , {
138+ beforeEach = function ()
139+
140+ local newScreenGui = Instance .new ("ScreenGui" );
141+ screenGui = newScreenGui ;
142+ reactRoot = ReactRoblox .createRoot (newScreenGui );
143+
144+ local virtualSelection = VirtualSelection .new ();
145+ local virtualChangeHistoryService = VirtualChangeHistoryService .new ();
146+ VirtualService .globals .game = {
147+ GetService = function (self , serviceName : string ): unknown
148+
149+ if serviceName == "Selection" then
150+
151+ return virtualSelection ;
152+
153+ elseif serviceName == "ChangeHistoryService" then
154+
155+ return virtualChangeHistoryService ;
156+
157+ end ;
158+
159+ return game :GetService (serviceName );
160+
161+ end ;
162+ };
163+
164+ end ;
165+ afterEach = function ()
166+
167+ if reactRoot then
168+
169+ reactRoot :unmount ();
170+ reactRoot = nil ;
171+
172+ end ;
173+
174+ if screenGui then
175+
176+ screenGui :Destroy ();
177+ screenGui = nil ;
178+
179+ end ;
180+
181+ if eventConnection then
182+
183+ eventConnection :Disconnect ();
184+ eventConnection = nil ;
185+
186+ end ;
187+
188+ propagatedErrorMessage = nil ;
189+ VirtualService .globals .game = game ;
190+
191+ end ;
192+ })
193+ };
0 commit comments