Merge pull request 'Add a speaker view with a next-slide preview and keep the live slide in view' (#93) from feature/presenter-notes into main
CI / Deploy / PHP 8.4 (push) Successful in 1m12s
CI / Deploy / PHP 8.5 (push) Successful in 1m13s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Successful in 7s

Reviewed-on: #93
This commit was merged in pull request #93.
This commit is contained in:
gnilebein committed 2026-11-16 15:45:15 +01:00
commit 0c97f61763
11 files changed
+264 -5

No files matched your search

@@ -0,0 +1,107 @@
<?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;
/**
* Speaker view (second window): preview of the next slide, no side effects, no solutions in the JSON.
*/
class SpeakerViewTest 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();
}
/**
* @return array<string, mixed>
*/
protected function state(string $token): array
{
$this->get("/admin/$token/state");
$this->assertResponseOk();
return json_decode((string)$this->_response->getBody(), true);
}
public function testSpeakerPageDoesNotStartThePresentation(): void
{
[$poll, $token] = $this->createPoll();
$this->createSlide($poll, Slide::TYPE_CHOICE);
for ($i = 0; $i < 2; $i++) {
$this->get("/admin/$token/speaker");
$this->assertResponseOk();
$this->assertResponseContains('data-next');
$this->assertNull($this->pollsTable()->get($poll->id)->current_slide_id);
}
$this->get("/admin/$token/present");
$this->assertResponseNotContains('data-next-question');
}
public function testSpeakerPageNeedsTheToken(): void
{
$this->get('/admin/' . str_repeat('x', 30) . '/speaker');
$this->assertResponseCode(404);
}
public function testNextIsTheSlideBehindTheLiveOne(): void
{
[$poll, $token] = $this->createPoll();
$first = $this->createSlide($poll, Slide::TYPE_CHOICE);
$second = $this->createSlide($poll, Slide::TYPE_CHOICE, ['question' => 'Zweite?']);
$hidden = $this->createSlide($poll, Slide::TYPE_CONTENT);
$hidden->is_hidden = true;
$this->slidesTable()->saveOrFail($hidden);
$this->createSlide($poll, Slide::TYPE_WORDCLOUD, ['question' => 'Letzte?']);
$this->assertSame($first->id, $this->state($token)['next']['id'], 'before the start: the first slide');
$this->goLive($poll, $first);
$next = $this->state($token)['next'];
$this->assertSame($second->id, $next['id']);
$this->assertSame('Zweite?', $next['question']);
$this->assertSame(['Ja', 'Nein'], $next['options']);
$this->goLive($poll, $second);
$this->assertSame('Letzte?', $this->state($token)['next']['question'], 'hidden slides are skipped');
$last = $this->slidesTable()->find()->where(['poll_id' => $poll->id, 'type' => Slide::TYPE_WORDCLOUD])->firstOrFail();
$this->goLive($poll, $last);
$this->assertNull($this->state($token)['next'], 'nothing after the last slide');
}
public function testPreviewRevealsNoSolution(): void
{
[$poll, $token] = $this->createPoll();
$first = $this->createSlide($poll, Slide::TYPE_CONTENT);
$this->createSlide($poll, Slide::TYPE_QUIZ, [], ['Richtig', 'Falsch']);
$this->createSlide($poll, Slide::TYPE_ORDER, [], ['Eins', 'Zwei', 'Drei']);
$this->goLive($poll, $first);
$quiz = $this->state($token)['next'];
$this->assertSame(['Richtig', 'Falsch'], $quiz['options']);
$this->assertStringNotContainsString('is_correct', json_encode($quiz));
$order = $this->slidesTable()->find()->where(['poll_id' => $poll->id, 'type' => Slide::TYPE_ORDER])->firstOrFail();
$quizSlide = $this->slidesTable()->find()->where(['poll_id' => $poll->id, 'type' => Slide::TYPE_QUIZ])->firstOrFail();
$this->goLive($poll, $quizSlide);
$this->assertSame([], $this->state($token)['next']['options'], 'the stored order is the solution');
$this->assertSame($order->id, $this->state($token)['next']['id']);
}
}