adrema/tests/Feature/DashboardTest.php

50 lines
1.1 KiB
PHP
Raw Normal View History

2022-11-16 22:04:37 +01:00
<?php
namespace Tests\Feature;
2023-04-29 21:30:41 +02:00
use App\Dashboard\Blocks\Block;
use App\Dashboard\DashboardFactory;
2022-11-16 22:04:37 +01:00
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
2023-04-29 21:30:41 +02:00
class DashboardTest extends TestCase
2022-11-16 22:04:37 +01:00
{
use DatabaseTransactions;
2022-11-17 02:15:29 +01:00
public function testItDisplaysBlock(): void
2022-11-16 22:04:37 +01:00
{
$this->withoutExceptionHandling();
2022-11-17 02:15:29 +01:00
app(DashboardFactory::class)->purge();
app(DashboardFactory::class)->register(ExampleBlock::class);
2022-11-16 22:04:37 +01:00
$this->login()->loginNami();
$response = $this->get('/');
2022-11-17 02:15:29 +01:00
$this->assertInertiaHas(['class' => 'name'], $response, 'blocks.0.data');
$this->assertInertiaHas('Example', $response, 'blocks.0.title');
$this->assertInertiaHas('exa', $response, 'blocks.0.component');
}
}
class ExampleBlock extends Block
{
public function title(): string
{
return 'Example';
}
/**
* @return array<string, string>
*/
public function data(): array
{
return ['class' => 'name'];
}
public function component(): string
{
return 'exa';
2022-11-16 22:04:37 +01:00
}
}