From 92139cf7ccf7495f1dc8e6ec0a2b60da3a7aea2e Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Sat, 2 Nov 2024 19:58:59 -0400 Subject: [PATCH] Flesh out test coverage for new `skip_option: false` functionality. --- tests/StarterKits/InstallTest.php | 118 +++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 2 deletions(-) diff --git a/tests/StarterKits/InstallTest.php b/tests/StarterKits/InstallTest.php index 078bb6a96a..b13a9eac88 100644 --- a/tests/StarterKits/InstallTest.php +++ b/tests/StarterKits/InstallTest.php @@ -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' => [ @@ -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', @@ -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',