refactor: split the questionnaire into teamer and bus feedback
This commit is contained in:
1 parent
2f4f9800dd
commit
a0170f5952
35 files changed
+1114
-554
No files matched your search
@@ -28,10 +28,13 @@ class QuestionnaireTemplateTest extends KernelTestCase
|
||||
{
|
||||
$crawler = $this->renderForm();
|
||||
|
||||
$this->assertCount(count($this->definition()->getQuestions()), $crawler->filter('[data-question-key]'));
|
||||
$this->assertCount(
|
||||
count($this->definition()->getQuestions()) + count($this->busDefinition()->getQuestions()),
|
||||
$crawler->filter('[data-question-key]'),
|
||||
);
|
||||
$this->assertSame(
|
||||
'{"question":"bus_company","operator":"equals","value":"other"}',
|
||||
$crawler->filter('[data-question-key="bus_company_other"]')->attr('data-show-if'),
|
||||
'{"question":"bus_feedback.bus_company","operator":"equals","value":"other"}',
|
||||
$crawler->filter('[data-question-key="bus_feedback.bus_company_other"]')->attr('data-show-if'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -40,12 +43,25 @@ class QuestionnaireTemplateTest extends KernelTestCase
|
||||
$crawler = $this->renderForm();
|
||||
|
||||
$this->assertSame('Organisation & Ablauf', trim($crawler->filter('fieldset legend')->first()->text()));
|
||||
$this->assertCount(count($this->definition()->sections), $crawler->filter('fieldset'));
|
||||
$this->assertCount(
|
||||
count($this->definition()->sections) + count($this->busDefinition()->sections),
|
||||
$crawler->filter('fieldset'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* On one page, each questionnaire keeps its own heading.
|
||||
*/
|
||||
public function testEachQuestionnaireHasItsHeading(): void
|
||||
{
|
||||
$headings = $this->renderForm()->filter('section > h2')->each(static fn (Crawler $h2): string => trim($h2->text()));
|
||||
|
||||
$this->assertSame([$this->definition()->title, $this->busDefinition()->title], $headings);
|
||||
}
|
||||
|
||||
public function testRatingIsFiveRadiosInARadioGroup(): void
|
||||
{
|
||||
$group = $this->renderForm()->filter('[data-question-key="office_briefing_rating"] [role="radiogroup"]');
|
||||
$group = $this->renderForm()->filter('[data-question-key="teamer_feedback.office_briefing_rating"] [role="radiogroup"]');
|
||||
|
||||
$this->assertCount(5, $group->filter('input[type="radio"]'));
|
||||
}
|
||||
@@ -57,23 +73,24 @@ class QuestionnaireTemplateTest extends KernelTestCase
|
||||
->submit($definition, [
|
||||
'office_briefing_rating' => 2,
|
||||
'office_briefing_low_reason' => 'Briefing kam zu spät',
|
||||
'bus_company' => 'heess',
|
||||
'had_organisational_problems' => 'no',
|
||||
'organisational_problems' => 'hidden, so dropped',
|
||||
], [], new \DateTimeImmutable())
|
||||
;
|
||||
|
||||
$html = self::getContainer()->get(Environment::class)->render('questionnaire/_answers.html.twig', [
|
||||
'definition' => $definition,
|
||||
'answers' => $response->getAnswers(),
|
||||
]);
|
||||
$html = $this->renderAnswers($definition, $response->getAnswers());
|
||||
|
||||
$this->assertStringContainsString('2 von 5', $html);
|
||||
$this->assertStringContainsString('Briefing kam zu spät', $html);
|
||||
$this->assertStringContainsString('Heeß', $html);
|
||||
$this->assertStringContainsString('Nein', $html);
|
||||
$this->assertStringNotContainsString('heess', $html);
|
||||
$this->assertStringNotContainsString('hidden, so dropped', $html);
|
||||
// nothing was answered there, so the section is left out
|
||||
$this->assertStringNotContainsString('Bewertung Bus & Fahrer', $html);
|
||||
$this->assertStringNotContainsString('Kommunikation & Zusammenarbeit', $html);
|
||||
|
||||
$html = $this->renderAnswers($this->busDefinition(), ['bus_company' => 'heess']);
|
||||
|
||||
$this->assertStringContainsString('Heeß', $html);
|
||||
$this->assertStringNotContainsString('heess', $html);
|
||||
}
|
||||
|
||||
private function renderForm(): Crawler
|
||||
@@ -82,7 +99,7 @@ class QuestionnaireTemplateTest extends KernelTestCase
|
||||
$container = self::getContainer();
|
||||
|
||||
$form = $container->get(FormFactoryInterface::class)->create(QuestionnaireType::class, [], [
|
||||
'definition' => $this->definition(),
|
||||
'definitions' => [$this->definition(), $this->busDefinition()],
|
||||
'csrf_protection' => false,
|
||||
]);
|
||||
|
||||
@@ -94,8 +111,23 @@ class QuestionnaireTemplateTest extends KernelTestCase
|
||||
return new Crawler($html);
|
||||
}
|
||||
|
||||
private function renderAnswers(Definition $definition, array $answers): string
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
return self::getContainer()->get(Environment::class)->render('questionnaire/_answers.html.twig', [
|
||||
'definition' => $definition,
|
||||
'answers' => $answers,
|
||||
]);
|
||||
}
|
||||
|
||||
private function definition(): Definition
|
||||
{
|
||||
return new QuestionnaireCatalog(__DIR__.'/../../config/questionnaires')->get(QuestionnaireCatalog::TEAMER_ASSIGNMENT);
|
||||
return new QuestionnaireCatalog(__DIR__.'/../../config/questionnaires')->get(QuestionnaireCatalog::TEAMER_FEEDBACK);
|
||||
}
|
||||
|
||||
private function busDefinition(): Definition
|
||||
{
|
||||
return new QuestionnaireCatalog(__DIR__.'/../../config/questionnaires')->get(QuestionnaireCatalog::BUS_FEEDBACK);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user