Skip to content

Commit

Permalink
Fix wizard form submit
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Mar 27, 2024
1 parent e75844b commit 2789a4c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
28 changes: 28 additions & 0 deletions demos/_unit-test/wizard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Atk4\Ui\Demos;

use Atk4\Ui\Form;
use Atk4\Ui\Header;
use Atk4\Ui\Wizard;

/** @var App $app */
require_once __DIR__ . '/../init-app.php';

Check failure on line 12 in demos/_unit-test/wizard.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

PHPDoc tag @var for variable $app contains unknown class Atk4\Ui\Demos\App.

$wizard = Wizard::addTo($app);

$stepFx = static function (Wizard $wizard) {
$form = Form::addTo($wizard);
$form->addControl('city', [], ['required' => true]);
$form->onSubmit(static function (Form $form) use ($wizard) {
return $wizard->jsNext();
});
};
$wizard->addStep(['Step 1'], $stepFx);
$wizard->addStep(['Step 2'], $stepFx);

$wizard->addFinish(static function (Wizard $wizard) {
Header::addTo($wizard, ['Wizard completed']);
});
1 change: 1 addition & 0 deletions src/Wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public function add($seed, $region = null): AbstractView
}

$this->buttonNext->on('click', $result->js()->submit());
$this->buttonFinish->on('click', $result->js()->submit());
}

return $result;
Expand Down
18 changes: 18 additions & 0 deletions tests-behat/wizard.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Feature: Wizard

Scenario: test form submit
Given I am on "_unit-test/wizard.php"
Then I check if text in "//div.ui.two.steps//div.ui.step.active" match text "Step 1"
Then I should not see "Must not be empty"
When I click using selector "//a[text()='Next']"
Then I should see "Must not be empty"
When I fill in "city" with "Prague"
When I click using selector "//a[text()='Next']"
Then I check if text in "//div.ui.two.steps//div.ui.step.active" match text "Step 2"
Then I should not see "Must not be empty"
When I click using selector "//a[text()='Finish']"
Then I should see "Must not be empty"
When I fill in "city" with "London"
Then I should not see "Wizard completed"
When I click using selector "//a[text()='Finish']"
Then I should see "Wizard completed"

0 comments on commit 2789a4c

Please sign in to comment.