mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-12-06 17:52:16 +00:00
Fix missing months in yearly admin charts at the end of a month
This commit is contained in:
committed by
Constantin Graf
parent
93eb93f1dc
commit
264ae3030c
@@ -25,7 +25,7 @@ class TimeEntriesCreated extends ChartWidget
|
||||
} elseif ($filter === 'month') {
|
||||
$start = now()->subMonth();
|
||||
} elseif ($filter === 'year') {
|
||||
$start = now()->subYear();
|
||||
$start = now()->subYear()->startOfMonth();
|
||||
} else {
|
||||
$start = now()->subWeek();
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class TimeEntriesImported extends ChartWidget
|
||||
} elseif ($filter === 'month') {
|
||||
$start = now()->subMonth();
|
||||
} elseif ($filter === 'year') {
|
||||
$start = now()->subYear();
|
||||
$start = now()->subYear()->startOfMonth();
|
||||
} else {
|
||||
$start = now()->subWeek();
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class UserRegistrations extends ChartWidget
|
||||
} elseif ($filter === 'month') {
|
||||
$start = now()->subMonth();
|
||||
} elseif ($filter === 'year') {
|
||||
$start = now()->subYear();
|
||||
$start = now()->subYear()->startOfMonth();
|
||||
} else {
|
||||
$start = now()->subWeek();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace Tests\Unit\Filament\Widgets;
|
||||
|
||||
use App\Filament\Widgets\TimeEntriesCreated;
|
||||
use App\Models\TimeEntry;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Livewire\Livewire;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
|
||||
@@ -95,6 +96,24 @@ class TimeEntriesCreatedWidgetTest extends ChartWidgetTestCase
|
||||
$this->assertSame(now()->format('Y-m'), $data['labels']->last());
|
||||
}
|
||||
|
||||
public function test_year_filter_contains_every_month_if_today_is_the_end_of_a_month(): void
|
||||
{
|
||||
// Arrange
|
||||
$this->travelTo(Carbon::parse('2026-10-31 12:00:00'));
|
||||
|
||||
// Act
|
||||
$response = Livewire::test(TimeEntriesCreated::class)
|
||||
->set('filter', 'year');
|
||||
|
||||
// Assert
|
||||
$response->assertSuccessful();
|
||||
$data = $this->getChartData($response);
|
||||
$this->assertSame([
|
||||
'2025-10', '2025-11', '2025-12', '2026-01', '2026-02', '2026-03', '2026-04',
|
||||
'2026-05', '2026-06', '2026-07', '2026-08', '2026-09', '2026-10',
|
||||
], $data['labels']->values()->all());
|
||||
}
|
||||
|
||||
public function test_unknown_filter_falls_back_to_last_week(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace Tests\Unit\Filament\Widgets;
|
||||
|
||||
use App\Filament\Widgets\TimeEntriesImported;
|
||||
use App\Models\TimeEntry;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Livewire\Livewire;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
|
||||
@@ -95,6 +96,24 @@ class TimeEntriesImportedWidgetTest extends ChartWidgetTestCase
|
||||
$this->assertSame(now()->format('Y-m'), $data['labels']->last());
|
||||
}
|
||||
|
||||
public function test_year_filter_contains_every_month_if_today_is_the_end_of_a_month(): void
|
||||
{
|
||||
// Arrange
|
||||
$this->travelTo(Carbon::parse('2026-10-31 12:00:00'));
|
||||
|
||||
// Act
|
||||
$response = Livewire::test(TimeEntriesImported::class)
|
||||
->set('filter', 'year');
|
||||
|
||||
// Assert
|
||||
$response->assertSuccessful();
|
||||
$data = $this->getChartData($response);
|
||||
$this->assertSame([
|
||||
'2025-10', '2025-11', '2025-12', '2026-01', '2026-02', '2026-03', '2026-04',
|
||||
'2026-05', '2026-06', '2026-07', '2026-08', '2026-09', '2026-10',
|
||||
], $data['labels']->values()->all());
|
||||
}
|
||||
|
||||
public function test_unknown_filter_falls_back_to_last_week(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace Tests\Unit\Filament\Widgets;
|
||||
|
||||
use App\Filament\Widgets\UserRegistrations;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Livewire\Livewire;
|
||||
use PHPUnit\Framework\Attributes\UsesClass;
|
||||
|
||||
@@ -96,6 +97,24 @@ class UserRegistrationsWidgetTest extends ChartWidgetTestCase
|
||||
$this->assertSame(now()->format('Y-m'), $data['labels']->last());
|
||||
}
|
||||
|
||||
public function test_year_filter_contains_every_month_if_today_is_the_end_of_a_month(): void
|
||||
{
|
||||
// Arrange
|
||||
$this->travelTo(Carbon::parse('2026-10-31 12:00:00'));
|
||||
|
||||
// Act
|
||||
$response = Livewire::test(UserRegistrations::class)
|
||||
->set('filter', 'year');
|
||||
|
||||
// Assert
|
||||
$response->assertSuccessful();
|
||||
$data = $this->getChartData($response);
|
||||
$this->assertSame([
|
||||
'2025-10', '2025-11', '2025-12', '2026-01', '2026-02', '2026-03', '2026-04',
|
||||
'2026-05', '2026-06', '2026-07', '2026-08', '2026-09', '2026-10',
|
||||
], $data['labels']->values()->all());
|
||||
}
|
||||
|
||||
public function test_unknown_filter_falls_back_to_last_week(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
Reference in New Issue
Block a user