Skip to content

Commit

Permalink
Fix form submit in wizard (#2193)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored Mar 29, 2024
1 parent accdc77 commit 1722c8e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
29 changes: 29 additions & 0 deletions demos/_unit-test/wizard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Atk4\Ui\Demos;

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

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

$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']);
});
6 changes: 3 additions & 3 deletions src/Behat/JsCoverageContextTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function saveJsCoverage(): void
throw new Error('"window.__coverage__" is not defined');
}
const transformCoverageFx = function (istanbulCoverage) {
const transformCoverageFx = function (istanbulCoverage, seenPaths) {
const res = {};
Object.entries(istanbulCoverage).forEach(([path, data]) => {
const resSingle = {};
Expand All @@ -66,7 +66,7 @@ protected function saveJsCoverage(): void
if (window.__coverage_beforeunload__ !== true) {
window.addEventListener('beforeunload', () => {
const navigateCoverages = JSON.parse(window.sessionStorage.getItem('__coverage_navigate__') ?? '[]');
navigateCoverages.push(transformCoverageFx(window.__coverage__));
navigateCoverages.push(transformCoverageFx(window.__coverage__, new Set()));
window.sessionStorage.setItem('__coverage_navigate__', JSON.stringify(navigateCoverages));
});
window.__coverage_beforeunload__ = true;
Expand All @@ -76,7 +76,7 @@ protected function saveJsCoverage(): void
const res = [];
for (const coverage of [windowCoverage, ...navigateCoverages]) {
res.push(transformCoverageFx(coverage));
res.push(transformCoverageFx(coverage, seenPaths));
}
return res;
Expand Down
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 1722c8e

Please sign in to comment.