Add admin menu drawer and poll cloning, drop participant screen tools
- Remove fullscreen and wake lock buttons from the participant view. - Turn the admin sidebar into a drawer below 900px, opened from a header menu button next to the theme switch (progressive enhancement). - Add "Umfrage kopieren": clone a poll with all slides, options and images but without responses, with its own join code and admin link. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0f91377de3
commit
bd57f23be6
15 files changed
+374
-138
No files matched your search
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Controller;
|
||||
|
||||
use App\Model\Entity\Slide;
|
||||
use App\Service\VoteService;
|
||||
use App\Test\TestCase\PlenarioTestTrait;
|
||||
use Cake\ORM\TableRegistry;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
/**
|
||||
* Cloning a whole poll without responses (admin:clone).
|
||||
*/
|
||||
class ClonePollTest 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 testCopiesSlidesButNoResponses(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
$first = $this->createSlide($poll, Slide::TYPE_CHOICE, ['description' => '*Wichtig*'], ['Rot', 'Grün']);
|
||||
$quiz = $this->createSlide($poll, Slide::TYPE_QUIZ, [], ['Richtig', 'Falsch']);
|
||||
$hidden = $this->createSlide($poll, Slide::TYPE_OPEN);
|
||||
$hidden->is_hidden = true;
|
||||
$this->slidesTable()->saveOrFail($hidden);
|
||||
$poll = $this->goLive($poll, $first);
|
||||
(new VoteService())->submit($poll, $first, VoteService::participantHash(str_repeat('a', 32), $poll->id), [
|
||||
'option_id' => $first->slide_options[0]->id,
|
||||
]);
|
||||
|
||||
$this->post("/admin/$token/clone");
|
||||
|
||||
$polls = $this->pollsTable()->find()->orderBy(['id' => 'ASC'])->all()->toList();
|
||||
$this->assertCount(2, $polls);
|
||||
$copy = $polls[1];
|
||||
$this->assertNotSame($poll->join_code, $copy->join_code);
|
||||
$this->assertSame($poll->email, $copy->email);
|
||||
$this->assertStringEndsWith('(Kopie)', $copy->title);
|
||||
$this->assertNull($copy->current_slide_id, 'copy is not started');
|
||||
$this->assertSame($first->id, $this->pollsTable()->get($poll->id)->current_slide_id, 'original stays live');
|
||||
|
||||
$slides = $this->slidesTable()->listForPoll($copy->id);
|
||||
$this->assertSame([1, 2, 3], array_map(fn($s) => $s->position, $slides));
|
||||
$this->assertSame(
|
||||
[$first->question, $quiz->question, $hidden->question],
|
||||
array_map(fn($s) => $s->question, $slides),
|
||||
);
|
||||
$this->assertSame('*Wichtig*', $slides[0]->description);
|
||||
$this->assertSame(['Rot', 'Grün'], array_map(fn($o) => $o->label, $slides[0]->slide_options));
|
||||
$this->assertSame([true, false], array_map(fn($o) => $o->is_correct, $slides[1]->slide_options));
|
||||
$this->assertTrue($slides[2]->is_hidden);
|
||||
$this->assertSame(Slide::QUIZ_READY, $slides[1]->quizPhase());
|
||||
|
||||
$responses = TableRegistry::getTableLocator()->get('Responses');
|
||||
$this->assertSame(0, $responses->find()->matching('Slides', fn($q) => $q->where(['Slides.poll_id' => $copy->id]))->count());
|
||||
$this->assertSame(1, $responses->find()->where(['slide_id' => $first->id])->count(), 'original keeps its votes');
|
||||
$this->assertCount(3, $this->slidesTable()->listForPoll($poll->id));
|
||||
}
|
||||
|
||||
public function testRedirectsToAdminOfTheCopyOnlyViaPost(): void
|
||||
{
|
||||
[, $token] = $this->createPoll();
|
||||
|
||||
$this->get("/admin/$token/clone");
|
||||
$this->assertResponseCode(404);
|
||||
|
||||
$this->post("/admin/$token/clone");
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('/admin/');
|
||||
$this->assertHeaderNotContains('Location', $token);
|
||||
}
|
||||
|
||||
public function testDashboardOffersCloneAndMenu(): void
|
||||
{
|
||||
[, $token] = $this->createPoll();
|
||||
$this->get("/admin/$token");
|
||||
$this->assertResponseContains("/admin/$token/clone");
|
||||
$this->assertResponseContains('data-drawer-toggle');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user