-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ebd4b9
commit 5fa5efc
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Collection; | ||
use Laravel\Prompts\Prompt; | ||
use Laravel\Prompts\Themes\Default\Concerns\DrawsTabs; | ||
use Laravel\Prompts\Themes\Default\Renderer; | ||
|
||
class TestPrompt extends Prompt | ||
{ | ||
public function __construct( | ||
public Collection $tabs, | ||
public int $selected = 0, | ||
public int $width = 60, | ||
) { | ||
static::$themes['default'][static::class] = TestRenderer::class; | ||
} | ||
|
||
public function value(): mixed | ||
{ | ||
return null; | ||
} | ||
|
||
public function display(): void | ||
{ | ||
static::output()->write($this->renderTheme()); | ||
} | ||
} | ||
|
||
class TestRenderer extends Renderer | ||
{ | ||
use DrawsTabs; | ||
|
||
public function __invoke(TestPrompt $prompt) | ||
{ | ||
return $this->tabs($prompt->tabs, $prompt->selected, $prompt->width); | ||
} | ||
} | ||
|
||
/** | ||
* Note: Trailing whitespace is intentional in order to match the output. | ||
* Removing it will cause the test to fail (correctly) while allowing | ||
* the output to appear indistinguishable from the expected output. | ||
*/ | ||
|
||
it('renders tabs', function () { | ||
Prompt::fake(); | ||
|
||
$tabs = collect(['One', 'Two', 'Three', 'Four', 'Five', 'Six']); | ||
|
||
(new TestPrompt($tabs))->display(); | ||
|
||
Prompt::assertStrippedOutputContains(<<<'OUTPUT' | ||
╭─────╮ | ||
│ One │ Two Three Four Five Six | ||
┴─────┴───────────────────────────────────────────────────── | ||
OUTPUT); | ||
}); | ||
|
||
it('highlights tabs', function () { | ||
Prompt::fake(); | ||
|
||
$tabs = collect(['One', 'Two', 'Three', 'Four', 'Five', 'Six']); | ||
|
||
(new TestPrompt($tabs, 2))->display(); | ||
|
||
Prompt::assertStrippedOutputContains(<<<'OUTPUT' | ||
╭───────╮ | ||
One Two │ Three │ Four Five Six | ||
──────────────┴───────┴───────────────────────────────────── | ||
OUTPUT); | ||
}); | ||
|
||
it('truncates tabs', function () { | ||
Prompt::fake(); | ||
|
||
$tabs = collect(['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight']); | ||
|
||
(new TestPrompt($tabs))->display(); | ||
|
||
Prompt::assertStrippedOutputContains(<<<'OUTPUT' | ||
╭─────╮ | ||
│ One │ Two Three Four Five Six Seven Eig | ||
┴─────┴───────────────────────────────────────────────────── | ||
OUTPUT); | ||
}); | ||
|
||
it('scrolls tabs', function () { | ||
Prompt::fake(); | ||
|
||
$tabs = collect(['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight']); | ||
|
||
(new TestPrompt($tabs, 7))->display(); | ||
|
||
Prompt::assertStrippedOutputContains(<<<'OUTPUT' | ||
╭───────╮ | ||
e Two Three Four Five Six Seven │ Eight │ | ||
───────────────────────────────────────────────────┴───────┴ | ||
OUTPUT); | ||
}); |