--wip-- [skip ci]
This commit is contained in:
parent
64c2cb9408
commit
80def4abde
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Form\Enums;
|
||||
|
||||
use App\Group\Enums\Level;
|
||||
use App\Member\Member;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
enum SpecialType: string
|
||||
{
|
||||
case FIRSTNAME = 'Vorname';
|
||||
case LASTNAME = 'Nachname';
|
||||
case EMAIL = 'E-Mail-Adresse';
|
||||
|
||||
/**
|
||||
* @return array<int, array{name: string, id: string}>
|
||||
*/
|
||||
public static function forSelect(): array
|
||||
{
|
||||
return collect(static::cases())
|
||||
->map(fn ($case) => ['id' => $case->value, 'name' => $case->value])
|
||||
->toArray();
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ namespace App\Form\Fields;
|
|||
|
||||
use App\Form\Data\ColumnData;
|
||||
use App\Form\Enums\NamiType;
|
||||
use App\Form\Enums\SpecialType;
|
||||
use App\Form\Models\Form;
|
||||
use App\Form\Models\Participant;
|
||||
use App\Form\Presenters\DefaultPresenter;
|
||||
|
@ -24,6 +25,7 @@ abstract class Field extends Data
|
|||
public ?NamiType $namiType = null;
|
||||
public ColumnData $columns;
|
||||
public bool $forMembers;
|
||||
public ?SpecialType $specialType = null;
|
||||
|
||||
/** @var mixed */
|
||||
public $value;
|
||||
|
@ -140,6 +142,7 @@ abstract class Field extends Data
|
|||
'required' => false,
|
||||
'nami_type' => null,
|
||||
'for_members' => true,
|
||||
'special_type' => null,
|
||||
...collect(static::meta())->mapWithKeys(fn ($meta) => [$meta['key'] => $meta['default']])->toArray(),
|
||||
],
|
||||
];
|
||||
|
|
|
@ -41,6 +41,7 @@ class FormtemplateIndexActionTest extends TestCase
|
|||
'required' => false,
|
||||
'nami_type' => null,
|
||||
'for_members' => true,
|
||||
'special_type' => null,
|
||||
'options' => [],
|
||||
]
|
||||
])
|
||||
|
@ -55,6 +56,7 @@ class FormtemplateIndexActionTest extends TestCase
|
|||
'required' => false,
|
||||
'nami_type' => null,
|
||||
'for_members' => true,
|
||||
'special_type' => null,
|
||||
]
|
||||
])
|
||||
->assertInertiaPath('data.meta.fields.8', [
|
||||
|
@ -68,6 +70,7 @@ class FormtemplateIndexActionTest extends TestCase
|
|||
'required' => false,
|
||||
'nami_type' => null,
|
||||
'for_members' => true,
|
||||
'special_type' => null,
|
||||
'rows' => 5,
|
||||
]
|
||||
])
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace Tests\Feature\Form;
|
||||
|
||||
use App\Form\Enums\SpecialType;
|
||||
use App\Form\Fields\TextareaField;
|
||||
use App\Form\Fields\TextField;
|
||||
use App\Form\Models\Form;
|
||||
use App\Form\Models\Formtemplate;
|
||||
use App\Lib\Events\Succeeded;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
@ -23,7 +23,7 @@ class FormtemplateStoreActionTest extends FormTestCase
|
|||
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),
|
||||
$this->textareaField('b')->name('lala2')->required(false)->rows(10),
|
||||
$this->textareaField('b')->name('lala2')->required(false)->specialType(SpecialType::FIRSTNAME)->rows(10),
|
||||
]),
|
||||
])->fake();
|
||||
|
||||
|
@ -32,9 +32,11 @@ class FormtemplateStoreActionTest extends FormTestCase
|
|||
$formtemplate = Formtemplate::latest()->first();
|
||||
$this->assertEquals('Persönliches', $formtemplate->config->sections->get(0)->name);
|
||||
$this->assertEquals('lala1', $formtemplate->config->sections->get(0)->fields->get(0)->name);
|
||||
$this->assertNull($formtemplate->config->sections->get(0)->fields->get(0)->specialType);
|
||||
$this->assertInstanceOf(TextField::class, $formtemplate->config->sections->get(0)->fields->get(0));
|
||||
$this->assertInstanceOf(TextareaField::class, $formtemplate->config->sections->get(0)->fields->get(1));
|
||||
$this->assertEquals(false, $formtemplate->config->sections->get(0)->fields->get(1)->required);
|
||||
$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->assertFalse($formtemplate->config->sections->get(0)->fields->get(0)->required);
|
||||
|
|
Loading…
Reference in New Issue