From 1722c8e8bc9fb68c959f50293c89b48ad0f8bbde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Fri, 29 Mar 2024 10:28:56 +0100 Subject: [PATCH] Fix form submit in wizard (#2193) --- demos/_unit-test/wizard.php | 29 ++++++++++++++++++++++++++++ src/Behat/JsCoverageContextTrait.php | 6 +++--- src/Wizard.php | 1 + tests-behat/wizard.feature | 18 +++++++++++++++++ 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 demos/_unit-test/wizard.php create mode 100644 tests-behat/wizard.feature diff --git a/demos/_unit-test/wizard.php b/demos/_unit-test/wizard.php new file mode 100644 index 0000000000..1b3033ecd2 --- /dev/null +++ b/demos/_unit-test/wizard.php @@ -0,0 +1,29 @@ +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']); +}); diff --git a/src/Behat/JsCoverageContextTrait.php b/src/Behat/JsCoverageContextTrait.php index 9ffbad9801..b3d60be253 100644 --- a/src/Behat/JsCoverageContextTrait.php +++ b/src/Behat/JsCoverageContextTrait.php @@ -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 = {}; @@ -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; @@ -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; diff --git a/src/Wizard.php b/src/Wizard.php index 530441a601..67659ed957 100644 --- a/src/Wizard.php +++ b/src/Wizard.php @@ -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; diff --git a/tests-behat/wizard.feature b/tests-behat/wizard.feature new file mode 100644 index 0000000000..a52455ef80 --- /dev/null +++ b/tests-behat/wizard.feature @@ -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"