diff --git a/app/Form/Fields/Field.php b/app/Form/Fields/Field.php index e72369ce..9bc2075f 100644 --- a/app/Form/Fields/Field.php +++ b/app/Form/Fields/Field.php @@ -25,6 +25,9 @@ abstract class Field extends Data public ColumnData $columns; public bool $forMembers; + /** @var mixed */ + public $value; + /** * @param array $input */ @@ -133,7 +136,7 @@ abstract class Field extends Data 'name' => '', 'type' => static::type(), 'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6], - 'default' => static::default(), + 'value' => static::default(), 'required' => false, 'nami_type' => null, 'for_members' => true, diff --git a/database/factories/Form/Models/FormFactory.php b/database/factories/Form/Models/FormFactory.php index 10312b86..68720d1a 100644 --- a/database/factories/Form/Models/FormFactory.php +++ b/database/factories/Form/Models/FormFactory.php @@ -42,8 +42,8 @@ class FormFactory extends Factory 'description' => $this->faker->text(), 'excerpt' => $this->faker->words(10, true), 'config' => ['sections' => []], - 'from' => $this->faker->dateTime()->format('Y-m-d H:i:s'), - 'to' => $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->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' => $this->faker->text(), diff --git a/tests/EndToEnd/Form/FormApiListActionTest.php b/tests/EndToEnd/Form/FormApiListActionTest.php index 7f3079a6..7612aabb 100644 --- a/tests/EndToEnd/Form/FormApiListActionTest.php +++ b/tests/EndToEnd/Form/FormApiListActionTest.php @@ -3,7 +3,6 @@ namespace Tests\EndToEnd\Form; use App\Form\Models\Form; -use App\Form\Models\Formtemplate; use App\Subactivity; use Carbon\Carbon; use Illuminate\Foundation\Testing\DatabaseTransactions; @@ -11,7 +10,7 @@ use Illuminate\Support\Facades\Storage; use Tests\EndToEndTestCase; use Tests\Feature\Form\FormtemplateSectionRequest; -class FormApiListActionTest extends EndToEndTestCase +class FormApiListActionTest extends FormTestCase { use DatabaseTransactions; @@ -21,7 +20,6 @@ class FormApiListActionTest extends EndToEndTestCase Carbon::setTestNow(Carbon::parse('2023-03-02')); Storage::fake('temp'); $this->loginNami()->withoutExceptionHandling(); - Formtemplate::factory()->name('tname')->sections([FormtemplateSectionRequest::new()->name('sname')])->create(); $form = Form::factory() ->name('lala 2') ->excerpt('fff') @@ -50,6 +48,18 @@ class FormApiListActionTest extends EndToEndTestCase ->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 { $this->loginNami()->withoutExceptionHandling(); diff --git a/tests/Feature/Form/FormtemplateFieldRequest.php b/tests/Feature/Form/FormtemplateFieldRequest.php index bf5645e2..61244046 100644 --- a/tests/Feature/Form/FormtemplateFieldRequest.php +++ b/tests/Feature/Form/FormtemplateFieldRequest.php @@ -48,6 +48,7 @@ class FormtemplateFieldRequest extends RequestFactory return self::new([ 'type' => $field::type(), + 'value' => $field::default(), ...$field::fake((new static())->faker), ]); } diff --git a/tests/Feature/Form/FormtemplateIndexActionTest.php b/tests/Feature/Form/FormtemplateIndexActionTest.php index f35ee9e0..0bff49ef 100644 --- a/tests/Feature/Form/FormtemplateIndexActionTest.php +++ b/tests/Feature/Form/FormtemplateIndexActionTest.php @@ -37,7 +37,7 @@ class FormtemplateIndexActionTest extends TestCase 'name' => '', 'type' => 'DropdownField', 'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6], - 'default' => null, + 'value' => null, 'required' => false, 'nami_type' => null, 'for_members' => true, @@ -51,7 +51,7 @@ class FormtemplateIndexActionTest extends TestCase 'name' => '', 'type' => 'TextField', 'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6], - 'default' => '', + 'value' => '', 'required' => false, 'nami_type' => null, 'for_members' => true, @@ -64,7 +64,7 @@ class FormtemplateIndexActionTest extends TestCase 'name' => '', 'type' => 'TextareaField', 'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6], - 'default' => '', + 'value' => '', 'required' => false, 'nami_type' => null, 'for_members' => true,