diff --git a/app/Form/Actions/HasValidation.php b/app/Form/Actions/HasValidation.php index b3daae21..4efec438 100644 --- a/app/Form/Actions/HasValidation.php +++ b/app/Form/Actions/HasValidation.php @@ -18,6 +18,7 @@ trait HasValidation 'name' => 'required|string|max:255', 'config' => 'array', 'config.sections.*.name' => 'required', + 'config.sections.*.intro' => 'nullable|string', 'config.sections.*.fields' => 'array', 'config.sections.*.fields.*.name' => 'required|string', 'config.sections.*.fields.*.type' => ['required', 'string', Rule::in(array_column(Field::asMeta(), 'id'))], diff --git a/app/Form/Data/SectionData.php b/app/Form/Data/SectionData.php index eb57c208..d0d4bbfe 100644 --- a/app/Form/Data/SectionData.php +++ b/app/Form/Data/SectionData.php @@ -15,7 +15,8 @@ class SectionData extends Data public string $name, #[WithCast(FieldCollectionCast::class)] #[WithTransformer(FieldCollectionTransformer::class)] - public FieldCollection $fields + public FieldCollection $fields, + public ?string $intro ) { } } diff --git a/tests/Feature/Form/FormUpdateActionTest.php b/tests/Feature/Form/FormUpdateActionTest.php index 6cd1ed32..0c12f3ce 100644 --- a/tests/Feature/Form/FormUpdateActionTest.php +++ b/tests/Feature/Form/FormUpdateActionTest.php @@ -59,6 +59,20 @@ class FormUpdateActionTest extends FormTestCase $this->assertEquals(['firstname'], $form->fresh()->meta['active_columns']); } + public function testItUpdatesIntroOfSections(): void + { + $this->login()->loginNami()->withoutExceptionHandling(); + $form = Form::factory() + ->sections([FormtemplateSectionRequest::new()->intro('aaa')]) + ->create(); + $payload = FormRequest::new()->sections([ + FormtemplateSectionRequest::new()->intro('aaa') + ])->create(); + + $this->patchJson(route('form.update', ['form' => $form]), $payload)->assertSessionDoesntHaveErrors()->assertOk(); + $this->assertEquals('aaa', $form->fresh()->config->sections[0]->intro); + } + public function testItUpdatesActiveState(): void { $this->login()->loginNami()->withoutExceptionHandling(); diff --git a/tests/Feature/Form/FormtemplateSectionRequest.php b/tests/Feature/Form/FormtemplateSectionRequest.php index 1c0cb950..490b3cc5 100644 --- a/tests/Feature/Form/FormtemplateSectionRequest.php +++ b/tests/Feature/Form/FormtemplateSectionRequest.php @@ -16,6 +16,7 @@ class FormtemplateSectionRequest extends RequestFactory { return [ 'name' => $this->faker->words(5, true), + 'intro' => '', 'fields' => [], ]; } @@ -28,6 +29,11 @@ class FormtemplateSectionRequest extends RequestFactory return $this->state(['fields' => $fields]); } + public function intro(string $intro): self + { + return $this->state(['intro' => $intro]); + } + /** * @param mixed $args */