From 43c528fc4623faba5209d9b2d09ea32130f5e46a Mon Sep 17 00:00:00 2001 From: philipp lang Date: Thu, 20 Jun 2024 23:29:23 +0200 Subject: [PATCH] Add has_nami and two participant urls to form --- app/Form/Data/FieldCollection.php | 5 +++++ app/Form/Resources/FormResource.php | 4 +++- tests/EndToEnd/Form/FormIndexActionTest.php | 12 ++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/Form/Data/FieldCollection.php b/app/Form/Data/FieldCollection.php index 31673e7c..2bf6a450 100644 --- a/app/Form/Data/FieldCollection.php +++ b/app/Form/Data/FieldCollection.php @@ -35,6 +35,11 @@ class FieldCollection extends Collection return $this->filter(fn ($field) => !is_a($field, NamiField::class)); } + public function hasNamiField(): bool + { + return $this->first(fn ($field) => is_a($field, NamiField::class)) !== null; + } + /** * @return stdClass */ diff --git a/app/Form/Resources/FormResource.php b/app/Form/Resources/FormResource.php index 58964496..80c4e0b0 100644 --- a/app/Form/Resources/FormResource.php +++ b/app/Form/Resources/FormResource.php @@ -46,8 +46,10 @@ class FormResource extends JsonResource 'participants_count' => $this->participants_count, 'is_active' => $this->is_active, 'is_private' => $this->is_private, + 'has_nami_field' => $this->getFields()->hasNamiField(), 'links' => [ - 'participant_index' => route('form.participant.index', ['form' => $this->getModel()]), + 'participant_index' => route('form.participant.index', ['form' => $this->getModel(), 'parent' => null]), + 'participant_root_index' => route('form.participant.index', ['form' => $this->getModel(), 'parent' => -1]), 'update' => route('form.update', ['form' => $this->getModel()]), 'destroy' => route('form.destroy', ['form' => $this->getModel()]), 'is_dirty' => route('form.is-dirty', ['form' => $this->getModel()]), diff --git a/tests/EndToEnd/Form/FormIndexActionTest.php b/tests/EndToEnd/Form/FormIndexActionTest.php index 1120929f..b43cf01d 100644 --- a/tests/EndToEnd/Form/FormIndexActionTest.php +++ b/tests/EndToEnd/Form/FormIndexActionTest.php @@ -83,6 +83,18 @@ class FormIndexActionTest extends FormTestCase ->assertInertiaCount('data.data', 2); } + public function testItDisplaysParentLinkForFormWithNamiFields(): void + { + $this->withoutExceptionHandling()->login()->loginNami(); + $form = Form::factory()->fields([$this->namiField('mitglieder')])->create(); + + sleep(1); + $this->callFilter('form.index', []) + ->assertInertiaPath('data.data.0.has_nami_field', true) + ->assertInertiaPath('data.data.0.links.participant_root_index', route('form.participant.index', ['form' => $form, 'parent' => -1])) + ->assertInertiaPath('data.data.0.links.participant_index', route('form.participant.index', ['form' => $form, 'parent' => null])); + } + public function testItDisplaysRegisterUrl(): void { $this->withoutExceptionHandling()->login()->loginNami();