Skip to content

Commit

Permalink
Flesh out test coverage for new skip_option: false functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseleite committed Nov 2, 2024
1 parent e8ffb6b commit 92139cf
Showing 1 changed file with 116 additions and 2 deletions.
118 changes: 116 additions & 2 deletions tests/StarterKits/InstallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,120 @@ public function it_installs_only_the_modules_confirmed_interactively_via_prompt(
}

#[Test]
public function it_display_custom_module_prompts()
public function it_allows_user_to_skip_in_select_module_prompts()
{
$this->setConfig([
'modules' => [
'js' => [
'prompt' => 'Want one of these fancy JS options?',
'options' => [
'react' => [
'label' => 'React JS',
'export_paths' => [
'resources/js/react.js',
],
],
'vue' => [
'label' => 'Vue JS',
'export_paths' => [
'resources/js/vue.js',
],
],
'svelte' => [
'export_paths' => [
'resources/js/svelte.js',
],
],
],
],
],
]);

$this->assertFileDoesNotExist(base_path('resources/js/react.js'));
$this->assertFileDoesNotExist(base_path('resources/js/vue.js'));
$this->assertFileDoesNotExist(base_path('resources/js/svelte.js'));

$command = $this->installCoolRunningsModules();

// Some fixes to `expectsChoice()` were merged for us, but are not available on 11.20.0 and below
// See: https://github.com/laravel/framework/pull/52408
if (version_compare(app()->version(), '11.20.0', '>')) {
$command->expectsChoice('Want one of these fancy JS options?', 'skip_module', [
'skip_module' => 'No',
'react' => 'React JS',
'vue' => 'Vue JS',
'svelte' => 'Svelte',
]);
} else {
$command->expectsQuestion('Want one of these fancy JS options?', 'skip_module');
}

$command->run();

$this->assertFileDoesNotExist(base_path('resources/js/react.js'));
$this->assertFileDoesNotExist(base_path('resources/js/vue.js'));
$this->assertFileDoesNotExist(base_path('resources/js/svelte.js'));
}

#[Test]
public function it_can_disable_skip_option_in_select_module_prompts()
{
$this->setConfig([
'modules' => [
'js' => [
'prompt' => 'Want one of these fancy JS options?',
'skip_option' => false,
'options' => [
'react' => [
'label' => 'React JS',
'export_paths' => [
'resources/js/react.js',
],
],
'vue' => [
'label' => 'Vue JS',
'export_paths' => [
'resources/js/vue.js',
],
],
'svelte' => [
'export_paths' => [
'resources/js/svelte.js',
],
],
],
],
],
]);

$this->assertFileDoesNotExist(base_path('resources/js/react.js'));
$this->assertFileDoesNotExist(base_path('resources/js/vue.js'));
$this->assertFileDoesNotExist(base_path('resources/js/svelte.js'));

$command = $this->installCoolRunningsModules();

// Some fixes to `expectsChoice()` were merged for us, but are not available on 11.20.0 and below
// See: https://github.com/laravel/framework/pull/52408
if (version_compare(app()->version(), '11.20.0', '>')) {
$command->expectsChoice('Want one of these fancy JS options?', 'svelte', [
// 'skip_module' => 'No', // This should not be here anymore, because of `skip_option: false`
'react' => 'React JS',
'vue' => 'Vue JS',
'svelte' => 'Svelte',
]);
} else {
$command->expectsQuestion('Want one of these fancy JS options?', 'svelte');
}

$command->run();

$this->assertFileDoesNotExist(base_path('resources/js/react.js'));
$this->assertFileDoesNotExist(base_path('resources/js/vue.js'));
$this->assertFileExists(base_path('resources/js/svelte.js'));
}

#[Test]
public function it_display_custom_module_prompts_and_option_labels()
{
$this->setConfig([
'modules' => [
Expand All @@ -971,6 +1084,7 @@ public function it_display_custom_module_prompts()
],
'js' => [
'prompt' => 'Want one of these fancy JS options?',
'skip_option' => 'No, thank you!',
'options' => [
'react' => [
'label' => 'React JS',
Expand Down Expand Up @@ -1007,7 +1121,7 @@ public function it_display_custom_module_prompts()
// See: https://github.com/laravel/framework/pull/52408
if (version_compare(app()->version(), '11.20.0', '>')) {
$command->expectsChoice('Want one of these fancy JS options?', 'svelte', [
'skip_module' => 'No',
'skip_module' => 'No, thank you!',
'react' => 'React JS',
'vue' => 'Vue JS',
'svelte' => 'Svelte',
Expand Down

0 comments on commit 92139cf

Please sign in to comment.