Skip to content

Commit

Permalink
Feedback changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeraymonddowning committed Apr 10, 2024
1 parent c356a43 commit 0842c47
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 41 deletions.
12 changes: 1 addition & 11 deletions src/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,7 @@ class FormBuilder
*/
public function add(Closure $step, ?string $name = null, bool $ignoreWhenReverting = false): self
{
return $this->when(true, $step, $name, $ignoreWhenReverting);
}

/**
* Add a step if the given condition evaluates to true.
*
* @param bool|(Closure(array<mixed>): bool) $condition
*/
public function when(bool|Closure $condition, Closure $step, ?string $name = null, bool $ignoreWhenReverting = false): self
{
$this->steps[] = new FormStep($step, $condition, $name, $ignoreWhenReverting);
$this->steps[] = new FormStep($step, true, $name, $ignoreWhenReverting);

return $this;
}
Expand Down
30 changes: 0 additions & 30 deletions tests/Feature/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,36 +110,6 @@
expect($responses)->toBe([true]);
});

it('can conditionally run a step', function () {
Prompt::fake([
Key::ENTER,
Key::DOWN, Key::ENTER,
]);

form()
->when(true, fn () => confirm('Are you sure?'), name: 'confirm')
->when(
fn (array $responses) => $responses['confirm'],
fn (array $responses) => outro('This should display')
)
->submit();

form()
->when(false, fn () => outro('This should not display'))
->submit();

form()
->confirm('Are you sure?', name: 'confirm')
->when(
fn (array $responses) => $responses['confirm'],
fn () => outro('This should not display')
)
->submit();

Prompt::assertOutputContains('This should display');
Prompt::assertOutputDoesntContain('This should not display');
});

it('skips steps over steps that have no user input when reverting', function () {
Prompt::fake([
'3', Key::ENTER,
Expand Down

0 comments on commit 0842c47

Please sign in to comment.