Merge pull request 'Update slide list and edit slide form without page reloads' (#57) from feature/hide-slides into main
CI / Deploy / test (push) Successful in 58s
CI / Deploy / deploy (push) Successful in 6s

Reviewed-on: #57
This commit was merged in pull request #57.
This commit is contained in:
gnilebein committed 2026-11-11 20:29:04 +01:00
commit 0294744281
9 files changed
+403 -32

No files matched your search

@@ -0,0 +1,105 @@
<?php
declare(strict_types=1);
namespace App\Test\TestCase\Controller;
use App\Model\Entity\Slide;
use App\Test\TestCase\PlenarioTestTrait;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
/**
* Dashboard updates without reloading: fragments (header X-Fragment) and the slide form in a dialog.
*/
class AdminFragmentTest extends TestCase
{
use IntegrationTestTrait;
use PlenarioTestTrait;
/**
* @var list<string>
*/
protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses'];
protected function setUp(): void
{
parent::setUp();
$this->enableCsrfToken();
}
public function testFragmentContainsRegionsButNoPageFrame(): void
{
[$poll, $token] = $this->createPoll();
$this->createSlide($poll, Slide::TYPE_CHOICE);
$this->configRequest(['headers' => ['X-Fragment' => '1']]);
$this->get("/admin/$token");
$this->assertResponseOk();
$this->assertResponseContains('data-refresh="slides"');
$this->assertResponseContains('data-refresh="head"');
$this->assertResponseContains('data-refresh="flash"');
$this->assertResponseNotContains('<html');
$this->assertResponseNotContains('site-header');
}
public function testFullPageKeepsFrameAndRegions(): void
{
[$poll, $token] = $this->createPoll();
$this->createSlide($poll, Slide::TYPE_CHOICE);
$this->get("/admin/$token");
$this->assertResponseContains('<html');
$this->assertResponseContains('data-refresh="flash"');
$this->assertResponseContains('<dialog');
}
public function testActionsUseNoInlineHandlers(): void
{
[$poll, $token] = $this->createPoll();
$this->createSlide($poll, Slide::TYPE_CHOICE);
$this->get("/admin/$token");
$this->assertResponseNotContains('onclick=');
$this->assertResponseContains('data-confirm=');
}
public function testSlideFormFragmentIsTheDialogContent(): void
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_OPEN);
$this->configRequest(['headers' => ['X-Fragment' => '1']]);
$this->get("/admin/$token/slides/{$slide->id}/edit");
$this->assertResponseOk();
$this->assertResponseContains('data-modal-content');
$this->assertResponseNotContains('site-header');
}
public function testValidationErrorKeepsTheFormInTheFragment(): void
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_OPEN);
$this->configRequest(['headers' => ['X-Fragment' => '1']]);
$this->post("/admin/$token/slides/{$slide->id}/edit", ['question' => '']);
$this->assertResponseOk();
$this->assertResponseContains('data-modal-content');
$this->assertResponseContains('Bitte prüfe deine Eingaben.');
}
public function testSuccessfulSaveRedirectsToTheDashboard(): void
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_OPEN);
$this->configRequest(['headers' => ['X-Fragment' => '1']]);
$this->post("/admin/$token/slides/{$slide->id}/edit", ['question' => 'Neue Frage']);
$this->assertRedirect(['_name' => 'admin', 'token' => $token]);
}
}