generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19e2630
commit 552ada5
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
use Carbon\CarbonPeriod; | ||
use Illuminate\Support\Carbon; | ||
use Spatie\FilamentSimpleStat\SimpleStat; | ||
use Spatie\FilamentSimpleStat\Tests\Support\ExampleEvent; | ||
|
||
beforeEach(function () { | ||
Carbon::setTestNow(Carbon::parse('2024-02-22')); | ||
|
||
$period = CarbonPeriod::create('2024-03-20', '2024-03-25'); | ||
|
||
foreach ($period as $date) { | ||
ExampleEvent::factory()->count(rand(0, 2))->create(['created_at' => $date]); | ||
} | ||
}); | ||
|
||
it('constructs a description based on the interval', function () { | ||
$simpleStat = SimpleStat::make(ExampleEvent::class)->last7Days()->dailyAverage(); | ||
expect($simpleStat->getDescription())->toBe('Last 7 days'); | ||
|
||
$simpleStat = SimpleStat::make(ExampleEvent::class)->last30Days()->dailyAverage(); | ||
expect($simpleStat->getDescription())->toBe('Last 30 days'); | ||
|
||
$simpleStat = SimpleStat::make(ExampleEvent::class)->lastDays(14)->dailyAverage(); | ||
expect($simpleStat->getDescription())->toBe('Last 14 days'); | ||
}); |