diff --git a/src/WizardServiceProvider.php b/src/WizardServiceProvider.php index e1a7f69..c4a60f2 100644 --- a/src/WizardServiceProvider.php +++ b/src/WizardServiceProvider.php @@ -27,8 +27,8 @@ public function bootingPackage() public function registerLivewireTestMacros() { - Component::macro('testStep', function (string $stepClass, array $state = []) { - $wizardComponent = Livewire::test(static::class, ['initialState' => $state]); + Component::macro('testStep', function (string $stepClass, array $state = [], array $params = []) { + $wizardComponent = Livewire::test(static::class, array_merge(['initialState' => $state], $params)); $wizard = $wizardComponent->invade(); $wizard->mountMountsWizard($stepClass, $state); diff --git a/tests/TestStepMacroTest.php b/tests/TestStepMacroTest.php index 9b7de43..a6e612d 100644 --- a/tests/TestStepMacroTest.php +++ b/tests/TestStepMacroTest.php @@ -2,7 +2,9 @@ use Spatie\LivewireWizard\Tests\TestSupport\Components\MyWizardComponent; use Spatie\LivewireWizard\Tests\TestSupport\Components\Steps\FirstStepComponent; +use Spatie\LivewireWizard\Tests\TestSupport\Components\Steps\MountStepComponent; use Spatie\LivewireWizard\Tests\TestSupport\Components\Steps\SecondStepComponent; +use Spatie\LivewireWizard\Tests\TestSupport\Components\WizardWithMountComponent; it('can test a step without state', function () { MyWizardComponent::testStep(FirstStepComponent::class) @@ -25,3 +27,14 @@ ], ]); })->throws(Exception::class); + +it('can test wizard with params', function () { + WizardWithMountComponent::testStep(MountStepComponent::class, params: [ + 'counter' => 999, + ]) + ->assertSee('Mount step'); +}); + +it('cant test wizard without params', function () { + WizardWithMountComponent::testStep(MountStepComponent::class); +})->throws(Exception::class); diff --git a/tests/TestSupport/Components/Steps/MountStepComponent.php b/tests/TestSupport/Components/Steps/MountStepComponent.php new file mode 100644 index 0000000..1f02d85 --- /dev/null +++ b/tests/TestSupport/Components/Steps/MountStepComponent.php @@ -0,0 +1,13 @@ +counter = $counter; + } + + public function steps(): array + { + return [ + MountStepComponent::class, + ]; + } +} diff --git a/tests/TestSupport/TestCase.php b/tests/TestSupport/TestCase.php index 1c34464..281228c 100644 --- a/tests/TestSupport/TestCase.php +++ b/tests/TestSupport/TestCase.php @@ -14,6 +14,7 @@ use Spatie\LivewireWizard\Tests\TestSupport\Components\Steps\CustomStateStepComponent; use Spatie\LivewireWizard\Tests\TestSupport\Components\Steps\FirstStepComponent; use Spatie\LivewireWizard\Tests\TestSupport\Components\Steps\FourthStepComponent; +use Spatie\LivewireWizard\Tests\TestSupport\Components\Steps\MountStepComponent; use Spatie\LivewireWizard\Tests\TestSupport\Components\Steps\SecondStepComponent; use Spatie\LivewireWizard\Tests\TestSupport\Components\Steps\ThirdStepComponent; use Spatie\LivewireWizard\WizardServiceProvider; @@ -50,6 +51,7 @@ private function registerLivewireComponents(): self Livewire::component('third-step', ThirdStepComponent::class); Livewire::component('fourth-step', FourthStepComponent::class); Livewire::component('custom-state-step', CustomStateStepComponent::class); + Livewire::component('mount-step', MountStepComponent::class); return $this; } diff --git a/tests/TestSupport/resources/views/mount-step.blade.php b/tests/TestSupport/resources/views/mount-step.blade.php new file mode 100644 index 0000000..50b6e73 --- /dev/null +++ b/tests/TestSupport/resources/views/mount-step.blade.php @@ -0,0 +1,3 @@ +