33namespace Tests \Feature \Livewire ;
44
55use App \Livewire \PurchaseModal ;
6- use Illuminate \Foundation \Testing \RefreshDatabase ;
76use Livewire \Livewire ;
87use PHPUnit \Framework \Attributes \Test ;
98use Tests \TestCase ;
109
1110class PurchaseModalTest extends TestCase
1211{
13- use RefreshDatabase;
14-
1512 #[Test]
16- public function purchase_modal_can_be_opened_with_plan ()
13+ public function purchase_modal_can_set_a_plan ()
1714 {
1815 Livewire::test (PurchaseModal::class)
19- ->call ('openModal ' , 'mini ' )
20- ->assertSet ('selectedPlan ' , 'mini ' )
21- ->assertSet ('showModal ' , true );
16+ ->call ('setPlan ' , 'mini ' )
17+ ->assertSet ('selectedPlan ' , 'mini ' );
2218 }
2319
2420 #[Test]
@@ -38,30 +34,28 @@ public function purchase_modal_can_be_closed()
3834 public function purchase_modal_validates_email ()
3935 {
4036 Livewire::test (PurchaseModal::class)
41- ->call ('openModal ' , 'mini ' )
4237 ->set ('email ' , 'invalid-email ' )
43- ->call ('emitEmail ' )
38+ ->call ('submit ' )
4439 ->assertHasErrors (['email ' => 'email ' ]);
4540 }
4641
4742 #[Test]
4843 public function purchase_modal_requires_email ()
4944 {
5045 Livewire::test (PurchaseModal::class)
51- ->call ('openModal ' , 'mini ' )
5246 ->set ('email ' , '' )
53- ->call ('emitEmail ' )
47+ ->call ('submit ' )
5448 ->assertHasErrors (['email ' => 'required ' ]);
5549 }
5650
5751 #[Test]
58- public function purchase_modal_emits_event_with_valid_email ()
52+ public function test_submit_action ()
5953 {
6054 Livewire::test (PurchaseModal::class)
61- ->call ('openModal ' , 'mini ' )
55+ ->call ('setPlan ' , 'mini ' )
6256 ->set ('email ' , 'valid@example.com ' )
63- ->call ('emitEmail ' )
64- ->assertDispatched ('email -submitted ' , [
57+ ->call ('submit ' )
58+ ->assertDispatched ('purchase-request -submitted ' , [
6559 'email ' => 'valid@example.com ' ,
6660 'plan ' => 'mini ' ,
6761 ]);
@@ -71,25 +65,9 @@ public function purchase_modal_emits_event_with_valid_email()
7165 public function purchase_modal_closes_after_emitting_event ()
7266 {
7367 Livewire::test (PurchaseModal::class)
74- ->call ('openModal ' , 'mini ' )
68+ ->call ('setPlan ' , 'mini ' )
7569 ->set ('email ' , 'valid@example.com ' )
76- ->call ('emitEmail ' )
70+ ->call ('submit ' )
7771 ->assertSet ('showModal ' , false );
7872 }
79-
80- #[Test]
81- public function purchase_modal_can_be_opened_via_alpine_event ()
82- {
83- $ component = Livewire::test (PurchaseModal::class);
84-
85- // Simulate the Alpine.js event
86- $ component ->dispatch ('open-purchase-modal ' , ['plan ' => 'pro ' ])
87- ->assertDispatched ('open-purchase-modal ' );
88-
89- // Since we can't directly test Alpine.js event handling in PHPUnit,
90- // we'll verify that the openModal method works as expected
91- $ component ->call ('openModal ' , 'pro ' )
92- ->assertSet ('selectedPlan ' , 'pro ' )
93- ->assertSet ('showModal ' , true );
94- }
9573}
0 commit comments