Skip to content

Commit 7227768

Browse files
committed
update test + improve doc
1 parent d2febe0 commit 7227768

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

docs/guide/testing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ You can use `withFilter()` to apply filters to the list before calling `get()` o
6767

6868
```php
6969
$this->sharpList(Post::class)
70-
->withFilter('category', 1)
70+
->withFilter(CategoryFilter::class, 1)
7171
->get()
7272
->assertOk();
7373
```
@@ -210,7 +210,7 @@ $this->sharpDashboard(MyDashboard::class)
210210

211211
```php
212212
$this->sharpDashboard(MyDashboard::class)
213-
->withFilter('period', '2023')
213+
->withFilter(PeriodFilter::class, ['start' => '2023-01-01', 'end' => '2023-01-31'])
214214
->get()
215215
->assertOk();
216216
```

tests/Http/SharpAssertionsHttpTest.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Code16\Sharp\EntityList\Commands\InstanceCommand;
66
use Code16\Sharp\EntityList\Commands\Wizards\EntityWizardCommand;
77
use Code16\Sharp\Filters\CheckFilter;
8+
use Code16\Sharp\Filters\DateRange\DateRangeFilterValue;
9+
use Code16\Sharp\Filters\DateRangeFilter;
810
use Code16\Sharp\Form\Fields\SharpFormEditorField;
911
use Code16\Sharp\Form\Fields\SharpFormTextField;
1012
use Code16\Sharp\Show\Fields\SharpShowDashboardField;
@@ -622,17 +624,45 @@ public function update($id, array $data)
622624
});
623625

624626
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
626631
{
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+
627652
protected function buildWidgetsData(): void
628653
{
654+
$this->filterValues = ['period' => $this->queryParams->filterFor('period')];
629655
$this->setPanelData('panel', ['name' => 'Marie Curie']);
630656
}
631657
});
632658

633659
$this->sharpDashboard(DashboardEntity::class)
660+
->withFilter('period', ['start' => '2021-01-01', 'end' => '2021-01-31'])
634661
->get()
635662
->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');
636666
});
637667

638668
test('get show dashboard field', function () {

0 commit comments

Comments
 (0)