added button component
This commit is contained in:
43
tests/Feature/Component/ButtonTest.php
Normal file
43
tests/Feature/Component/ButtonTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Component;
|
||||
|
||||
use Tests\Feature\Component\DataProvider\ButtonTestDataProvider;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ButtonTest extends TestCase
|
||||
{
|
||||
public function testGeneratesButtonElement(): void
|
||||
{
|
||||
$view = $this->blade('<x-button>Click!</x-button>');
|
||||
|
||||
$view->assertSeeHtml('<button ');
|
||||
$view->assertDontSeeHtml('<a ');
|
||||
}
|
||||
|
||||
public function testButtonCanHaveAttributes(): void
|
||||
{
|
||||
$view = $this->blade('<x-button data-attr="123">Click!</x-button>');
|
||||
|
||||
$view->assertSeeHtml('data-attr="123"');
|
||||
}
|
||||
|
||||
public function testDefaultVariantIsPrimary(): void
|
||||
{
|
||||
$view = $this->blade('<x-button>Click!</x-button>');
|
||||
|
||||
$view->assertSeeHtml('bg-primary text-text-inverted');
|
||||
}
|
||||
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\DataProviderExternal(ButtonTestDataProvider::class, 'getDataForButtonTestWithButtons')]
|
||||
public function testVariants(string $variant, string $expectedHtml): void
|
||||
{
|
||||
$button = sprintf('<x-button variant="%s">Click!</x-button>', $variant);
|
||||
$view = $this->blade($button);
|
||||
|
||||
$view->assertSeeHtml($expectedHtml);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Component\DataProvider;
|
||||
|
||||
use App\View\Components\Button;
|
||||
|
||||
class ButtonTestDataProvider
|
||||
{
|
||||
public static function getDataForButtonTestWithButtons(): array
|
||||
{
|
||||
return [
|
||||
'primary variant' => [
|
||||
'variant' => Button::VARIANT_PRIMARY,
|
||||
'expectedHtml' => 'bg-primary text-text-inverted'
|
||||
],
|
||||
'secondary variant' => [
|
||||
'variant' => Button::VARIANT_SECONDARY,
|
||||
'expectedHtml' => 'bg-secondary text-text'
|
||||
],
|
||||
'outline variant' => [
|
||||
'variant' => Button::VARIANT_OUTLINE,
|
||||
'expectedHtml' => 'bg-surface border border-primary text-primary'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user