1+ --!strict
2+
3+ local root = script .Parent .Parent .Parent .Parent .Parent .Parent .Parent .Parent ;
4+ local AutoTriggerCheckbox = 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+
15+ local screenGui : ScreenGui ? ;
16+ local reactRoot : ReactRoblox .RootType ? ;
17+ local propagatedErrorMessage ;
18+
19+ return {
20+
21+ describe ("DialogueGroupContainer" , function ()
22+
23+ local function MockComponent (properties : any )
24+
25+ local selectedScript = properties .selectedScript ;
26+ local onErrored = properties .onErrored or function () end ;
27+ local onRendered = properties .onRendered or function () end ;
28+
29+ React .useEffect (function ()
30+
31+ onRendered ();
32+
33+ end , {onRendered });
34+
35+ return React .createElement (ErrorBoundary , {
36+ FallbackComponent = React .Fragment ;
37+ onError = onErrored ;
38+ }, {
39+ React .createElement (AutoTriggerCheckbox , {
40+ selectedScript = selectedScript ;
41+ layoutOrder = 1 ;
42+ })
43+ });
44+
45+ end ;
46+
47+ local function verifyReactStatus ()
48+
49+ if propagatedErrorMessage then
50+
51+ error (propagatedErrorMessage );
52+
53+ end ;
54+
55+ end ;
56+
57+ local function createDialogueScript (name : string )
58+
59+ local dialogueScript = Instance .new ("ModuleScript" );
60+ dialogueScript :AddTag ("DialogueMakerConversationScript" );
61+ return dialogueScript ;
62+
63+ end ;
64+
65+ local function render (): ModuleScript
66+
67+ assert (reactRoot , "React root should be initialized before running tests." );
68+
69+ local selectedScript = createDialogueScript ("TestDialogueScript" );
70+ local didRender = false ;
71+ local element = React .createElement (MockComponent , {
72+ selectedScript = selectedScript ;
73+ onErrored = function (errorMessage )
74+
75+ propagatedErrorMessage = errorMessage ;
76+
77+ end ;
78+ onRendered = function ()
79+
80+ didRender = true ;
81+
82+ end ;
83+ });
84+
85+ reactRoot :render (element );
86+ repeat task.wait () until didRender or propagatedErrorMessage ;
87+
88+ return selectedScript ;
89+
90+ end ;
91+
92+ return {
93+
94+ it (`can add "ShouldAutoTriggerConversation" tag to selected script` , function ()
95+
96+ expect (function ()
97+
98+ -- Render the component and wait for it to finish rendering.
99+ assert (screenGui , "ScreenGui should be initialized before running tests." );
100+ local selectedScript = render ();
101+ verifyReactStatus ();
102+
103+ -- Verify that the checkbox is unchecked.
104+ local checkboxFrame = screenGui :FindFirstChildOfClass ("Frame" );
105+ assert (checkboxFrame , "Frame should be present in the ScreenGui." );
106+
107+ local checkbox = checkboxFrame :FindFirstChild ("Checkbox" );
108+ assert (checkbox and checkbox :IsA ("TextButton" ), "Checkbox should be present in the frame." );
109+
110+ VirtualService .events .GuiButton .Activated :fireEvent (checkbox );
111+ expect (selectedScript :GetAttribute ("ShouldAutoTriggerConversation" )).toBe (true );
112+
113+ end ).toFinishBeforeSeconds (1 );
114+
115+ end );
116+
117+ }
118+
119+ end , {
120+ beforeEach = function ()
121+
122+ local newScreenGui = Instance .new ("ScreenGui" );
123+ screenGui = newScreenGui ;
124+ reactRoot = ReactRoblox .createRoot (newScreenGui );
125+
126+ end ;
127+ afterEach = function ()
128+
129+ if reactRoot then
130+
131+ reactRoot :unmount ();
132+
133+ end ;
134+
135+ if screenGui then
136+
137+ screenGui :Destroy ();
138+
139+ end ;
140+
141+ propagatedErrorMessage = nil ;
142+
143+ end ;
144+ })
145+ };
0 commit comments