adrema/tests/EndToEnd/Form/FormIndexActionTest.php

103 lines
4.5 KiB
PHP
Raw Normal View History

2023-12-31 22:35:13 +01:00
<?php
2024-02-03 17:51:27 +01:00
namespace Tests\EndToEnd\Form;
2023-12-31 22:35:13 +01:00
2024-02-04 03:19:28 +01:00
use App\Form\Fields\TextField;
2023-12-31 22:35:13 +01:00
use App\Form\Models\Form;
2024-01-01 16:53:32 +01:00
use App\Form\Models\Formtemplate;
2024-02-03 17:51:27 +01:00
use Carbon\Carbon;
use Tests\EndToEndTestCase;
use Tests\Feature\Form\FormtemplateFieldRequest;
use Tests\Feature\Form\FormtemplateSectionRequest;
2023-12-31 22:35:13 +01:00
2024-02-03 17:51:27 +01:00
class FormIndexActionTest extends EndToEndTestCase
2023-12-31 22:35:13 +01:00
{
public function testItDisplaysForms(): void
{
2024-02-03 17:51:27 +01:00
Carbon::setTestNow(Carbon::parse('2023-03-03'));
2023-12-31 22:35:13 +01:00
$this->login()->loginNami()->withoutExceptionHandling();
2024-01-10 21:31:34 +01:00
Formtemplate::factory()->name('tname')->sections([FormtemplateSectionRequest::new()->name('sname')])->create();
2024-01-01 18:29:33 +01:00
$form = Form::factory()
2024-01-01 16:43:40 +01:00
->name('lala')
->excerpt('fff')
->description('desc')
->from('2023-05-05')
->to('2023-06-07')
->mailTop('Guten Tag')
->mailBottom('Cheers')
->registrationFrom('2023-05-06 04:00:00')
->registrationUntil('2023-04-01 05:00:00')
2024-02-04 03:19:28 +01:00
->sections([FormtemplateSectionRequest::new()->name('sname')->fields([FormtemplateFieldRequest::type(TextField::class)])])
2024-01-01 16:43:40 +01:00
->create();
2023-12-31 22:35:13 +01:00
2024-02-03 17:51:27 +01:00
sleep(1);
2023-12-31 22:35:13 +01:00
$this->get(route('form.index'))
->assertOk()
->assertInertiaPath('data.data.0.name', 'lala')
2024-02-03 17:51:27 +01:00
->assertInertiaPath('data.data.0.config.sections.0.name', 'sname')
2024-01-01 18:29:33 +01:00
->assertInertiaPath('data.data.0.id', $form->id)
2023-12-31 22:35:13 +01:00
->assertInertiaPath('data.data.0.excerpt', 'fff')
->assertInertiaPath('data.data.0.description', 'desc')
->assertInertiaPath('data.data.0.mail_top', 'Guten Tag')
->assertInertiaPath('data.data.0.mail_bottom', 'Cheers')
2024-01-01 16:43:40 +01:00
->assertInertiaPath('data.data.0.from_human', '05.05.2023')
->assertInertiaPath('data.data.0.to_human', '07.06.2023')
->assertInertiaPath('data.data.0.from', '2023-05-05')
->assertInertiaPath('data.data.0.to', '2023-06-07')
2023-12-31 22:35:13 +01:00
->assertInertiaPath('data.data.0.registration_from', '2023-05-06 04:00:00')
2024-01-01 16:53:32 +01:00
->assertInertiaPath('data.data.0.registration_until', '2023-04-01 05:00:00')
->assertInertiaPath('data.meta.links.store', route('form.store'))
2024-01-01 18:29:33 +01:00
->assertInertiaPath('data.meta.links.formtemplate_index', route('formtemplate.index'))
2024-01-01 16:53:32 +01:00
->assertInertiaPath('data.meta.templates.0.name', 'tname')
2024-01-01 18:29:33 +01:00
->assertInertiaPath('data.meta.templates.0.config.sections.0.name', 'sname')
->assertInertiaPath('data.meta.default.name', '')
2024-02-03 17:51:27 +01:00
->assertInertiaPath('data.meta.default.description', [])
2024-01-01 18:29:33 +01:00
->assertInertiaPath('data.meta.default.excerpt', '')
2024-01-01 18:30:52 +01:00
->assertInertiaPath('data.meta.default.config', null)
->assertInertiaPath('data.meta.base_url', url(''))
->assertInertiaPath('data.meta.section_default.name', '');
2023-12-31 22:35:13 +01:00
}
2024-02-03 17:51:27 +01:00
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);
}
2023-12-31 22:35:13 +01:00
}