feat: paginate the admin booking list

This commit is contained in:
fromme committed 2026-09-18 10:53:55 +02:00
1 parent ba64033948
commit 2f5d1d14e4
16 files changed
+504 -75

No files matched your search

@@ -125,7 +125,7 @@ class BookingAdminControllerTest extends WebTestCase
$crawler = $this->client->request('GET', '/admin/bookings?user='.$bea->getId());
self::assertResponseIsSuccessful();
$text = $crawler->filter('ul')->text();
$text = $crawler->filter('tbody')->text();
self::assertStringContainsString('Bea Berger', $text);
self::assertStringNotContainsString('Carl Conrad', $text);
}
@@ -139,7 +139,7 @@ class BookingAdminControllerTest extends WebTestCase
$crawler = $this->client->request('GET', '/admin/bookings?type=parking');
self::assertResponseIsSuccessful();
$text = $crawler->filter('ul')->text();
$text = $crawler->filter('tbody')->text();
self::assertStringContainsString('Carl Conrad', $text);
self::assertStringNotContainsString('Bea Berger', $text);
}
@@ -236,6 +236,50 @@ class BookingAdminControllerTest extends WebTestCase
);
}
/**
* The list is paginated, so the window no longer decides how much gets rendered. Page two is
* the part of the assertion that matters: the first page could be right by accident if the
* limit were applied without an offset.
*/
public function testTheListIsPaginated(): void
{
$user = $this->user('[email protected]', 'Bea Berger');
$desk = $this->resource('D1');
for ($day = 0; $day < 30; ++$day) {
$this->booking($user, $desk, new \DateTimeImmutable('today +'.$day.' days'));
}
$this->client->loginUser($this->admin());
$crawler = $this->client->request('GET', '/admin/bookings');
self::assertResponseIsSuccessful();
self::assertCount(25, $crawler->filter('tbody tr'));
$crawler = $this->client->request('GET', '/admin/bookings?page=2');
self::assertResponseIsSuccessful();
self::assertCount(5, $crawler->filter('tbody tr'));
}
/**
* Sorting has to survive next to the filter: both live in the query string, and a sort link
* that dropped the filter would silently widen what is being paged through.
*/
public function testAColumnHeaderSortsWithoutLosingTheFilter(): void
{
$bea = $this->user('[email protected]', 'Bea Berger');
$this->booking($bea, $this->resource('D1'));
$this->booking($this->user('[email protected]', 'Carl Conrad'), $this->resource('D2'));
$this->client->loginUser($this->admin());
$crawler = $this->client->request('GET', '/admin/bookings?user='.$bea->getId().'&sort=u.name&direction=desc');
self::assertResponseIsSuccessful();
$text = $crawler->filter('tbody')->text();
self::assertStringContainsString('Bea Berger', $text);
self::assertStringNotContainsString('Carl Conrad', $text);
}
private function confirmationToken(string $uri): string
{
$crawler = $this->client->request('GET', $uri, server: ['HTTP_HX-Request' => 'true']);
@@ -246,9 +290,9 @@ class BookingAdminControllerTest extends WebTestCase
return json_decode((string) $vals, true, flags: \JSON_THROW_ON_ERROR)['_token'];
}
private function booking(User $user, Resource $resource): Booking
private function booking(User $user, Resource $resource, ?\DateTimeImmutable $date = null): Booking
{
$booking = new Booking($user, $resource, new \DateTimeImmutable('today'));
$booking = new Booking($user, $resource, $date ?? new \DateTimeImmutable('today'));
$this->em->persist($booking);
$this->em->flush();