From 768af7682f1d5904dfe31ffaeeb80602655bef07 Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Tue, 30 Jul 2024 12:20:32 +0100 Subject: [PATCH] clean up --- packages/forms/.stubs.php | 2 +- packages/forms/docs/09-testing.md | 16 ++++++++-------- packages/forms/src/Testing/TestsForms.php | 6 +++--- .../PostResource/Pages/CreatePostUsingWizard.php | 1 + 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/forms/.stubs.php b/packages/forms/.stubs.php index 889e4ee66b..0a286cb12f 100644 --- a/packages/forms/.stubs.php +++ b/packages/forms/.stubs.php @@ -89,7 +89,7 @@ namespace Livewire\Features\SupportTesting { public function parseNestedFormComponentActionComponentAndName(string | array $component, string | array $name, string $formName = 'form'): static {} - public function goToWizardStep(int $desiredStep, string $formName = 'form'): static {} + public function goToWizardStep(int $step, string $formName = 'form'): static {} public function goToNextWizardStep(string $formName = 'form'): static {} diff --git a/packages/forms/docs/09-testing.md b/packages/forms/docs/09-testing.md index 415b626a38..93f87ce25c 100644 --- a/packages/forms/docs/09-testing.md +++ b/packages/forms/docs/09-testing.md @@ -288,49 +288,49 @@ test('comments section is enabled' function () { ### Wizard -To call a wizard's next step, use the `goToNextWizardStep()` method: +To go to a wizard's next step, use `goToNextWizardStep()`: ```php use function Pest\Livewire\livewire; it('moves to next wizard step', function () { - livewire(CreatePostUsingWizard::class) + livewire(CreatePost::class) ->goToNextWizardStep() ->assertHasFormErrors(['title']); }); ``` -You can also go to the previous step by calling `goToPreviousWizardStep()` method: +You can also go to the previous step by calling `goToPreviousWizardStep()`: ```php use function Pest\Livewire\livewire; it('moves to next wizard step', function () { - livewire(CreatePostUsingWizard::class) + livewire(CreatePost::class) ->goToPreviousWizardStep() ->assertHasFormErrors(['title']); }); ``` -If you want to go to a specific step, use `goToWizardStep`, the `assertWizardCurrentStep` method can ensure you are on the desired step: +If you want to go to a specific step, use `goToWizardStep()`, then the `assertWizardCurrentStep` method which can ensure you are on the desired step without validation errors from the previous: ```php use function Pest\Livewire\livewire; it('moves to the wizards second step', function () { - livewire(CreatePostUsingWizard::class) + livewire(CreatePost::class) ->goToWizardStep(2) ->assertWizardCurrentStep(2); }); ``` -If you have multiple forms on a single component, any of the wizard test helpers can accept a formName parameter: +If you have multiple forms on a single Livewire component, any of the wizard test helpers can accept a `formName` parameter: ```php use function Pest\Livewire\livewire; it('moves to next wizard step only for fooForm', function () { - livewire(CreatePostUsingWizard::class) + livewire(CreatePost::class) ->goToNextWizardStep(formName: 'fooForm') ->assertHasFormErrors(['title'], formName: 'fooForm'); }); diff --git a/packages/forms/src/Testing/TestsForms.php b/packages/forms/src/Testing/TestsForms.php index d0910fd132..ceebdeda32 100644 --- a/packages/forms/src/Testing/TestsForms.php +++ b/packages/forms/src/Testing/TestsForms.php @@ -417,7 +417,7 @@ class TestsForms Assert::assertArrayHasKey( $step - 1, $wizard->getChildComponents(), - "Wizard does not have a step {$step}" + "Wizard does not have a step {$step}." ); return $this; @@ -438,7 +438,7 @@ class TestsForms Assert::assertEquals( $step, $current = $wizard->getCurrentStepIndex() + 1, - "Failed asserting that wizard is on step {$step}, current step is {$current}" + "Failed asserting that wizard is on step {$step}, current step is {$current}." ); return $this; @@ -447,7 +447,7 @@ class TestsForms public function goToWizardStep(): Closure { - return function (int $step = 1, string $formName = 'form'): static { + return function (int $step, string $formName = 'form'): static { /** @phpstan-ignore-next-line */ $this->assertWizardStepExists($step, $formName); diff --git a/tests/src/Panels/Fixtures/Resources/PostResource/Pages/CreatePostUsingWizard.php b/tests/src/Panels/Fixtures/Resources/PostResource/Pages/CreatePostUsingWizard.php index 2e821d6f41..4e8b30b93e 100644 --- a/tests/src/Panels/Fixtures/Resources/PostResource/Pages/CreatePostUsingWizard.php +++ b/tests/src/Panels/Fixtures/Resources/PostResource/Pages/CreatePostUsingWizard.php @@ -13,6 +13,7 @@ class CreatePostUsingWizard extends CreateRecord use HasWizard; protected static string $resource = PostResource::class; + public function getSteps(): array { return [