33namespace Livewire \Features \SupportJsModules ;
44
55use Illuminate \Support \Facades \Route ;
6+ use Livewire \Component ;
67use Livewire \Livewire ;
78
89class BrowserTest extends \Tests \BrowserTestCase
@@ -17,6 +18,22 @@ public static function tweakApplicationHook()
1718 'Content-Type ' => 'application/javascript ' ,
1819 ]);
1920 });
21+
22+ Route ::get ('/slow-slot-module.js ' , function () {
23+ usleep (2_000_000 );
24+
25+ return response ("export let greeting = 'slot-alpine-data-loaded' " , 200 , [
26+ 'Content-Type ' => 'application/javascript ' ,
27+ ]);
28+ });
29+
30+ Route ::get ('/alpine-data-page ' , function () {
31+ return app ('livewire ' )->new ('testns::alpine-data.index ' )();
32+ })->middleware ('web ' );
33+
34+ Route ::get ('/alpine-data-page-2 ' , function () {
35+ return app ('livewire ' )->new ('testns::alpine-data.index ' )();
36+ })->middleware ('web ' );
2037 };
2138 }
2239
@@ -52,6 +69,108 @@ public function test_multi_file_component_js_supports_es_imports()
5269 ->waitForTextIn ('@target ' , 'js-import-loaded ' );
5370 }
5471
72+ public function test_alpine_data_is_available_during_initial_component_initialization ()
73+ {
74+ Livewire ::visit ('testns::alpine-data.index ' )
75+ ->waitForLivewireToLoad ()
76+ ->waitForTextIn ('@target ' , 'alpine-data-loaded ' )
77+ ->assertSeeIn ('@js-action ' , 'js-action-loaded ' )
78+ ->assertSeeIn ('@js-action-state ' , 'ready ' )
79+ ->assertConsoleLogHasNoErrors ();
80+ }
81+
82+ public function test_alpine_data_is_available_when_a_lazy_component_hydrates ()
83+ {
84+ Livewire ::visit ('testns::lazy-with-alpine-data ' )
85+ ->waitForTextIn ('@target ' , 'alpine-data-loaded ' )
86+ ->assertConsoleLogHasNoErrors ();
87+ }
88+
89+ public function test_alpine_data_is_available_when_a_component_is_added_dynamically ()
90+ {
91+ Livewire ::visit ([new class extends Component {
92+ public $ show = false ;
93+
94+ public function render ()
95+ {
96+ return <<<'HTML'
97+ <div>
98+ <button wire:click="$toggle('show')" dusk="toggle">Toggle</button>
99+
100+ @if ($show)
101+ <livewire:testns::alpine-data.index />
102+ @endif
103+ </div>
104+ HTML;
105+ }
106+ }])
107+ ->assertDontSee ('alpine-data-loaded ' )
108+ ->waitForLivewire ()->click ('@toggle ' )
109+ ->waitForTextIn ('@target ' , 'alpine-data-loaded ' )
110+ ->assertConsoleLogHasNoErrors ();
111+ }
112+
113+ public function test_alpine_data_is_available_in_a_slot_forwarded_through_a_lazy_component ()
114+ {
115+ Livewire ::visit ('testns::lazy-with-alpine-data-in-slot.parent ' )
116+ ->waitForTextIn ('@target ' , 'alpine-data-loaded ' )
117+ ->assertConsoleLogHasNoErrors ();
118+ }
119+
120+ public function test_alpine_data_is_available_when_an_existing_child_morphs_forwarded_slot_content ()
121+ {
122+ Livewire ::visit ('testns::lazy-slot-with-existing-wrapper.parent ' )
123+ ->assertSeeIn ('@target ' , 'Loading... ' )
124+ ->waitForTextIn ('@target ' , 'slot-alpine-data-loaded ' )
125+ ->assertConsoleLogHasNoErrors ();
126+ }
127+
128+ public function test_alpine_data_is_available_in_a_component_added_to_an_island ()
129+ {
130+ Livewire ::visit ('testns::island-with-alpine-data ' )
131+ ->assertSeeIn ('@placeholder ' , 'No child yet ' )
132+ ->waitForLivewire ()->click ('@toggle ' )
133+ ->waitForTextIn ('@target ' , 'alpine-data-loaded ' )
134+ ->assertConsoleLogHasNoErrors ();
135+ }
136+
137+ public function test_alpine_data_is_available_after_wire_navigate ()
138+ {
139+ Livewire ::visit ([new class extends Component {
140+ public function render ()
141+ {
142+ return <<<'HTML'
143+ <div>
144+ <div dusk="source-page">Source page</div>
145+ <a href="/alpine-data-page" wire:navigate dusk="link">Go to alpine data page</a>
146+ </div>
147+ HTML;
148+ }
149+ }])
150+ ->assertSeeIn ('@source-page ' , 'Source page ' )
151+ ->waitForNavigate ()->click ('@link ' )
152+ ->waitForTextIn ('@target ' , 'alpine-data-loaded ' )
153+ ->assertConsoleLogHasNoErrors ();
154+ }
155+
156+ public function test_alpine_data_module_remains_available_across_wire_navigate ()
157+ {
158+ Livewire ::visit ('testns::navigate-with-alpine-data ' )
159+ ->waitForTextIn ('@target ' , 'alpine-data-loaded ' )
160+ ->waitForNavigate ()->click ('@link ' )
161+ ->waitUntilMissing ('@first-page ' )
162+ ->waitForTextIn ('@target ' , 'alpine-data-loaded ' )
163+ ->assertConsoleLogHasNoErrors ();
164+ }
165+
166+ public function test_component_initialization_recovers_when_a_script_module_fails_to_import ()
167+ {
168+ Livewire ::visit ('testns::failed-module ' )
169+ ->waitForTextIn ('@ready ' , 'ready ' )
170+ ->waitForLivewire ()->click ('@increment ' )
171+ ->assertSeeIn ('@count ' , '1 ' );
172+ }
173+
55174 public function test_script_module_survives_a_back_navigation ()
56175 {
57176 // The `scriptModule` effect is only sent while mounting, so navigating
0 commit comments