Add internal feedback and comments to scale slides
- Setting "private": distribution and average are only shown in the
admin evaluation page and CSV export, the stage shows just the count.
- Setting "comments": optional comment field for participants; on public
scales the comments rotate on the results ("Kommentar X von N") with
previous/next/pause controls.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a138425ab0
commit
238797ecfd
15 files changed
+665
-23
No files matched your search
@@ -12,7 +12,7 @@ use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
/**
|
||||
* Open questions as anonymous feedback: answers only in the admin area.
|
||||
* Open questions and scales as anonymous/internal feedback: results only in the admin area.
|
||||
*/
|
||||
class PrivateFeedbackTest extends TestCase
|
||||
{
|
||||
@@ -157,4 +157,108 @@ class PrivateFeedbackTest extends TestCase
|
||||
$this->assertFalse($state['results']['private']);
|
||||
$this->assertSame('Offen', $state['results']['answers'][0]['text']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0: \App\Model\Entity\Poll, 1: string, 2: \App\Model\Entity\Slide}
|
||||
*/
|
||||
protected function privateScaleWithRatings(): array
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
$slide = $this->createSlide($poll, Slide::TYPE_SCALE, ['settings' => ['scale_min' => 1, 'scale_max' => 5, 'private' => true]]);
|
||||
$poll = $this->goLive($poll, $slide);
|
||||
$votes = new VoteService();
|
||||
$votes->submit($poll, $slide, VoteService::participantHash(str_repeat('a', 32), $poll->id), ['value' => 2]);
|
||||
$votes->submit($poll, $slide, VoteService::participantHash(str_repeat('b', 32), $poll->id), ['value' => 5]);
|
||||
|
||||
return [$poll, $token, $slide];
|
||||
}
|
||||
|
||||
public function testScaleSettingIsSanitized(): void
|
||||
{
|
||||
$this->assertTrue(SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['private' => '1'])['private']);
|
||||
$this->assertFalse(SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, [])['private']);
|
||||
|
||||
[$poll] = $this->createPoll();
|
||||
$this->assertFalse($this->createSlide($poll, Slide::TYPE_SCALE, ['settings' => []])->isPrivate());
|
||||
}
|
||||
|
||||
public function testFormSavesPrivateScaleSetting(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
$this->post("/admin/$token/slides/add?type=scale", [
|
||||
'type' => 'scale',
|
||||
'question' => 'Wie zufrieden bist du?',
|
||||
'settings' => ['scale_min' => '1', 'scale_max' => '5', 'private' => '1'],
|
||||
]);
|
||||
|
||||
$slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->firstOrFail();
|
||||
$this->assertTrue($slide->isPrivate());
|
||||
}
|
||||
|
||||
public function testPresenterSeesOnlyTheScaleCount(): void
|
||||
{
|
||||
[, $token] = $this->privateScaleWithRatings();
|
||||
|
||||
$this->get("/admin/$token/state");
|
||||
$state = json_decode((string)$this->_response->getBody(), true);
|
||||
|
||||
$this->assertTrue($state['results']['private']);
|
||||
$this->assertSame([], $state['results']['buckets']);
|
||||
$this->assertNull($state['results']['average']);
|
||||
$this->assertSame(2, $state['results']['participants']);
|
||||
}
|
||||
|
||||
public function testParticipantsNeverSeeScaleResults(): void
|
||||
{
|
||||
[$poll] = $this->privateScaleWithRatings();
|
||||
$this->assertTrue($poll->show_results_to_participants);
|
||||
|
||||
$this->assertNull($this->participantState($poll)['results']);
|
||||
$this->get('/p/' . $poll->join_code);
|
||||
$this->assertResponseContains('Internes Feedback');
|
||||
|
||||
$this->post('/p/' . $poll->join_code . '/vote', ['slide_id' => $poll->current_slide_id, 'value' => '3']);
|
||||
$this->assertNull($this->participantState($poll)['results']);
|
||||
}
|
||||
|
||||
public function testEmbedSeesOnlyTheScaleCount(): void
|
||||
{
|
||||
[$poll, , $slide] = $this->privateScaleWithRatings();
|
||||
$key = $this->pollsTable()->ensureEmbedKey($poll);
|
||||
|
||||
$this->get("/e/$key/{$slide->id}/state");
|
||||
$state = json_decode((string)$this->_response->getBody(), true);
|
||||
|
||||
$this->assertResponseOk();
|
||||
$this->assertSame([], $state['results']['buckets']);
|
||||
$this->assertNull($state['results']['average']);
|
||||
}
|
||||
|
||||
public function testAdminReadsScaleResults(): void
|
||||
{
|
||||
[, $token, $slide] = $this->privateScaleWithRatings();
|
||||
|
||||
$this->get("/admin/$token");
|
||||
$this->assertResponseContains("/slides/{$slide->id}/answers");
|
||||
|
||||
$this->get("/admin/$token/slides/{$slide->id}/answers");
|
||||
$this->assertResponseOk();
|
||||
$this->assertResponseContains('Internes Feedback');
|
||||
$this->assertResponseContains('3,5');
|
||||
$this->assertResponseContains('2 Bewertungen');
|
||||
}
|
||||
|
||||
public function testPublicScaleStillShowsResults(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
$slide = $this->createSlide($poll, Slide::TYPE_SCALE, ['settings' => ['scale_min' => 1, 'scale_max' => 5]]);
|
||||
$poll = $this->goLive($poll, $slide);
|
||||
(new VoteService())->submit($poll, $slide, VoteService::participantHash(str_repeat('c', 32), $poll->id), ['value' => 4]);
|
||||
|
||||
$this->get("/admin/$token/state");
|
||||
$state = json_decode((string)$this->_response->getBody(), true);
|
||||
|
||||
$this->assertFalse($state['results']['private']);
|
||||
$this->assertEqualsWithDelta(4.0, $state['results']['average'], 0.001);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
<?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\VoteException;
|
||||
use App\Service\VoteService;
|
||||
use App\Test\TestCase\PlenarioTestTrait;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
/**
|
||||
* Scale slides with an optional comment field: comments rotate on the results unless the scale is private.
|
||||
*/
|
||||
class ScaleCommentsTest 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $settings Extra settings
|
||||
* @return array{0: \App\Model\Entity\Poll, 1: string, 2: \App\Model\Entity\Slide}
|
||||
*/
|
||||
protected function scaleWithComments(array $settings = []): array
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
$slide = $this->createSlide($poll, Slide::TYPE_SCALE, [
|
||||
'settings' => $settings + ['scale_min' => 1, 'scale_max' => 5, 'comments' => true],
|
||||
]);
|
||||
$poll = $this->goLive($poll, $slide);
|
||||
$votes = new VoteService();
|
||||
$votes->submit($poll, $slide, $this->hash('a', $poll), ['value' => 4, 'comment' => ' Sehr <gut> ']);
|
||||
$votes->submit($poll, $slide, $this->hash('b', $poll), ['value' => 2, 'comment' => '']);
|
||||
$votes->submit($poll, $slide, $this->hash('c', $poll), ['value' => 3, 'comment' => 'Zu lang']);
|
||||
|
||||
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 testSettingIsSanitized(): void
|
||||
{
|
||||
$this->assertTrue(SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['comments' => '1'])['comments']);
|
||||
$this->assertFalse(SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, [])['comments']);
|
||||
|
||||
[$poll] = $this->createPoll();
|
||||
$this->assertFalse($this->createSlide($poll, Slide::TYPE_SCALE, ['settings' => []])->hasComments());
|
||||
}
|
||||
|
||||
public function testFormSavesCommentSetting(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
$this->post("/admin/$token/slides/add?type=scale", [
|
||||
'type' => 'scale',
|
||||
'question' => 'Wie fandest du den Abend?',
|
||||
'settings' => ['scale_min' => '1', 'scale_max' => '5', 'comments' => '1'],
|
||||
]);
|
||||
|
||||
$slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->firstOrFail();
|
||||
$this->assertTrue($slide->hasComments());
|
||||
}
|
||||
|
||||
public function testParticipantPageShowsCommentField(): void
|
||||
{
|
||||
[$poll, , $slide] = $this->scaleWithComments();
|
||||
$this->slidesTable()->Responses->deleteAll(['slide_id' => $slide->id]);
|
||||
|
||||
$this->get('/p/' . $poll->join_code);
|
||||
$this->assertResponseContains('name="comment"');
|
||||
$this->assertResponseContains('Kommentar (optional)');
|
||||
}
|
||||
|
||||
public function testCommentIsStoredWithTheRating(): void
|
||||
{
|
||||
[$poll, , $slide] = $this->scaleWithComments();
|
||||
|
||||
$this->post('/p/' . $poll->join_code . '/vote', ['slide_id' => $slide->id, 'value' => '5', 'comment' => 'Per Formular']);
|
||||
|
||||
$row = $this->slidesTable()->Responses->find()->where(['slide_id' => $slide->id])->orderBy(['id' => 'DESC'])->firstOrFail();
|
||||
$this->assertSame(5, $row->numeric_value);
|
||||
$this->assertSame('Per Formular', $row->text_value);
|
||||
}
|
||||
|
||||
public function testCommentIsIgnoredWithoutCommentField(): void
|
||||
{
|
||||
[$poll] = $this->createPoll();
|
||||
$slide = $this->createSlide($poll, Slide::TYPE_SCALE, ['settings' => ['scale_min' => 1, 'scale_max' => 5]]);
|
||||
$poll = $this->goLive($poll, $slide);
|
||||
(new VoteService())->submit($poll, $slide, $this->hash('a', $poll), ['value' => 3, 'comment' => 'Eingeschmuggelt']);
|
||||
|
||||
$row = $this->slidesTable()->Responses->find()->where(['slide_id' => $slide->id])->firstOrFail();
|
||||
$this->assertNull($row->text_value);
|
||||
}
|
||||
|
||||
public function testTooLongCommentIsRejected(): void
|
||||
{
|
||||
[$poll] = $this->createPoll();
|
||||
$slide = $this->createSlide($poll, Slide::TYPE_SCALE, ['settings' => ['comments' => true]]);
|
||||
$poll = $this->goLive($poll, $slide);
|
||||
|
||||
$this->expectException(VoteException::class);
|
||||
(new VoteService())->submit($poll, $slide, $this->hash('a', $poll), [
|
||||
'value' => 3,
|
||||
'comment' => str_repeat('x', VoteService::MAX_TEXT_LENGTH + 1),
|
||||
]);
|
||||
}
|
||||
|
||||
public function testPresenterGetsCommentsOldestFirst(): void
|
||||
{
|
||||
[, $token] = $this->scaleWithComments();
|
||||
|
||||
$results = $this->presenterResults($token);
|
||||
|
||||
$this->assertSame(3, $results['participants']);
|
||||
$this->assertEqualsWithDelta(3.0, $results['average'], 0.001);
|
||||
$this->assertSame(['Sehr <gut>', 'Zu lang'], array_column($results['comments'], 'text'));
|
||||
$this->assertSame([4, 3], array_column($results['comments'], 'value'));
|
||||
}
|
||||
|
||||
public function testParticipantsSeeCommentsOnlyWithPublicResults(): void
|
||||
{
|
||||
[$poll] = $this->scaleWithComments();
|
||||
// Participant "a" has already rated.
|
||||
$this->cookie('plenario_pid', str_repeat('a', 32));
|
||||
|
||||
$this->get('/p/' . $poll->join_code . '/state');
|
||||
$state = json_decode((string)$this->_response->getBody(), true);
|
||||
$this->assertCount(2, $state['results']['comments']);
|
||||
|
||||
$poll->show_results_to_participants = false;
|
||||
$this->pollsTable()->saveOrFail($poll);
|
||||
$this->get('/p/' . $poll->join_code . '/state');
|
||||
$this->assertNull(json_decode((string)$this->_response->getBody(), true)['results']);
|
||||
}
|
||||
|
||||
public function testPrivateScaleNeverShowsComments(): void
|
||||
{
|
||||
[$poll, $token, $slide] = $this->scaleWithComments(['private' => true]);
|
||||
|
||||
$results = $this->presenterResults($token);
|
||||
$this->assertSame([], $results['comments']);
|
||||
$this->assertResponseNotContains('Sehr');
|
||||
|
||||
$key = $this->pollsTable()->ensureEmbedKey($poll);
|
||||
$this->get("/e/$key/{$slide->id}/state");
|
||||
$this->assertResponseNotContains('Sehr');
|
||||
|
||||
$this->get('/p/' . $poll->join_code . '/state');
|
||||
$this->assertResponseNotContains('Sehr');
|
||||
}
|
||||
|
||||
public function testAdminEvaluationListsComments(): void
|
||||
{
|
||||
[, $token, $slide] = $this->scaleWithComments(['private' => true]);
|
||||
|
||||
$this->get("/admin/$token");
|
||||
$this->assertResponseContains("/slides/{$slide->id}/answers");
|
||||
|
||||
$this->get("/admin/$token/slides/{$slide->id}/answers");
|
||||
$this->assertResponseOk();
|
||||
$this->assertResponseContains('2 Kommentare');
|
||||
$this->assertResponseContains('Sehr <gut>');
|
||||
$this->assertResponseContains('Bewertung 4');
|
||||
}
|
||||
|
||||
public function testExportContainsComments(): void
|
||||
{
|
||||
[, $token] = $this->scaleWithComments();
|
||||
|
||||
$this->get("/admin/$token/export.csv");
|
||||
|
||||
$this->assertResponseContains('4 (Kommentar: Sehr <gut>)');
|
||||
$this->assertResponseContains(';2;');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user