Add value for field

This commit is contained in:
philipp lang 2024-03-13 15:48:08 +01:00
parent 78d6c6d864
commit 64c2cb9408
5 changed files with 23 additions and 9 deletions

View File

@ -25,6 +25,9 @@ abstract class Field extends Data
public ColumnData $columns; public ColumnData $columns;
public bool $forMembers; public bool $forMembers;
/** @var mixed */
public $value;
/** /**
* @param array<array-key, mixed> $input * @param array<array-key, mixed> $input
*/ */
@ -133,7 +136,7 @@ abstract class Field extends Data
'name' => '', 'name' => '',
'type' => static::type(), 'type' => static::type(),
'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6], 'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6],
'default' => static::default(), 'value' => static::default(),
'required' => false, 'required' => false,
'nami_type' => null, 'nami_type' => null,
'for_members' => true, 'for_members' => true,

View File

@ -42,8 +42,8 @@ class FormFactory extends Factory
'description' => $this->faker->text(), 'description' => $this->faker->text(),
'excerpt' => $this->faker->words(10, true), 'excerpt' => $this->faker->words(10, true),
'config' => ['sections' => []], 'config' => ['sections' => []],
'from' => $this->faker->dateTime()->format('Y-m-d H:i:s'), 'from' => $this->faker->dateTimeBetween('+1 week', '+4 weeks')->format('Y-m-d H:i:s'),
'to' => $this->faker->dateTime()->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_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'), 'registration_until' => $this->faker->dateTimeBetween('now', '+2 weeks')->format('Y-m-d H:i:s'),
'mail_top' => $this->faker->text(), 'mail_top' => $this->faker->text(),

View File

@ -3,7 +3,6 @@
namespace Tests\EndToEnd\Form; namespace Tests\EndToEnd\Form;
use App\Form\Models\Form; use App\Form\Models\Form;
use App\Form\Models\Formtemplate;
use App\Subactivity; use App\Subactivity;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
@ -11,7 +10,7 @@ use Illuminate\Support\Facades\Storage;
use Tests\EndToEndTestCase; use Tests\EndToEndTestCase;
use Tests\Feature\Form\FormtemplateSectionRequest; use Tests\Feature\Form\FormtemplateSectionRequest;
class FormApiListActionTest extends EndToEndTestCase class FormApiListActionTest extends FormTestCase
{ {
use DatabaseTransactions; use DatabaseTransactions;
@ -21,7 +20,6 @@ class FormApiListActionTest extends EndToEndTestCase
Carbon::setTestNow(Carbon::parse('2023-03-02')); Carbon::setTestNow(Carbon::parse('2023-03-02'));
Storage::fake('temp'); Storage::fake('temp');
$this->loginNami()->withoutExceptionHandling(); $this->loginNami()->withoutExceptionHandling();
Formtemplate::factory()->name('tname')->sections([FormtemplateSectionRequest::new()->name('sname')])->create();
$form = Form::factory() $form = Form::factory()
->name('lala 2') ->name('lala 2')
->excerpt('fff') ->excerpt('fff')
@ -50,6 +48,18 @@ class FormApiListActionTest extends EndToEndTestCase
->assertJsonPath('meta.total', 1); ->assertJsonPath('meta.total', 1);
} }
public function testItDisplaysDefaultValueOfField(): void
{
Storage::fake('temp');
$this->loginNami()->withoutExceptionHandling();
Form::factory()->withImage('headerImage', 'lala-2.jpg')
->sections([FormtemplateSectionRequest::new()->fields([$this->textField()])])
->create();
sleep(1);
$this->get('/api/form?perPage=15')->assertJsonPath('data.0.config.sections.0.fields.0.value', '');
}
public function testItDisplaysRemoteGroups(): void public function testItDisplaysRemoteGroups(): void
{ {
$this->loginNami()->withoutExceptionHandling(); $this->loginNami()->withoutExceptionHandling();

View File

@ -48,6 +48,7 @@ class FormtemplateFieldRequest extends RequestFactory
return self::new([ return self::new([
'type' => $field::type(), 'type' => $field::type(),
'value' => $field::default(),
...$field::fake((new static())->faker), ...$field::fake((new static())->faker),
]); ]);
} }

View File

@ -37,7 +37,7 @@ class FormtemplateIndexActionTest extends TestCase
'name' => '', 'name' => '',
'type' => 'DropdownField', 'type' => 'DropdownField',
'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6], 'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6],
'default' => null, 'value' => null,
'required' => false, 'required' => false,
'nami_type' => null, 'nami_type' => null,
'for_members' => true, 'for_members' => true,
@ -51,7 +51,7 @@ class FormtemplateIndexActionTest extends TestCase
'name' => '', 'name' => '',
'type' => 'TextField', 'type' => 'TextField',
'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6], 'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6],
'default' => '', 'value' => '',
'required' => false, 'required' => false,
'nami_type' => null, 'nami_type' => null,
'for_members' => true, 'for_members' => true,
@ -64,7 +64,7 @@ class FormtemplateIndexActionTest extends TestCase
'name' => '', 'name' => '',
'type' => 'TextareaField', 'type' => 'TextareaField',
'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6], 'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6],
'default' => '', 'value' => '',
'required' => false, 'required' => false,
'nami_type' => null, 'nami_type' => null,
'for_members' => true, 'for_members' => true,