Add Type to FormtemplateFieldRequest
This commit is contained in:
parent
ddb44d64d6
commit
a7394e12aa
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Tests\EndToEnd\Form;
|
||||
|
||||
use App\Form\Fields\TextField;
|
||||
use App\Form\Models\Form;
|
||||
use App\Form\Models\Formtemplate;
|
||||
use Carbon\Carbon;
|
||||
|
@ -29,7 +30,7 @@ class FormApiListActionTest extends EndToEndTestCase
|
|||
->description('desc')
|
||||
->from('2023-05-05')
|
||||
->to('2023-06-07')
|
||||
->sections([FormtemplateSectionRequest::new()->name('sname')->fields([FormtemplateFieldRequest::new()])])
|
||||
->sections([FormtemplateSectionRequest::new()->name('sname')->fields([FormtemplateFieldRequest::type(TextField::class)])])
|
||||
->create();
|
||||
|
||||
sleep(1);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Tests\EndToEnd\Form;
|
||||
|
||||
use App\Form\Fields\TextField;
|
||||
use App\Form\Models\Form;
|
||||
use App\Form\Models\Formtemplate;
|
||||
use Carbon\Carbon;
|
||||
|
@ -27,7 +28,7 @@ class FormIndexActionTest extends EndToEndTestCase
|
|||
->mailBottom('Cheers')
|
||||
->registrationFrom('2023-05-06 04:00:00')
|
||||
->registrationUntil('2023-04-01 05:00:00')
|
||||
->sections([FormtemplateSectionRequest::new()->name('sname')->fields([FormtemplateFieldRequest::new()])])
|
||||
->sections([FormtemplateSectionRequest::new()->name('sname')->fields([FormtemplateFieldRequest::type(TextField::class)])])
|
||||
->create();
|
||||
|
||||
sleep(1);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Tests\Feature\Form;
|
||||
|
||||
use App\Form\Fields\TextField;
|
||||
use App\Form\Models\Form;
|
||||
use App\Lib\Events\Succeeded;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
@ -36,7 +37,7 @@ class FormStoreActionTest extends TestCase
|
|||
->mailTop('Guten Tag')
|
||||
->mailBottom('Viele Grüße')
|
||||
->headerImage('htzz.jpg')
|
||||
->sections([FormtemplateSectionRequest::new()->name('sname')->fields([FormtemplateFieldRequest::new()])])
|
||||
->sections([FormtemplateSectionRequest::new()->name('sname')->fields([FormtemplateFieldRequest::type(TextField::class)])])
|
||||
->fake();
|
||||
|
||||
$this->postJson(route('form.store'))->assertOk();
|
||||
|
|
|
@ -26,7 +26,7 @@ class FormUpdateActionTest extends TestCase
|
|||
$form = Form::factory()->create();
|
||||
$payload = FormRequest::new()->sections([
|
||||
FormtemplateSectionRequest::new()->fields([
|
||||
FormtemplateFieldRequest::new()->type(DateField::class)->state(['max_today' => true]),
|
||||
FormtemplateFieldRequest::type(DateField::class)->state(['max_today' => true]),
|
||||
])
|
||||
])->create();
|
||||
|
||||
|
|
|
@ -7,10 +7,8 @@ use Worksome\RequestFactories\RequestFactory;
|
|||
|
||||
/**
|
||||
* @method self name(string $name)
|
||||
* @method self type(string $type)
|
||||
* @method self key(string $key)
|
||||
* @method self required(string|bool $key)
|
||||
* @method self type(string $type)
|
||||
* @method self rows(int $rows)
|
||||
* @method self columns(array{mobile: int, tablet: int, desktop: int} $rows)
|
||||
* @method self default(mixed $default)
|
||||
|
@ -22,29 +20,27 @@ class FormtemplateFieldRequest extends RequestFactory
|
|||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$type = $this->faker->randomElement(array_column(Field::asMeta(), 'id'));
|
||||
return [
|
||||
'name' => $this->faker->words(5, true),
|
||||
'key' => str($this->faker->words(5, true))->snake()->toString(),
|
||||
'type' => $type,
|
||||
'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6],
|
||||
'default' => '',
|
||||
...Field::classFromType($type)::fake($this->faker),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|class-string<Field> $field
|
||||
*/
|
||||
public function type(string $field): self
|
||||
public static function type(string $field): self
|
||||
{
|
||||
|
||||
if (!$field || !class_exists($field)) {
|
||||
return $this->state(['type' => $field]);
|
||||
return self::new(['type' => $field]);
|
||||
}
|
||||
|
||||
return $this->state([
|
||||
return self::new([
|
||||
'type' => $field::type(),
|
||||
...$field::fake($this->faker),
|
||||
...$field::fake((new static())->faker),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ class FormtemplateStoreActionTest extends TestCase
|
|||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
FormtemplateRequest::new()->name('testname')->sections([
|
||||
FormtemplateSectionRequest::new()->name('Persönliches')->fields([
|
||||
FormtemplateFieldRequest::new()->type(TextField::class)->name('lala1')->columns(['mobile' => 2, 'tablet' => 2, 'desktop' => 1])->required(false)->default('zuzu'),
|
||||
FormtemplateFieldRequest::new()->type(TextareaField::class)->name('lala2')->required(false)->rows(10),
|
||||
FormtemplateFieldRequest::type(TextField::class)->name('lala1')->columns(['mobile' => 2, 'tablet' => 2, 'desktop' => 1])->required(false)->default('zuzu'),
|
||||
FormtemplateFieldRequest::type(TextareaField::class)->name('lala2')->required(false)->rows(10),
|
||||
]),
|
||||
])->fake();
|
||||
|
||||
|
@ -47,22 +47,22 @@ class FormtemplateStoreActionTest extends TestCase
|
|||
yield [FormtemplateRequest::new()->name(''), ['name' => 'Name ist erforderlich.']];
|
||||
yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->name('')]), ['config.sections.0.name' => 'Sektionsname ist erforderlich.']];
|
||||
yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->fields([
|
||||
FormtemplateFieldRequest::new()->name(''),
|
||||
FormtemplateFieldRequest::type(TextField::class)->name(''),
|
||||
])]), ['config.sections.0.fields.0.name' => 'Feldname ist erforderlich.']];
|
||||
yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->fields([
|
||||
FormtemplateFieldRequest::new()->type(''),
|
||||
FormtemplateFieldRequest::type('')
|
||||
])]), ['config.sections.0.fields.0.type' => 'Feldtyp ist erforderlich.']];
|
||||
yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->fields([
|
||||
FormtemplateFieldRequest::new()->type('aaaaa'),
|
||||
FormtemplateFieldRequest::type('aaaaa'),
|
||||
])]), ['config.sections.0.fields.0.type' => 'Feldtyp ist ungültig.']];
|
||||
yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->fields([
|
||||
FormtemplateFieldRequest::new()->key(''),
|
||||
FormtemplateFieldRequest::type(TextField::class)->key(''),
|
||||
])]), ['config.sections.0.fields.0.key' => 'Feldkey ist erforderlich.']];
|
||||
yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->fields([
|
||||
FormtemplateFieldRequest::new()->key('a b'),
|
||||
FormtemplateFieldRequest::type(TextField::class)->key('a b'),
|
||||
])]), ['config.sections.0.fields.0.key' => 'Feldkey Format ist ungültig.']];
|
||||
yield [FormtemplateRequest::new()->sections([FormtemplateSectionRequest::new()->fields([
|
||||
FormtemplateFieldRequest::new()->type(TextField::class)->required('la')
|
||||
FormtemplateFieldRequest::type(TextField::class)->required('la')
|
||||
])]), ['config.sections.0.fields.0.required' => 'Erforderlich muss ein Wahrheitswert sein.']];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue