feat: reload the page with a flash when an htmx request fails

This commit is contained in:
fromme committed 2026-09-17 16:48:48 +02:00
1 parent 0be3c2ccde
commit a2e4035889
14 files changed
+205 -210

No files matched your search

@@ -43,8 +43,7 @@ class ResourceAdminControllerTest extends WebTestCase
$this->client->request('GET', '/admin/resources');
self::assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
// Not as htmx: an htmx request gets the error modal instead of the bare status.
$this->client->request('GET', '/admin/resources/new/desk');
$this->client->request('GET', '/admin/resources/new/desk', server: ['HTTP_HX-Request' => 'true']);
self::assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
}
@@ -123,7 +122,7 @@ class ResourceAdminControllerTest extends WebTestCase
{
$this->client->loginUser($this->admin());
$this->client->request('GET', '/admin/resources/new/boat');
$this->client->request('GET', '/admin/resources/new/boat', server: ['HTTP_HX-Request' => 'true']);
self::assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
}
@@ -221,7 +220,7 @@ class ResourceAdminControllerTest extends WebTestCase
$crawler = $this->client->request('GET', '/admin/resources');
self::assertCount(0, $crawler->filter(\sprintf('[hx-get="/admin/resource-groups/%d/delete"]', $room->getId())));
$this->client->request('POST', \sprintf('/admin/resource-groups/%d/delete', $room->getId()), ['_token' => 'whatever']);
$this->client->request('POST', \sprintf('/admin/resource-groups/%d/delete', $room->getId()), ['_token' => 'whatever'], server: ['HTTP_HX-Request' => 'true']);
self::assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
}
+1 -8
View File
@@ -155,12 +155,6 @@ class BookingControllerTest extends WebTestCase
self::assertNull($this->em->getRepository(Booking::class)->findOneBy(['resource' => $desk]));
}
/**
* Note the status is 200, not 403: HtmxExceptionListener deliberately converts every
* exception on an htmx request -- access denied included -- into a visible error modal,
* because htmx discards a 4xx body and the click would otherwise do nothing at all.
* What matters here is that the booking survives.
*/
public function testReleasingAnotherPersonsBookingIsRefused(): void
{
$booking = new Booking($this->user('[email protected]'), $this->resource('D1'), new \DateTimeImmutable('2026-10-01'));
@@ -170,8 +164,7 @@ class BookingControllerTest extends WebTestCase
$this->client->loginUser($this->user('[email protected]'));
$this->client->request('POST', \sprintf('/bookings/%d/release', $booking->getId()), server: ['HTTP_HX-Request' => 'true']);
$response = $this->client->getResponse();
self::assertSame('body', $response->headers->get('HX-Retarget'));
self::assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
self::assertNotNull($this->em->getRepository(Booking::class)->find($booking->getId()));
}