|
2 | 2 |
|
3 | 3 | namespace Hyde\Framework\Testing\Feature\Commands;
|
4 | 4 |
|
| 5 | +use Hyde\Framework\Commands\HydeBuildSearchCommand; |
5 | 6 | use Hyde\Framework\Hyde;
|
6 | 7 | use Hyde\Testing\TestCase;
|
7 | 8 |
|
|
10 | 11 | */
|
11 | 12 | class HydeBuildSearchCommandTest extends TestCase
|
12 | 13 | {
|
13 |
| - public function test_it_creates_the_search_json_file() |
| 14 | + protected function setUp(): void |
| 15 | + { |
| 16 | + parent::setUp(); |
| 17 | + unlinkIfExists(Hyde::path('_site/docs/search.json')); |
| 18 | + unlinkIfExists(Hyde::path('_site/docs/search.html')); |
| 19 | + } |
| 20 | + |
| 21 | + protected function tearDown(): void |
14 | 22 | {
|
| 23 | + unlinkIfExists(Hyde::path('_site/docs/search.html')); |
15 | 24 | unlinkIfExists(Hyde::path('_site/docs/search.json'));
|
| 25 | + HydeBuildSearchCommand::$guesstimationFactor = 52.5; |
| 26 | + parent::tearDown(); |
| 27 | + } |
| 28 | + |
| 29 | + public function test_it_creates_the_search_json_file() |
| 30 | + { |
16 | 31 | $this->artisan('build:search')
|
17 | 32 | ->expectsOutput('Generating documentation site search index...')
|
18 | 33 | ->assertExitCode(0);
|
19 | 34 |
|
20 | 35 | $this->assertFileExists(Hyde::path('_site/docs/search.json'));
|
21 |
| - unlink(Hyde::path('_site/docs/search.json')); |
| 36 | + } |
| 37 | + |
| 38 | + public function test_it_creates_the_search_page() |
| 39 | + { |
| 40 | + $this->artisan('build:search') |
| 41 | + ->expectsOutput('Generating documentation site search index...') |
| 42 | + ->assertExitCode(0); |
| 43 | + |
| 44 | + $this->assertFileExists(Hyde::path('_site/docs/search.html')); |
| 45 | + } |
| 46 | + |
| 47 | + public function test_it_does_not_create_the_search_page_if_disabled() |
| 48 | + { |
| 49 | + config(['docs.create_search_page' => false]); |
| 50 | + $this->artisan('build:search') |
| 51 | + ->expectsOutput('Generating documentation site search index...') |
| 52 | + ->assertExitCode(0); |
| 53 | + |
| 54 | + $this->assertFileDoesNotExist(Hyde::path('_site/docs/search.html')); |
| 55 | + } |
| 56 | + |
| 57 | + public function test_it_does_not_display_the_estimation_message_when_it_is_less_than_1_second() |
| 58 | + { |
| 59 | + HydeBuildSearchCommand::$guesstimationFactor = 0; |
| 60 | + |
| 61 | + $this->artisan('build:search') |
| 62 | + ->expectsOutput('Generating documentation site search index...') |
| 63 | + ->doesntExpectOutputToContain('> This will take an estimated') |
| 64 | + ->assertExitCode(0); |
| 65 | + } |
| 66 | + |
| 67 | + public function test_it_displays_the_estimation_message_when_it_is_greater_than_1_second() |
| 68 | + { |
| 69 | + HydeBuildSearchCommand::$guesstimationFactor = 1000; |
| 70 | + touch(Hyde::path('_docs/foo.md')); |
| 71 | + $this->artisan('build:search') |
| 72 | + ->expectsOutput('Generating documentation site search index...') |
| 73 | + ->expectsOutputToContain('> This will take an estimated') |
| 74 | + ->assertExitCode(0); |
| 75 | + unlink(Hyde::path('_docs/foo.md')); |
22 | 76 | }
|
23 | 77 | }
|
0 commit comments