Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/WizardServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 13 additions & 0 deletions tests/TestStepMacroTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
13 changes: 13 additions & 0 deletions tests/TestSupport/Components/Steps/MountStepComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Spatie\LivewireWizard\Tests\TestSupport\Components\Steps;

use Spatie\LivewireWizard\Components\StepComponent;

class MountStepComponent extends StepComponent
{
public function render()
{
return view('test::mount-step');
}
}
27 changes: 27 additions & 0 deletions tests/TestSupport/Components/WizardWithMountComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Spatie\LivewireWizard\Tests\TestSupport\Components;

use Spatie\LivewireWizard\Components\WizardComponent;
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;

class WizardWithMountComponent extends WizardComponent
{
public int $counter;

public function mount(int $counter): void
{
$this->counter = $counter;
}

public function steps(): array
{
return [
MountStepComponent::class,
];
}
}
2 changes: 2 additions & 0 deletions tests/TestSupport/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/TestSupport/resources/views/mount-step.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
Mount step
</div>
Loading