Add internal feedback and comments to choice slides
Same options as for scales: "private" shows only the number of votes on the stage, "comments" adds an optional comment field whose comments rotate in the presentation, "comment_ratings" shows the chosen answer(s) next to each comment. With multiple choice the comment is stored on the participant's first row. Settings and participant fields are shared elements for scale and choice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3e09906830
commit
547b564e32
18 files changed
+485
-108
No files matched your search
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Controller;
|
||||
|
||||
use App\Model\Entity\Poll;
|
||||
use App\Model\Entity\Slide;
|
||||
use App\Model\Table\SlidesTable;
|
||||
use App\Service\VoteService;
|
||||
use App\Test\TestCase\PlenarioTestTrait;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
/**
|
||||
* Choice slides as internal feedback and with an optional comment field.
|
||||
*/
|
||||
class ChoiceFeedbackTest 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Choice "Ja/Nein/Vielleicht" (multiple) with two votes and one comment.
|
||||
*
|
||||
* @param array<string, mixed> $settings Settings
|
||||
* @return array{0: \App\Model\Entity\Poll, 1: string, 2: \App\Model\Entity\Slide}
|
||||
*/
|
||||
protected function choiceWithVotes(array $settings): array
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
$slide = $this->createSlide($poll, Slide::TYPE_CHOICE, ['settings' => $settings + ['multiple' => true]], ['Ja', 'Nein', 'Vielleicht']);
|
||||
$poll = $this->goLive($poll, $slide);
|
||||
[$yes, $no, $maybe] = array_map(fn($option) => $option->id, $slide->slide_options);
|
||||
$votes = new VoteService();
|
||||
$votes->submit($poll, $slide, $this->hash('a', $poll), ['option_ids' => [$yes, $maybe], 'comment' => 'Weil <darum>']);
|
||||
$votes->submit($poll, $slide, $this->hash('b', $poll), ['option_ids' => [$no]]);
|
||||
|
||||
return [$poll, $token, $slide];
|
||||
}
|
||||
|
||||
protected function hash(string $char, Poll $poll): string
|
||||
{
|
||||
return VoteService::participantHash(str_repeat($char, 32), $poll->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function presenterResults(string $token): array
|
||||
{
|
||||
$this->get("/admin/$token/state");
|
||||
|
||||
return json_decode((string)$this->_response->getBody(), true)['results'];
|
||||
}
|
||||
|
||||
public function testSettingsAreSanitized(): void
|
||||
{
|
||||
$settings = SlidesTable::sanitizeSettings(Slide::TYPE_CHOICE, ['private' => '1', 'comments' => '1', 'comment_ratings' => '1']);
|
||||
$this->assertTrue($settings['private']);
|
||||
$this->assertTrue($settings['comments']);
|
||||
$this->assertTrue($settings['comment_ratings']);
|
||||
|
||||
$settings = SlidesTable::sanitizeSettings(Slide::TYPE_CHOICE, []);
|
||||
$this->assertFalse($settings['private']);
|
||||
$this->assertFalse($settings['comments']);
|
||||
$this->assertFalse($settings['comment_ratings']);
|
||||
|
||||
[$poll] = $this->createPoll();
|
||||
$slide = $this->createSlide($poll, Slide::TYPE_CHOICE, ['settings' => ['multiple' => false]]);
|
||||
$this->assertFalse($slide->isPrivate());
|
||||
$this->assertFalse($slide->hasComments());
|
||||
}
|
||||
|
||||
public function testFormOffersFeedbackSettings(): void
|
||||
{
|
||||
[, $token] = $this->createPoll();
|
||||
|
||||
$this->get("/admin/$token/slides/add?type=choice");
|
||||
$this->assertResponseOk();
|
||||
$this->assertResponseContains('name="settings[comments]"');
|
||||
$this->assertResponseContains('Gewählte Antwort beim Kommentar');
|
||||
$this->assertResponseContains('name="settings[private]"');
|
||||
|
||||
$this->get("/admin/$token/slides/add?type=scale");
|
||||
$this->assertResponseOk();
|
||||
$this->assertResponseContains('Bewertung beim Kommentar');
|
||||
}
|
||||
|
||||
public function testCommentIsStoredOnceForMultipleChoice(): void
|
||||
{
|
||||
[, , $slide] = $this->choiceWithVotes(['comments' => true]);
|
||||
|
||||
$texts = $this->slidesTable()->Responses->find()
|
||||
->where(['slide_id' => $slide->id, 'text_value IS NOT' => null])
|
||||
->all()
|
||||
->extract('text_value')
|
||||
->toList();
|
||||
$this->assertSame(['Weil <darum>'], $texts);
|
||||
}
|
||||
|
||||
public function testCommentIsIgnoredWithoutCommentField(): void
|
||||
{
|
||||
[, , $slide] = $this->choiceWithVotes([]);
|
||||
|
||||
$this->assertFalse($this->slidesTable()->Responses->exists(['slide_id' => $slide->id, 'text_value IS NOT' => null]));
|
||||
}
|
||||
|
||||
public function testParticipantPageShowsCommentFieldAndHint(): void
|
||||
{
|
||||
[$poll, , $slide] = $this->choiceWithVotes(['comments' => true, 'private' => true]);
|
||||
$this->slidesTable()->Responses->deleteAll(['slide_id' => $slide->id]);
|
||||
|
||||
$this->get('/p/' . $poll->join_code);
|
||||
$this->assertResponseContains('name="comment"');
|
||||
$this->assertResponseContains('Internes Feedback');
|
||||
}
|
||||
|
||||
public function testPresenterGetsCommentsWithoutAnswerByDefault(): void
|
||||
{
|
||||
[, $token] = $this->choiceWithVotes(['comments' => true]);
|
||||
|
||||
$results = $this->presenterResults($token);
|
||||
|
||||
$this->assertFalse($results['private']);
|
||||
$this->assertSame([1, 1, 1], array_column($results['options'], 'count'));
|
||||
$this->assertSame(['Weil <darum>'], array_column($results['comments'], 'text'));
|
||||
$this->assertSame([null], array_column($results['comments'], 'value'));
|
||||
}
|
||||
|
||||
public function testChosenAnswersNextToCommentAreOptional(): void
|
||||
{
|
||||
[, $token] = $this->choiceWithVotes(['comments' => true, 'comment_ratings' => true]);
|
||||
|
||||
$this->assertSame(['Ja, Vielleicht'], array_column($this->presenterResults($token)['comments'], 'value'));
|
||||
}
|
||||
|
||||
public function testParticipantsNeverSeeComments(): void
|
||||
{
|
||||
[$poll] = $this->choiceWithVotes(['comments' => true]);
|
||||
$this->cookie('plenario_pid', str_repeat('a', 32));
|
||||
|
||||
$this->get('/p/' . $poll->join_code . '/state');
|
||||
$state = json_decode((string)$this->_response->getBody(), true);
|
||||
|
||||
$this->assertNotEmpty($state['results']['options']);
|
||||
$this->assertSame([], $state['results']['comments']);
|
||||
$this->assertResponseNotContains('darum');
|
||||
}
|
||||
|
||||
public function testPrivateChoiceShowsOnlyTheCount(): void
|
||||
{
|
||||
[$poll, $token, $slide] = $this->choiceWithVotes(['private' => true, 'comments' => true]);
|
||||
|
||||
$results = $this->presenterResults($token);
|
||||
$this->assertTrue($results['private']);
|
||||
$this->assertSame([], $results['options']);
|
||||
$this->assertSame([], $results['comments']);
|
||||
$this->assertSame(2, $results['participants']);
|
||||
$this->assertResponseNotContains('darum');
|
||||
|
||||
$key = $this->pollsTable()->ensureEmbedKey($poll);
|
||||
$this->get("/e/$key/{$slide->id}/state");
|
||||
$this->assertResponseNotContains('darum');
|
||||
|
||||
$this->cookie('plenario_pid', str_repeat('a', 32));
|
||||
$this->get('/p/' . $poll->join_code . '/state');
|
||||
$this->assertNull(json_decode((string)$this->_response->getBody(), true)['results']);
|
||||
}
|
||||
|
||||
public function testAdminEvaluationShowsVotesAndComments(): void
|
||||
{
|
||||
[, $token, $slide] = $this->choiceWithVotes(['private' => true, 'comments' => true]);
|
||||
|
||||
$this->get("/admin/$token");
|
||||
$this->assertResponseContains("/slides/{$slide->id}/answers");
|
||||
$this->assertResponseContains('intern');
|
||||
|
||||
$this->get("/admin/$token/slides/{$slide->id}/answers");
|
||||
$this->assertResponseOk();
|
||||
$this->assertResponseContains('2 Personen haben abgestimmt');
|
||||
$this->assertResponseContains('Internes Feedback');
|
||||
$this->assertResponseContains('1 Kommentar');
|
||||
$this->assertResponseContains('Weil <darum>');
|
||||
$this->assertResponseContains('Antwort: Ja, Vielleicht');
|
||||
}
|
||||
|
||||
public function testExportContainsComment(): void
|
||||
{
|
||||
[, $token] = $this->choiceWithVotes(['comments' => true]);
|
||||
|
||||
$this->get("/admin/$token/export.csv");
|
||||
|
||||
$this->assertResponseContains('Ja (Kommentar: Weil <darum>)');
|
||||
$this->assertResponseContains(';Vielleicht;');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user