Tips for testing Wizard Steps?

How do you test a Wizard? Obviously you would need to be able to test validation at the step level and then a submit overall as well. Didn't see anything documented or really mentioned in discord lately either.
8 Replies
CGM
CGM10mo ago
I know it's been a while, but I just ran into this same problem. What I ended up doing, at least for testing validation is to call my final submit call that does the validation ($this->form->getState();) Then I just stick to normal ->assertHasFormErrors(['name' => 'required']); style tests. I.e.,
it('should require a name', function () {
livewire(CreateTenant::class)
->fillForm(['name' => ''])
->call('create')
->assertHasFormErrors(['name' => 'required']);
});
it('should require a name', function () {
livewire(CreateTenant::class)
->fillForm(['name' => ''])
->call('create')
->assertHasFormErrors(['name' => 'required']);
});
I see the per-step issue will be next for me to figure out. Will report back if I find anything interesting. 🙂 - Wizard Tests The wizard doesn't seem to matter too much when testing individual fields. As long as you're being specific you can test anywhere it seems. Just test as if all of the fields are on the same page. When you are ready to test the entire form, just fillForm() completely to ensure it will succeed. Otherwise stick to specific fields like in my example above. Other fields will be throwing errors all over the place of course, but when you target with ['field' => 'validation_type'] you're isolating what is being tested.
Mark Chaney
Mark ChaneyOP10mo ago
Yep, per step is the only issue
Anik
Anik8mo ago
have you been able to find any solution for this?
Mark Chaney
Mark ChaneyOP8mo ago
I think you ahve to simply ->call('next') or something like that
Anik
Anik8mo ago
have tried it. call('next') tries to find the method in the page itself.
CGM
CGM8mo ago
I have a 3 step wizard I was testing and I think I just ended up testing as if it was a single form. Maybe I have a different level of complexity, but looking over my tests I don't think I ended up doing anything special, just treating it as a standard long form.
Mark Chaney
Mark ChaneyOP8mo ago
right, but a key part of wizard validation would be testing at each step. Could be able to get to step 2 until step 1 validates
Anik
Anik8mo ago
I am talking about this scenerio as well

Did you find this page helpful?