diff --git a/app/Form/Actions/FormStoreAction.php b/app/Form/Actions/FormStoreAction.php index 32cece88..afa9ddb8 100644 --- a/app/Form/Actions/FormStoreAction.php +++ b/app/Form/Actions/FormStoreAction.php @@ -28,8 +28,6 @@ class FormStoreAction 'to' => 'required|date', 'registration_from' => 'present|nullable|date', 'registration_until' => 'present|nullable|date', - 'mail_top' => 'array', - 'mail_bottom' => 'array', 'header_image' => 'required|exclude', 'mailattachments' => 'present|array|exclude', 'is_active' => 'boolean', diff --git a/app/Form/Actions/FormUpdateAction.php b/app/Form/Actions/FormUpdateAction.php index 65f73c56..e921e512 100644 --- a/app/Form/Actions/FormUpdateAction.php +++ b/app/Form/Actions/FormUpdateAction.php @@ -30,8 +30,6 @@ class FormUpdateAction 'to' => 'required|date', 'registration_from' => 'present|nullable|date', 'registration_until' => 'present|nullable|date', - 'mail_top' => 'array', - 'mail_bottom' => 'array', 'is_active' => 'boolean', 'is_private' => 'boolean', 'export' => 'nullable|array', diff --git a/app/Form/Actions/HasValidation.php b/app/Form/Actions/HasValidation.php index 4efec438..10141d17 100644 --- a/app/Form/Actions/HasValidation.php +++ b/app/Form/Actions/HasValidation.php @@ -28,6 +28,8 @@ trait HasValidation 'config.sections.*.fields.*.columns.mobile' => 'required|numeric|gt:0|lte:2', 'config.sections.*.fields.*.columns.tablet' => 'required|numeric|gt:0|lte:4', 'config.sections.*.fields.*.columns.desktop' => 'required|numeric|gt:0|lte:6', + 'mail_top' => 'array', + 'mail_bottom' => 'array', ]; } diff --git a/app/Form/Models/Formtemplate.php b/app/Form/Models/Formtemplate.php index 1efae888..86ab2cf1 100644 --- a/app/Form/Models/Formtemplate.php +++ b/app/Form/Models/Formtemplate.php @@ -3,6 +3,7 @@ namespace App\Form\Models; use App\Form\Data\FormConfigData; +use App\Lib\Editor\EditorData; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -17,5 +18,7 @@ class Formtemplate extends Model public $casts = [ 'config' => FormConfigData::class, + 'mail_top' => EditorData::class, + 'mail_bottom' => EditorData::class, ]; } diff --git a/app/Form/Resources/FormtemplateResource.php b/app/Form/Resources/FormtemplateResource.php index f89ed835..a53f2e5f 100644 --- a/app/Form/Resources/FormtemplateResource.php +++ b/app/Form/Resources/FormtemplateResource.php @@ -7,6 +7,7 @@ use App\Form\Enums\SpecialType; use App\Form\Fields\Field; use App\Form\Models\Formtemplate; use App\Group; +use App\Lib\Editor\EditorData; use App\Lib\HasMeta; use Illuminate\Http\Resources\Json\JsonResource; @@ -52,6 +53,8 @@ class FormtemplateResource extends JsonResource ], 'default' => [ 'name' => '', + 'mail_top' => EditorData::default(), + 'mail_bottom' => EditorData::default(), 'config' => [ 'sections' => [], ] diff --git a/database/factories/Form/Models/FormtemplateFactory.php b/database/factories/Form/Models/FormtemplateFactory.php index 3970aaaf..c0de17ff 100644 --- a/database/factories/Form/Models/FormtemplateFactory.php +++ b/database/factories/Form/Models/FormtemplateFactory.php @@ -5,6 +5,7 @@ namespace Database\Factories\Form\Models; use App\Form\Models\Formtemplate; use Illuminate\Database\Eloquent\Factories\Factory; use Tests\Feature\Form\FormtemplateSectionRequest; +use Tests\RequestFactories\EditorRequestFactory; /** * @extends Factory @@ -24,6 +25,8 @@ class FormtemplateFactory extends Factory { return [ 'name' => $this->faker->words(4, true), + 'mail_top' => EditorRequestFactory::new()->toData(), + 'mail_bottom' => EditorRequestFactory::new()->toData(), 'config' => [ 'sections' => [], ], @@ -45,4 +48,14 @@ class FormtemplateFactory extends Factory { return $this->state([str($method)->snake()->toString() => $parameters[0]]); } + + public function mailTop(EditorRequestFactory $factory): self + { + return $this->state(['mail_top' => $factory->toData()]); + } + + public function mailBottom(EditorRequestFactory $factory): self + { + return $this->state(['mail_bottom' => $factory->toData()]); + } } diff --git a/database/migrations/2024_07_14_174643_create_formtemplates_mail_columns_2.php b/database/migrations/2024_07_14_174643_create_formtemplates_mail_columns_2.php new file mode 100644 index 00000000..cf864795 --- /dev/null +++ b/database/migrations/2024_07_14_174643_create_formtemplates_mail_columns_2.php @@ -0,0 +1,34 @@ +json('mail_top')->after('name')->default(json_encode(['time' => 4, 'blocks' => [], 'version' => '1.0'])); + $table->json('mail_bottom')->after('name')->default(json_encode(['time' => 4, 'blocks' => [], 'version' => '1.0'])); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('formtemplates', function (Blueprint $table) { + $table->dropColumn('mail_top'); + $table->dropColumn('mail_bottom'); + }); + } +}; diff --git a/tests/Feature/Form/FormtemplateIndexActionTest.php b/tests/Feature/Form/FormtemplateIndexActionTest.php index f950dadf..cd958599 100644 --- a/tests/Feature/Form/FormtemplateIndexActionTest.php +++ b/tests/Feature/Form/FormtemplateIndexActionTest.php @@ -83,6 +83,16 @@ class FormtemplateIndexActionTest extends TestCase ]) ->assertInertiaPath('data.meta.default', [ 'name' => '', + 'mail_top' => [ + 'version' => '1.0', + 'blocks' => [], + 'time' => 0, + ], + 'mail_bottom' => [ + 'version' => '1.0', + 'blocks' => [], + 'time' => 0, + ], 'config' => [ 'sections' => [], ] diff --git a/tests/Feature/Form/FormtemplateRequest.php b/tests/Feature/Form/FormtemplateRequest.php index befe5189..56355664 100644 --- a/tests/Feature/Form/FormtemplateRequest.php +++ b/tests/Feature/Form/FormtemplateRequest.php @@ -6,6 +6,8 @@ use Worksome\RequestFactories\RequestFactory; /** * @method self name(string $name) + * @method self mailTop(?EditorRequestFactory $content) + * @method self mailBottom(?EditorRequestFactory $content) */ class FormtemplateRequest extends RequestFactory { @@ -33,6 +35,6 @@ class FormtemplateRequest extends RequestFactory */ public function __call(string $method, $args): self { - return $this->state([$method => $args[0]]); + return $this->state([str($method)->snake()->toString() => $args[0]]); } } diff --git a/tests/Feature/Form/FormtemplateStoreActionTest.php b/tests/Feature/Form/FormtemplateStoreActionTest.php index 619258d3..90ea0935 100644 --- a/tests/Feature/Form/FormtemplateStoreActionTest.php +++ b/tests/Feature/Form/FormtemplateStoreActionTest.php @@ -10,6 +10,7 @@ use App\Lib\Events\Succeeded; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Event; use Generator; +use Tests\RequestFactories\EditorRequestFactory; class FormtemplateStoreActionTest extends FormTestCase { @@ -20,14 +21,17 @@ class FormtemplateStoreActionTest extends FormTestCase { Event::fake([Succeeded::class]); $this->login()->loginNami()->withoutExceptionHandling(); - FormtemplateRequest::new()->name('testname')->sections([ + $payload = FormtemplateRequest::new()->name('testname')->sections([ FormtemplateSectionRequest::new()->name('Persönliches')->fields([ $this->textField('a')->name('lala1')->columns(['mobile' => 2, 'tablet' => 2, 'desktop' => 1])->required(false)->hint('hhh')->intro('intro'), $this->textareaField('b')->name('lala2')->required(false)->specialType(SpecialType::FIRSTNAME)->rows(10), ]), - ])->fake(); + ]) + ->mailTop(EditorRequestFactory::new()->text(10, 'lala')) + ->mailBottom(EditorRequestFactory::new()->text(10, 'lblb')) + ->create(); - $this->postJson(route('formtemplate.store'))->assertOk(); + $this->postJson(route('formtemplate.store'), $payload)->assertOk(); $formtemplate = Formtemplate::latest()->first(); $this->assertEquals('Persönliches', $formtemplate->config->sections->get(0)->name); @@ -41,6 +45,8 @@ class FormtemplateStoreActionTest extends FormTestCase $this->assertEquals(SpecialType::FIRSTNAME, $formtemplate->config->sections->get(0)->fields->get(1)->specialType); $this->assertEquals(['mobile' => 2, 'tablet' => 2, 'desktop' => 1], $formtemplate->config->sections->get(0)->fields->get(0)->columns->toArray()); $this->assertEquals(10, $formtemplate->config->sections->get(0)->fields->get(1)->rows); + $this->assertEquals('lala', $formtemplate->mail_top->blocks[0]['data']['text']); + $this->assertEquals('lblb', $formtemplate->mail_bottom->blocks[0]['data']['text']); $this->assertFalse($formtemplate->config->sections->get(0)->fields->get(0)->required); Event::assertDispatched(Succeeded::class, fn (Succeeded $event) => $event->message === 'Vorlage gespeichert.'); } diff --git a/tests/Feature/Form/FormtemplateUpdateActionTest.php b/tests/Feature/Form/FormtemplateUpdateActionTest.php index 8c0eb011..73c79ddb 100644 --- a/tests/Feature/Form/FormtemplateUpdateActionTest.php +++ b/tests/Feature/Form/FormtemplateUpdateActionTest.php @@ -2,10 +2,12 @@ namespace Tests\Feature\Form; +use App\Form\Models\Form; use App\Form\Models\Formtemplate; use App\Lib\Events\Succeeded; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Event; +use Tests\RequestFactories\EditorRequestFactory; use Tests\TestCase; class FormtemplateUpdateActionTest extends TestCase @@ -29,6 +31,22 @@ class FormtemplateUpdateActionTest extends TestCase Event::assertDispatched(Succeeded::class, fn (Succeeded $event) => $event->message === 'Vorlage aktualisiert.'); } + public function testItUpdatesTexts(): void + { + $this->login()->loginNami()->withoutExceptionHandling(); + $formtemplate = Formtemplate::factory()->create(); + $payload = FormtemplateRequest::new() + ->mailTop(EditorRequestFactory::new()->text(10, 'lala')) + ->mailBottom(EditorRequestFactory::new()->text(10, 'lalb')) + ->create(); + + $this->patchJson(route('formtemplate.update', ['formtemplate' => $formtemplate]), $payload) + ->assertOk(); + + $this->assertEquals('lala', Formtemplate::first()->mail_top->blocks[0]['data']['text']); + $this->assertEquals('lalb', Formtemplate::first()->mail_bottom->blocks[0]['data']['text']); + } + public function testNameIsRequired(): void { $this->login()->loginNami();