Files
gnilebeinandClaude Opus 5.5 b3c80ab79f
CI / Deploy / test (push) Successful in 1m8s
CI / Deploy / deploy (push) Skipped
Show scale results as average next to a donut chart
Average and distribution now sit side by side: a big average figure with
its gauge or stars, and the distribution as a donut (CSS conic-gradient,
shades of one colour, legend with percent and count). A single dropdown
setting scale_view (both, average only, chart only) replaces the two
checkboxes; a single part is centred.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 13:38:58 +01:00

86 lines
3.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Test\TestCase\Controller;
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;
/**
* Scale slides show average and distribution in the presentation, or only one of them (setting scale_view).
*/
class ScalePartsTest 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<string, mixed> Presenter results
*/
protected function presenterResults(array $settings): array
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_SCALE, ['settings' => $settings + ['scale_min' => 1, 'scale_max' => 5]]);
$poll = $this->goLive($poll, $slide);
(new VoteService())->submit($poll, $slide, VoteService::participantHash(str_repeat('a', 32), $poll->id), ['value' => 4]);
$this->get("/admin/$token/state");
return json_decode((string)$this->_response->getBody(), true)['results'];
}
public function testBothPartsAreShownByDefault(): void
{
$this->assertSame(Slide::SCALE_VIEW_BOTH, SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, [])['scale_view']);
$this->assertSame(Slide::SCALE_VIEW_BOTH, $this->presenterResults([])['view']);
}
public function testUnknownViewFallsBackToBoth(): void
{
$settings = SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['scale_view' => 'nothing']);
$this->assertSame(Slide::SCALE_VIEW_BOTH, $settings['scale_view']);
}
public function testOnlyOnePartKeepsTheDataComplete(): void
{
$results = $this->presenterResults(['scale_view' => Slide::SCALE_VIEW_CHART]);
$this->assertSame(Slide::SCALE_VIEW_CHART, $results['view']);
// The data stays complete (evaluation, PDF), only the presentation hides a part.
$this->assertEqualsWithDelta(4.0, $results['average'], 0.001);
$this->assertSame(1, $results['participants']);
}
public function testFormSavesView(): void
{
[$poll, $token] = $this->createPoll();
$this->get("/admin/$token/slides/add?type=scale");
$this->assertResponseContains('name="settings[scale_view]"');
$this->post("/admin/$token/slides/add?type=scale", [
'type' => 'scale',
'question' => 'Wie fandest du den Abend?',
'settings' => ['scale_min' => '1', 'scale_max' => '5', 'scale_view' => Slide::SCALE_VIEW_AVERAGE],
]);
$slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->firstOrFail();
$this->assertSame(Slide::SCALE_VIEW_AVERAGE, $slide->setting('scale_view'));
}
}