feat: admin list filtering and search
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Form\Model\Filter;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Enum\Groups\AccommodationBookingType;
|
||||
use App\Form\Model\Filter\AccommodationBookingFilterDto;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AccommodationBookingFilterDtoTest extends TestCase
|
||||
{
|
||||
public function testGroupAdminsStartOnStillLiveBookingsThatAreNotOverYet(): void
|
||||
{
|
||||
$filter = AccommodationBookingFilterDto::defaults(true, new User('[email protected]'));
|
||||
|
||||
self::assertSame(
|
||||
[AccommodationBookingStatus::Draft, AccommodationBookingStatus::Open],
|
||||
$filter->status,
|
||||
'accepted and discarded bookings need no further work, so they stay out of the way',
|
||||
);
|
||||
self::assertSame((new \DateTimeImmutable('today'))->format('Y-m-d'), $filter->dateFrom?->format('Y-m-d'));
|
||||
self::assertNull($filter->managedBy, 'a group admin sees everybody’s bookings');
|
||||
self::assertFalse($filter->managedByLocked);
|
||||
}
|
||||
|
||||
public function testEverybodyElseStartsPinnedToTheirOwnBookings(): void
|
||||
{
|
||||
$user = new User('[email protected]');
|
||||
|
||||
$filter = AccommodationBookingFilterDto::defaults(false, $user);
|
||||
|
||||
self::assertSame($user, $filter->managedBy);
|
||||
self::assertTrue($filter->managedByLocked);
|
||||
}
|
||||
|
||||
public function testThePinnedManagerChipCannotBeDismissed(): void
|
||||
{
|
||||
$filter = AccommodationBookingFilterDto::defaults(false, new User('[email protected]'));
|
||||
|
||||
$chip = $this->chipFor($filter, 'Betreuer:in');
|
||||
self::assertNotNull($chip);
|
||||
self::assertFalse($chip->isRemovable());
|
||||
}
|
||||
|
||||
public function testAChosenManagerChipCanBeDismissed(): void
|
||||
{
|
||||
$filter = new AccommodationBookingFilterDto();
|
||||
$filter->managedBy = new User('[email protected]');
|
||||
|
||||
$chip = $this->chipFor($filter, 'Betreuer:in');
|
||||
self::assertNotNull($chip);
|
||||
self::assertTrue($chip->isRemovable());
|
||||
self::assertSame(['managedBy'], $chip->removeKeys);
|
||||
}
|
||||
|
||||
public function testTheUnassignedFilterReplacesTheManagerChip(): void
|
||||
{
|
||||
$filter = new AccommodationBookingFilterDto();
|
||||
$filter->managedBy = new User('[email protected]');
|
||||
$filter->unassigned = true;
|
||||
|
||||
$chip = $this->chipFor($filter, 'Betreuer:in');
|
||||
self::assertNotNull($chip);
|
||||
self::assertSame('keine Zuordnung', $chip->value);
|
||||
self::assertSame(['unassigned'], $chip->removeKeys);
|
||||
}
|
||||
|
||||
public function testAWhitespaceOnlySearchIsNotAFilter(): void
|
||||
{
|
||||
$filter = new AccommodationBookingFilterDto();
|
||||
$filter->q = ' ';
|
||||
|
||||
self::assertNull($filter->searchTerm());
|
||||
self::assertFalse($filter->isActive());
|
||||
}
|
||||
|
||||
public function testEveryActiveFilterIsAccountedForAsAChip(): void
|
||||
{
|
||||
$filter = new AccommodationBookingFilterDto();
|
||||
$filter->q = 'meier';
|
||||
$filter->dateFrom = new \DateTimeImmutable('2026-08-01');
|
||||
$filter->status = [AccommodationBookingStatus::Open, AccommodationBookingStatus::Accepted];
|
||||
$filter->type = [AccommodationBookingType::Booking];
|
||||
|
||||
self::assertSame(4, $filter->activeCount());
|
||||
self::assertSame('Offen, Bestätigt', $this->chipFor($filter, 'Status')?->value);
|
||||
self::assertSame('Buchung', $this->chipFor($filter, 'Art')?->value);
|
||||
self::assertSame('01.08.2026', $this->chipFor($filter, 'Aufenthalt ab')?->value);
|
||||
}
|
||||
|
||||
public function testAnUntouchedFilterHasNothingToShow(): void
|
||||
{
|
||||
$filter = new AccommodationBookingFilterDto();
|
||||
|
||||
self::assertSame([], $filter->activeFilters());
|
||||
self::assertFalse($filter->isActive());
|
||||
}
|
||||
|
||||
private function chipFor(AccommodationBookingFilterDto $filter, string $label): ?\App\Model\ListFilterChip
|
||||
{
|
||||
foreach ($filter->activeFilters() as $chip) {
|
||||
if ($label === $chip->label) {
|
||||
return $chip;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user