Skip to content

Commit

Permalink
add testcases - #
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-blok committed Sep 25, 2024
1 parent 457c28a commit 65d6808
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/Feature/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use function Laravel\Prompts\confirm;
use function Laravel\Prompts\form;
use function Laravel\Prompts\outro;
use function Laravel\Prompts\text;

it('can run multiple steps', function () {
Prompt::fake([
Expand Down Expand Up @@ -179,3 +180,50 @@

Prompt::assertOutputDoesntContain('This should not appear!');
});

it('can revert steps with conditions', function () {
Prompt::fake([
'L', 'u', 'k', 'e', Key::ENTER, // name
Key::DOWN, Key::ENTER, // JS
Key::CTRL_U, // revert
Key::UP, Key::ENTER, // PHP
'8', '.', '3', Key::ENTER, // version
Key::ENTER,
]);

$responses = form()
->text('What is your name?')
->select('What is your language?', ['PHP', 'JS'])
->add(fn ($responses) => text("Which version?"), condition: fn ($responses) => $responses[1] === 'PHP')
->confirm('Are you sure?')
->submit();

expect($responses)->toBe([
'Luke',
'PHP',
'8.3',
true,
]);
});

it('leaves skipped conditional field empty', function () {
Prompt::fake([
'L', 'u', 'k', 'e', Key::ENTER, // name
Key::DOWN, Key::ENTER, // JS
Key::ENTER,
]);

$responses = form()
->text('What is your name?')
->select('What is your language?', ['PHP', 'JS'])
->add(fn ($responses) => text("Which version?"), condition: fn ($responses) => $responses[1] === 'PHP')
->confirm('Are you sure?')
->submit();

expect($responses)->toBe([
'Luke',
'JS',
null,
true,
]);
});

0 comments on commit 65d6808

Please sign in to comment.