|
5 | 5 | use Code16\Sharp\EntityList\Commands\InstanceCommand; |
6 | 6 | use Code16\Sharp\EntityList\Commands\Wizards\EntityWizardCommand; |
7 | 7 | use Code16\Sharp\Filters\CheckFilter; |
| 8 | +use Code16\Sharp\Filters\DateRange\DateRangeFilterValue; |
| 9 | +use Code16\Sharp\Filters\DateRangeFilter; |
8 | 10 | use Code16\Sharp\Form\Fields\SharpFormEditorField; |
9 | 11 | use Code16\Sharp\Form\Fields\SharpFormTextField; |
10 | 12 | use Code16\Sharp\Show\Fields\SharpShowDashboardField; |
@@ -622,17 +624,45 @@ public function update($id, array $data) |
622 | 624 | }); |
623 | 625 |
|
624 | 626 | test('get dashboard', function () { |
625 | | - fakeDashboardFor(DashboardEntity::class, new class() extends TestDashboard |
| 627 | + /** @var array{'period':DateRangeFilterValue} $filterValues */ |
| 628 | + $filterValues = []; |
| 629 | + |
| 630 | + fakeDashboardFor(DashboardEntity::class, new class($filterValues) extends TestDashboard |
626 | 631 | { |
| 632 | + public function __construct(public &$filterValues) {} |
| 633 | + |
| 634 | + public function getFilters(): ?array |
| 635 | + { |
| 636 | + return [ |
| 637 | + new class() extends DateRangeFilter |
| 638 | + { |
| 639 | + public function label(): string |
| 640 | + { |
| 641 | + return 'Period'; |
| 642 | + } |
| 643 | + |
| 644 | + public function buildFilterConfig(): void |
| 645 | + { |
| 646 | + $this->configureKey('period'); |
| 647 | + } |
| 648 | + }, |
| 649 | + ]; |
| 650 | + } |
| 651 | + |
627 | 652 | protected function buildWidgetsData(): void |
628 | 653 | { |
| 654 | + $this->filterValues = ['period' => $this->queryParams->filterFor('period')]; |
629 | 655 | $this->setPanelData('panel', ['name' => 'Marie Curie']); |
630 | 656 | } |
631 | 657 | }); |
632 | 658 |
|
633 | 659 | $this->sharpDashboard(DashboardEntity::class) |
| 660 | + ->withFilter('period', ['start' => '2021-01-01', 'end' => '2021-01-31']) |
634 | 661 | ->get() |
635 | 662 | ->assertOk(); |
| 663 | + |
| 664 | + expect($filterValues['period']->getStart()->format('Y-m-d'))->toEqual('2021-01-01') |
| 665 | + ->and($filterValues['period']->getEnd()->format('Y-m-d'))->toEqual('2021-01-31'); |
636 | 666 | }); |
637 | 667 |
|
638 | 668 | test('get show dashboard field', function () { |
|
0 commit comments