diff --git a/app/Form/Actions/HasValidation.php b/app/Form/Actions/HasValidation.php index eda62525..92b59613 100644 --- a/app/Form/Actions/HasValidation.php +++ b/app/Form/Actions/HasValidation.php @@ -24,6 +24,7 @@ trait HasValidation 'config.sections.*.fields.*.key' => ['required', 'string', 'regex:/^[a-zA-Z_]*$/'], 'config.sections.*.fields.*.default' => 'present', 'config.sections.*.fields.*.columns' => 'required|array', + 'config.sections.*.fields.*.*' => '', 'config.sections.*.fields.*.columns.mobile' => 'required|numeric|gt:0|lte:2', 'config.sections.*.fields.*.columns.tablet' => 'required|numeric|gt:0|lte:4', 'config.sections.*.fields.*.columns.desktop' => 'required|numeric|gt:0|lte:6', diff --git a/app/Form/Fields/DateField.php b/app/Form/Fields/DateField.php index 37c8d92d..358af877 100644 --- a/app/Form/Fields/DateField.php +++ b/app/Form/Fields/DateField.php @@ -19,9 +19,9 @@ class DateField extends Field ]; } - public static function default(): string + public static function default(): ?string { - return ''; + return null; } public static function fake(Generator $faker): array diff --git a/tests/EndToEnd/Form/FormApiListActionTest.php b/tests/EndToEnd/Form/FormApiListActionTest.php index 46f16ac2..5f38d6a8 100644 --- a/tests/EndToEnd/Form/FormApiListActionTest.php +++ b/tests/EndToEnd/Form/FormApiListActionTest.php @@ -1,6 +1,6 @@ login()->loginNami()->withoutExceptionHandling(); Formtemplate::factory()->name('tname')->sections([FormtemplateSectionRequest::new()->name('sname')])->create(); $form = Form::factory() @@ -29,10 +30,11 @@ class FormIndexActionTest extends TestCase ->sections([FormtemplateSectionRequest::new()->name('sname')->fields([FormtemplateFieldRequest::new()])]) ->create(); + sleep(1); $this->get(route('form.index')) ->assertOk() - ->assertInertiaPath('data.data.0.config.sections.0.name', 'sname') ->assertInertiaPath('data.data.0.name', 'lala') + ->assertInertiaPath('data.data.0.config.sections.0.name', 'sname') ->assertInertiaPath('data.data.0.id', $form->id) ->assertInertiaPath('data.data.0.excerpt', 'fff') ->assertInertiaPath('data.data.0.description', 'desc') @@ -49,10 +51,51 @@ class FormIndexActionTest extends TestCase ->assertInertiaPath('data.meta.templates.0.name', 'tname') ->assertInertiaPath('data.meta.templates.0.config.sections.0.name', 'sname') ->assertInertiaPath('data.meta.default.name', '') - ->assertInertiaPath('data.meta.default.description', '') + ->assertInertiaPath('data.meta.default.description', []) ->assertInertiaPath('data.meta.default.excerpt', '') ->assertInertiaPath('data.meta.default.config', null) ->assertInertiaPath('data.meta.base_url', url('')) ->assertInertiaPath('data.meta.section_default.name', ''); } + + public function testItHandlesFullTextSearch() + { + $this->withoutExceptionHandling()->login()->loginNami(); + Form::factory()->to(now()->addYear())->name('ZEM 2024')->create(); + Form::factory()->to(now()->addYear())->name('Rover-Spek 2025')->create(); + + sleep(1); + $this->callFilter('form.index', ['search' => 'ZEM']) + ->assertInertiaCount('data.data', 1); + $this->callFilter('form.index', []) + ->assertInertiaCount('data.data', 2); + } + + public function testItOrdersByStartDateDesc() + { + $this->withoutExceptionHandling()->login()->loginNami(); + $form1 = Form::factory()->from(now()->addDays(4))->to(now()->addYear())->create(); + $form2 = Form::factory()->from(now()->addDays(3))->to(now()->addYear())->create(); + $form3 = Form::factory()->from(now()->addDays(2))->to(now()->addYear())->create(); + + sleep(1); + $this->callFilter('form.index', []) + ->assertInertiaPath('data.data.0.id', $form3->id) + ->assertInertiaPath('data.data.1.id', $form2->id) + ->assertInertiaPath('data.data.2.id', $form1->id); + } + + public function testItShowsPastEvents() + { + $this->withoutExceptionHandling()->login()->loginNami(); + Form::factory()->count(5)->to(now()->subDays(2))->create(); + Form::factory()->count(3)->to(now()->subDays(5))->create(); + Form::factory()->count(2)->to(now()->addDays(3))->create(); + + sleep(1); + $this->callFilter('form.index', ['past' => true]) + ->assertInertiaCount('data.data', 10); + $this->callFilter('form.index', []) + ->assertInertiaCount('data.data', 2); + } } diff --git a/tests/EndToEnd/Form/FormIndexTest.php b/tests/EndToEnd/Form/FormIndexTest.php deleted file mode 100644 index 3bd84329..00000000 --- a/tests/EndToEnd/Form/FormIndexTest.php +++ /dev/null @@ -1,50 +0,0 @@ -withoutExceptionHandling()->login()->loginNami(); - Form::factory()->to(now()->addYear())->name('ZEM 2024')->create(); - Form::factory()->to(now()->addYear())->name('Rover-Spek 2025')->create(); - - sleep(1); - $this->callFilter('form.index', ['search' => 'ZEM']) - ->assertInertiaCount('data.data', 1); - $this->callFilter('form.index', []) - ->assertInertiaCount('data.data', 2); - } - - public function testItOrdersByStartDateDesc() - { - $this->withoutExceptionHandling()->login()->loginNami(); - $form1 = Form::factory()->from(now()->addDays(4))->to(now()->addYear())->create(); - $form2 = Form::factory()->from(now()->addDays(3))->to(now()->addYear())->create(); - $form3 = Form::factory()->from(now()->addDays(2))->to(now()->addYear())->create(); - - sleep(1); - $this->callFilter('form.index', []) - ->assertInertiaPath('data.data.0.id', $form3->id) - ->assertInertiaPath('data.data.1.id', $form2->id) - ->assertInertiaPath('data.data.2.id', $form1->id); - } - - public function testItShowsPastEvents() - { - $this->withoutExceptionHandling()->login()->loginNami(); - Form::factory()->count(5)->to(now()->subDays(2))->create(); - Form::factory()->count(3)->to(now()->subDays(5))->create(); - Form::factory()->count(2)->to(now()->addDays(3))->create(); - - sleep(1); - $this->callFilter('form.index', ['past' => true]) - ->assertInertiaCount('data.data', 10); - $this->callFilter('form.index', []) - ->assertInertiaCount('data.data', 2); - } -} diff --git a/tests/Feature/Form/FormUpdateActionTest.php b/tests/Feature/Form/FormUpdateActionTest.php new file mode 100644 index 00000000..348d1446 --- /dev/null +++ b/tests/Feature/Form/FormUpdateActionTest.php @@ -0,0 +1,40 @@ +login()->loginNami()->withoutExceptionHandling(); + $form = Form::factory()->create(); + $payload = FormRequest::new()->sections([ + FormtemplateSectionRequest::new()->fields([ + FormtemplateFieldRequest::new()->type(DateField::class)->state(['max_today' => true]), + ]) + ])->create(); + + $this->patchJson(route('form.update', ['form' => $form]), $payload) + ->assertOk(); + + $form = $form->fresh(); + + $this->assertTrue(data_get($form->config, 'sections.0.fields.0.max_today')); + } +}