adrema/tests/Feature/DashboardTest.php

63 lines
1.6 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');
}
2024-07-31 22:41:02 +02:00
public function testItDisplaysUserAvatar(): void
{
$this->withoutExceptionHandling();
$this->login()->loginNami();
auth()->user()->update(['firstname' => 'Bob', 'lastname' => 'Dylan', 'email' => 'max@email.com']);
$this->get('/')
->assertInertiaPath('auth.user.firstname', 'Bob')
->assertInertiaPath('auth.user.avatar_url', 'https://www.gravatar.com/avatar/' . hash('sha256', 'max@email.com'))
->assertInertiaPath('auth.user.lastname', 'Dylan');
}
2022-11-17 02:15:29 +01:00
}
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
}
}