Fixed tests

This commit is contained in:
philipp lang 2024-02-03 17:51:27 +01:00
parent 9a3a0402d9
commit 3d62970baf
6 changed files with 95 additions and 62 deletions

View File

@ -24,6 +24,7 @@ trait HasValidation
'config.sections.*.fields.*.key' => ['required', 'string', 'regex:/^[a-zA-Z_]*$/'], 'config.sections.*.fields.*.key' => ['required', 'string', 'regex:/^[a-zA-Z_]*$/'],
'config.sections.*.fields.*.default' => 'present', 'config.sections.*.fields.*.default' => 'present',
'config.sections.*.fields.*.columns' => 'required|array', 'config.sections.*.fields.*.columns' => 'required|array',
'config.sections.*.fields.*.*' => '',
'config.sections.*.fields.*.columns.mobile' => 'required|numeric|gt:0|lte:2', '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.tablet' => 'required|numeric|gt:0|lte:4',
'config.sections.*.fields.*.columns.desktop' => 'required|numeric|gt:0|lte:6', 'config.sections.*.fields.*.columns.desktop' => 'required|numeric|gt:0|lte:6',

View File

@ -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 public static function fake(Generator $faker): array

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Tests\Feature\EndToEnd; namespace Tests\EndToEnd\Form;
use App\Form\Models\Form; use App\Form\Models\Form;
use App\Form\Models\Formtemplate; use App\Form\Models\Formtemplate;
@ -10,7 +10,6 @@ use Illuminate\Support\Facades\Storage;
use Tests\EndToEndTestCase; use Tests\EndToEndTestCase;
use Tests\Feature\Form\FormtemplateFieldRequest; use Tests\Feature\Form\FormtemplateFieldRequest;
use Tests\Feature\Form\FormtemplateSectionRequest; use Tests\Feature\Form\FormtemplateSectionRequest;
use Tests\TestCase;
class FormApiListActionTest extends EndToEndTestCase class FormApiListActionTest extends EndToEndTestCase
{ {

View File

@ -1,19 +1,20 @@
<?php <?php
namespace Tests\Feature\Form; namespace Tests\EndToEnd\Form;
use App\Form\Models\Form; use App\Form\Models\Form;
use App\Form\Models\Formtemplate; use App\Form\Models\Formtemplate;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Carbon\Carbon;
use Tests\TestCase; use Tests\EndToEndTestCase;
use Tests\Feature\Form\FormtemplateFieldRequest;
use Tests\Feature\Form\FormtemplateSectionRequest;
class FormIndexActionTest extends TestCase class FormIndexActionTest extends EndToEndTestCase
{ {
use DatabaseTransactions;
public function testItDisplaysForms(): void public function testItDisplaysForms(): void
{ {
Carbon::setTestNow(Carbon::parse('2023-03-03'));
$this->login()->loginNami()->withoutExceptionHandling(); $this->login()->loginNami()->withoutExceptionHandling();
Formtemplate::factory()->name('tname')->sections([FormtemplateSectionRequest::new()->name('sname')])->create(); Formtemplate::factory()->name('tname')->sections([FormtemplateSectionRequest::new()->name('sname')])->create();
$form = Form::factory() $form = Form::factory()
@ -29,10 +30,11 @@ class FormIndexActionTest extends TestCase
->sections([FormtemplateSectionRequest::new()->name('sname')->fields([FormtemplateFieldRequest::new()])]) ->sections([FormtemplateSectionRequest::new()->name('sname')->fields([FormtemplateFieldRequest::new()])])
->create(); ->create();
sleep(1);
$this->get(route('form.index')) $this->get(route('form.index'))
->assertOk() ->assertOk()
->assertInertiaPath('data.data.0.config.sections.0.name', 'sname')
->assertInertiaPath('data.data.0.name', 'lala') ->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.id', $form->id)
->assertInertiaPath('data.data.0.excerpt', 'fff') ->assertInertiaPath('data.data.0.excerpt', 'fff')
->assertInertiaPath('data.data.0.description', 'desc') ->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.name', 'tname')
->assertInertiaPath('data.meta.templates.0.config.sections.0.name', 'sname') ->assertInertiaPath('data.meta.templates.0.config.sections.0.name', 'sname')
->assertInertiaPath('data.meta.default.name', '') ->assertInertiaPath('data.meta.default.name', '')
->assertInertiaPath('data.meta.default.description', '') ->assertInertiaPath('data.meta.default.description', [])
->assertInertiaPath('data.meta.default.excerpt', '') ->assertInertiaPath('data.meta.default.excerpt', '')
->assertInertiaPath('data.meta.default.config', null) ->assertInertiaPath('data.meta.default.config', null)
->assertInertiaPath('data.meta.base_url', url('')) ->assertInertiaPath('data.meta.base_url', url(''))
->assertInertiaPath('data.meta.section_default.name', ''); ->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);
}
} }

View File

@ -1,50 +0,0 @@
<?php
namespace Tests\EndToEnd;
use App\Form\Models\Form;
use Tests\EndToEndTestCase;
class FormIndexTest extends EndToEndTestCase
{
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);
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace Tests\Feature\Form;
use App\Form\Fields\DateField;
use App\Form\Models\Form;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
use Illuminate\Support\Facades\Storage;
class FormUpdateActionTest extends TestCase
{
use DatabaseTransactions;
public function setUp(): void
{
parent::setUp();
Storage::fake('temp');
}
public function testItSetsCustomAttributesOfFields(): void
{
$this->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'));
}
}