Add EditorData for forms texts
continuous-integration/drone/push Build is failing Details

This commit is contained in:
philipp lang 2024-07-14 19:29:42 +02:00
parent 1ef7995ec2
commit c3f6d3827b
8 changed files with 89 additions and 53 deletions

View File

@ -32,9 +32,9 @@ class Form extends Model implements HasMedia
public $casts = [
'config' => FormConfigData::class,
'meta' => 'json',
'description' => 'json',
'mail_top' => 'json',
'mail_bottom' => 'json',
'description' => EditorData::class,
'mail_top' => EditorData::class,
'mail_bottom' => EditorData::class,
'is_active' => 'boolean',
'is_private' => 'boolean',
'export' => ExportData::class,

View File

@ -11,9 +11,9 @@ abstract class ConditionResolver
* @param array<string, mixed> $content
* @return array<string, mixed>
*/
public function makeBlocks(array $content): array
public function makeBlocks(EditorData $data): array
{
return array_filter(data_get($content, 'blocks', []), fn ($block) => $this->filterBlock($block));
return array_filter($data->blocks, fn ($block) => $this->filterBlock($block));
}
/**

View File

@ -43,15 +43,15 @@ class FormFactory extends Factory
{
return [
'name' => $this->faker->words(4, true),
'description' => EditorRequestFactory::new()->create(),
'description' => EditorRequestFactory::new()->toData(),
'excerpt' => $this->faker->words(10, true),
'config' => ['sections' => []],
'from' => $this->faker->dateTimeBetween('+1 week', '+4 weeks')->format('Y-m-d H:i:s'),
'to' => $this->faker->dateTimeBetween('+1 week', '+4 weeks')->format('Y-m-d H:i:s'),
'registration_from' => $this->faker->dateTimeBetween('-2 weeks', 'now')->format('Y-m-d H:i:s'),
'registration_until' => $this->faker->dateTimeBetween('now', '+2 weeks')->format('Y-m-d H:i:s'),
'mail_top' => EditorRequestFactory::new()->create(),
'mail_bottom' => EditorRequestFactory::new()->create(),
'mail_top' => EditorRequestFactory::new()->toData(),
'mail_bottom' => EditorRequestFactory::new()->toData(),
'is_active' => true,
'is_private' => false,
'export' => ExportData::from([]),
@ -85,16 +85,16 @@ class FormFactory extends Factory
public function mailTop(EditorRequestFactory $factory): self
{
return $this->state(['mail_top' => $factory->create()]);
return $this->state(['mail_top' => $factory->toData()]);
}
public function mailBottom(EditorRequestFactory $factory): self
{
return $this->state(['mail_bottom' => $factory->create()]);
return $this->state(['mail_bottom' => $factory->toData()]);
}
public function description(EditorRequestFactory $factory): self
{
return $this->state(['description' => $factory->create()]);
return $this->state(['description' => $factory->toData()]);
}
}

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('forms', function (Blueprint $table) {
$table->json('description')->after('name')->default(json_encode(['time' => 4, 'blocks' => [], 'version' => '1.0']))->change();
$table->json('mail_top')->after('name')->default(json_encode(['time' => 4, 'blocks' => [], 'version' => '1.0']))->change();
$table->json('mail_bottom')->after('name')->default(json_encode(['time' => 4, 'blocks' => [], 'version' => '1.0']))->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('formtemplates', function (Blueprint $table) {
$table->dropColumn('mail_top');
$table->dropColumn('mail_bottom');
});
}
};

View File

@ -241,24 +241,6 @@ class FormRegisterMailTest extends FormTestCase
}
}
public function testItSendsEmailWhenMailTopIsEmpty(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$participant = Participant::factory()->for(
Form::factory()
->fields([
$this->textField('firstname')->specialType(SpecialType::FIRSTNAME),
$this->textField('lastname')->specialType(SpecialType::LASTNAME),
])->state(['mail_top' => []])
)
->data(['firstname' => 'Max', 'lastname' => 'Muster'])
->create();
$mail = new ConfirmRegistrationMail($participant);
$mail->assertSeeInText('Max');
}
/**
* @dataProvider blockDataProvider
* @param array<string, mixed> $conditions

View File

@ -73,6 +73,14 @@ class FormRequest extends RequestFactory
return $this->state([str($method)->snake()->toString() => $args[0]]);
}
/**
* @param array<int, FormtemplateFieldRequest> $fields
*/
public function fields(array $fields): self
{
return $this->sections([FormtemplateSectionRequest::new()->fields($fields)]);
}
public function headerImage(string $fileName): self
{
UploadedFile::fake()->image($fileName, 1000, 1000)->storeAs('media-library', $fileName, 'temp');

View File

@ -41,9 +41,9 @@ class FormStoreActionTest extends FormTestCase
$this->assertEquals('formname', $form->name);
$this->assertEquals('lorem ipsum', $form->prevention_text->blocks[0]['data']['text']);
$this->assertEquals('avff', $form->excerpt);
$this->assertEquals($description->paragraphBlock(10, 'Lorem'), $form->description);
$this->assertEquals(json_decode('{"time":1,"blocks":[{"id":11,"type":"paragraph","data":{"text":"lala"},"tunes":{"condition":{"mode":"all","ifs":[]}}}],"version":"1.0"}', true), $form->mail_top);
$this->assertEquals(json_decode('{"time":1,"blocks":[{"id":12,"type":"paragraph","data":{"text":"lalab"},"tunes":{"condition":{"mode":"all","ifs":[]}}}],"version":"1.0"}', true), $form->mail_bottom);
$this->assertEquals('Lorem', $form->description->blocks[0]['data']['text']);
$this->assertEquals('lala', $form->mail_top->blocks[0]['data']['text']);
$this->assertEquals('lalab', $form->mail_bottom->blocks[0]['data']['text']);
$this->assertEquals('2023-05-04 01:00', $form->registration_from->format('Y-m-d H:i'));
$this->assertEquals(true, $form->is_active);
$this->assertEquals('2023-07-07 01:00', $form->registration_until->format('Y-m-d H:i'));

View File

@ -19,10 +19,8 @@ class FormUpdateActionTest extends FormTestCase
{
$this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory()->create();
$payload = FormRequest::new()->sections([
FormtemplateSectionRequest::new()->fields([
$this->dateField()->state(['max_today' => true]),
])
$payload = FormRequest::new()->fields([
$this->dateField()->state(['max_today' => true]),
])->create();
$this->patchJson(route('form.update', ['form' => $form]), $payload)
@ -33,6 +31,24 @@ class FormUpdateActionTest extends FormTestCase
$this->assertTrue($form->config->sections->get(0)->fields->get(0)->maxToday);
}
public function testItSetsTexts(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory()->create();
$payload = FormRequest::new()->fields([])
->mailTop(EditorRequestFactory::new()->text(11, 'lala'))
->mailBottom(EditorRequestFactory::new()->text(12, 'lalab'))
->description(EditorRequestFactory::new()->text(12, 'desc'))
->create();
$this->patchJson(route('form.update', ['form' => $form]), $payload)
->assertOk();
$this->assertEquals('lala', $form->fresh()->mail_top->blocks[0]['data']['text']);
$this->assertEquals('lalab', $form->fresh()->mail_bottom->blocks[0]['data']['text']);
$this->assertEquals('desc', $form->fresh()->description->blocks[0]['data']['text']);
}
public function testItClearsFrontendCacheWhenFormUpdated(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
@ -56,17 +72,14 @@ class FormUpdateActionTest extends FormTestCase
public function testItUpdatesActiveColumnsWhenFieldRemoved(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory()
->sections([FormtemplateSectionRequest::new()->fields([
$this->textField('firstname'),
$this->textField('geb'),
$this->textField('lastname'),
])])
$form = Form::factory()->fields([
$this->textField('firstname'),
$this->textField('geb'),
$this->textField('lastname'),
])
->create();
$payload = FormRequest::new()->sections([
FormtemplateSectionRequest::new()->fields([
$this->textField('firstname'),
])
$payload = FormRequest::new()->fields([
$this->textField('firstname'),
])->create();
$this->patchJson(route('form.update', ['form' => $form]), $payload)->assertSessionDoesntHaveErrors()->assertOk();
@ -113,14 +126,12 @@ class FormUpdateActionTest extends FormTestCase
{
$this->login()->loginNami()->withoutExceptionHandling();
$form = Form::factory()
->sections([FormtemplateSectionRequest::new()->fields([])])
->fields([])
->create();
$payload = FormRequest::new()->sections([
FormtemplateSectionRequest::new()->fields([
$this->textField('firstname'),
$this->textField('geb'),
$this->textField('lastname'),
])
$payload = FormRequest::new()->fields([
$this->textField('firstname'),
$this->textField('geb'),
$this->textField('lastname'),
])->create();
$this->patchJson(route('form.update', ['form' => $form]), $payload)->assertSessionDoesntHaveErrors()->assertOk();