mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-10 23:03:16 +01:00
Add additional tests for filament
This commit is contained in:
committed by
Constantin Graf
parent
0551c633a3
commit
08f9edbc96
52
tests/Unit/Filament/Widgets/ChartWidgetTestCase.php
Normal file
52
tests/Unit/Filament/Widgets/ChartWidgetTestCase.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Filament\Widgets;
|
||||
|
||||
use App\Models\User;
|
||||
use Closure;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Livewire\Features\SupportTesting\Testable;
|
||||
use Tests\Unit\Filament\FilamentTestCase;
|
||||
|
||||
abstract class ChartWidgetTestCase extends FilamentTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Config::set('auth.super_admins', ['admin@example.com']);
|
||||
$user = User::factory()->withPersonalOrganization()->create([
|
||||
'email' => 'admin@example.com',
|
||||
]);
|
||||
|
||||
$this->actingAs($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the protected getData() method of the chart widget of the given Livewire test.
|
||||
*
|
||||
* @param Testable<ChartWidget> $testable
|
||||
* @return array{datasets: array<int, array{label: string, data: Collection<int, int>}>, labels: Collection<int, string>}
|
||||
*/
|
||||
protected function getChartData(Testable $testable): array
|
||||
{
|
||||
/** @var ChartWidget $widget */
|
||||
$widget = $testable->instance();
|
||||
|
||||
/** @var array{datasets: array<int, array{label: string, data: Collection<int, int>}>, labels: Collection<int, string>} $data */
|
||||
$data = Closure::bind(fn (): array => $this->getData(), $widget, $widget)();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{datasets: array<int, array{label: string, data: Collection<int, int>}>, labels: Collection<int, string>} $data
|
||||
*/
|
||||
protected function sumOfChartData(array $data): int
|
||||
{
|
||||
return (int) $data['datasets'][0]['data']->sum();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user