Add trait for creating form fields
This commit is contained in:
parent
2a5c203cc0
commit
5919082211
|
@ -2,16 +2,13 @@
|
|||
|
||||
namespace Tests\EndToEnd\Form;
|
||||
|
||||
use App\Form\Fields\TextField;
|
||||
use App\Form\Models\Form;
|
||||
use App\Form\Models\Formtemplate;
|
||||
use App\Form\Models\Participant;
|
||||
use Carbon\Carbon;
|
||||
use Tests\EndToEndTestCase;
|
||||
use Tests\Feature\Form\FormtemplateFieldRequest;
|
||||
use Tests\Feature\Form\FormtemplateSectionRequest;
|
||||
|
||||
class FormIndexActionTest extends EndToEndTestCase
|
||||
class FormIndexActionTest extends FormTestCase
|
||||
{
|
||||
|
||||
public function testItDisplaysForms(): void
|
||||
|
@ -29,7 +26,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::type(TextField::class)])])
|
||||
->sections([FormtemplateSectionRequest::new()->name('sname')->fields([$this->textField()])])
|
||||
->has(Participant::factory()->count(5))
|
||||
->create();
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\EndToEnd\Form;
|
||||
|
||||
use Tests\EndToEndTestCase;
|
||||
use Tests\Lib\CreatesFormFields;
|
||||
|
||||
abstract class FormTestCase extends EndToEndTestCase
|
||||
{
|
||||
use CreatesFormFields;
|
||||
}
|
|
@ -3,66 +3,9 @@
|
|||
namespace Tests\Feature\Form;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Form\Fields\CheckboxesField;
|
||||
use App\Form\Fields\CheckboxField;
|
||||
use App\Form\Fields\DateField;
|
||||
use App\Form\Fields\DropdownField;
|
||||
use App\Form\Fields\GroupField;
|
||||
use App\Form\Fields\NamiField;
|
||||
use App\Form\Fields\RadioField;
|
||||
use App\Form\Fields\TextareaField;
|
||||
use App\Form\Fields\TextField;
|
||||
use Faker\Generator;
|
||||
use Tests\Lib\CreatesFormFields;
|
||||
|
||||
class FormTestCase extends TestCase
|
||||
{
|
||||
protected function namiField(?string $key = null): FormtemplateFieldRequest
|
||||
{
|
||||
return FormtemplateFieldRequest::type(NamiField::class)->key($key ?? $this->randomKey());
|
||||
}
|
||||
|
||||
protected function textField(?string $key = null): FormtemplateFieldRequest
|
||||
{
|
||||
return FormtemplateFieldRequest::type(TextField::class)->key($key ?? $this->randomKey());
|
||||
}
|
||||
|
||||
protected function checkboxesField(?string $key = null): FormtemplateFieldRequest
|
||||
{
|
||||
return FormtemplateFieldRequest::type(CheckboxesField::class)->key($key ?? $this->randomKey());
|
||||
}
|
||||
|
||||
protected function textareaField(?string $key = null): FormtemplateFieldRequest
|
||||
{
|
||||
return FormtemplateFieldRequest::type(TextareaField::class)->key($key ?? $this->randomKey());
|
||||
}
|
||||
|
||||
protected function dropdownField(?string $key = null): FormtemplateFieldRequest
|
||||
{
|
||||
return FormtemplateFieldRequest::type(DropdownField::class)->key($key ?? $this->randomKey());
|
||||
}
|
||||
|
||||
protected function dateField(?string $key = null): FormtemplateFieldRequest
|
||||
{
|
||||
return FormtemplateFieldRequest::type(DateField::class)->key($key ?? $this->randomKey());
|
||||
}
|
||||
|
||||
protected function radioField(?string $key = null): FormtemplateFieldRequest
|
||||
{
|
||||
return FormtemplateFieldRequest::type(RadioField::class)->key($key ?? $this->randomKey());
|
||||
}
|
||||
|
||||
protected function checkboxField(?string $key = null): FormtemplateFieldRequest
|
||||
{
|
||||
return FormtemplateFieldRequest::type(CheckboxField::class)->key($key ?? $this->randomKey());
|
||||
}
|
||||
|
||||
protected function groupField(?string $key = null): FormtemplateFieldRequest
|
||||
{
|
||||
return FormtemplateFieldRequest::type(GroupField::class)->key($key ?? $this->randomKey());
|
||||
}
|
||||
|
||||
protected function randomKey(): string
|
||||
{
|
||||
return preg_replace('/[\-0-9]/', '', str()->uuid().str()->uuid());
|
||||
}
|
||||
use CreatesFormFields;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Lib;
|
||||
|
||||
use App\Form\Fields\CheckboxesField;
|
||||
use App\Form\Fields\CheckboxField;
|
||||
use App\Form\Fields\DateField;
|
||||
use App\Form\Fields\DropdownField;
|
||||
use App\Form\Fields\GroupField;
|
||||
use App\Form\Fields\NamiField;
|
||||
use App\Form\Fields\RadioField;
|
||||
use App\Form\Fields\TextareaField;
|
||||
use App\Form\Fields\TextField;
|
||||
use Faker\Generator;
|
||||
use Tests\Feature\Form\FormtemplateFieldRequest;
|
||||
|
||||
trait CreatesFormFields
|
||||
{
|
||||
protected function namiField(?string $key = null): FormtemplateFieldRequest
|
||||
{
|
||||
return FormtemplateFieldRequest::type(NamiField::class)->key($key ?? $this->randomKey());
|
||||
}
|
||||
|
||||
protected function textField(?string $key = null): FormtemplateFieldRequest
|
||||
{
|
||||
return FormtemplateFieldRequest::type(TextField::class)->key($key ?? $this->randomKey());
|
||||
}
|
||||
|
||||
protected function checkboxesField(?string $key = null): FormtemplateFieldRequest
|
||||
{
|
||||
return FormtemplateFieldRequest::type(CheckboxesField::class)->key($key ?? $this->randomKey());
|
||||
}
|
||||
|
||||
protected function textareaField(?string $key = null): FormtemplateFieldRequest
|
||||
{
|
||||
return FormtemplateFieldRequest::type(TextareaField::class)->key($key ?? $this->randomKey());
|
||||
}
|
||||
|
||||
protected function dropdownField(?string $key = null): FormtemplateFieldRequest
|
||||
{
|
||||
return FormtemplateFieldRequest::type(DropdownField::class)->key($key ?? $this->randomKey());
|
||||
}
|
||||
|
||||
protected function dateField(?string $key = null): FormtemplateFieldRequest
|
||||
{
|
||||
return FormtemplateFieldRequest::type(DateField::class)->key($key ?? $this->randomKey());
|
||||
}
|
||||
|
||||
protected function radioField(?string $key = null): FormtemplateFieldRequest
|
||||
{
|
||||
return FormtemplateFieldRequest::type(RadioField::class)->key($key ?? $this->randomKey());
|
||||
}
|
||||
|
||||
protected function checkboxField(?string $key = null): FormtemplateFieldRequest
|
||||
{
|
||||
return FormtemplateFieldRequest::type(CheckboxField::class)->key($key ?? $this->randomKey());
|
||||
}
|
||||
|
||||
protected function groupField(?string $key = null): FormtemplateFieldRequest
|
||||
{
|
||||
return FormtemplateFieldRequest::type(GroupField::class)->key($key ?? $this->randomKey());
|
||||
}
|
||||
|
||||
protected function randomKey(): string
|
||||
{
|
||||
return preg_replace('/[\-0-9]/', '', str()->uuid().str()->uuid());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue