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-05-27 19:47:28 +02:00
|
|
|
use App\Form\FormSettings;
|
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-08 20:29:46 +01:00
|
|
|
use App\Form\Models\Participant;
|
2024-02-03 17:51:27 +01:00
|
|
|
use Carbon\Carbon;
|
|
|
|
use Tests\Feature\Form\FormtemplateSectionRequest;
|
2024-04-24 00:02:27 +02:00
|
|
|
use Tests\RequestFactories\EditorRequestFactory;
|
2023-12-31 22:35:13 +01:00
|
|
|
|
2024-02-20 02:02:42 +01:00
|
|
|
class FormIndexActionTest extends FormTestCase
|
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')
|
2024-04-24 00:02:27 +02:00
|
|
|
->description(EditorRequestFactory::new()->text(10, 'desc'))
|
2024-01-01 16:43:40 +01:00
|
|
|
->from('2023-05-05')
|
|
|
|
->to('2023-06-07')
|
2024-04-24 00:02:27 +02:00
|
|
|
->mailTop(EditorRequestFactory::new()->text(10, 'Guten Tag'))
|
|
|
|
->mailBottom(EditorRequestFactory::new()->text(10, 'Cheers'))
|
2024-01-01 16:43:40 +01:00
|
|
|
->registrationFrom('2023-05-06 04:00:00')
|
|
|
|
->registrationUntil('2023-04-01 05:00:00')
|
2024-02-20 02:02:42 +01:00
|
|
|
->sections([FormtemplateSectionRequest::new()->name('sname')->fields([$this->textField()])])
|
2024-02-08 20:29:46 +01:00
|
|
|
->has(Participant::factory()->count(5))
|
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')
|
2024-04-24 00:02:27 +02:00
|
|
|
->assertInertiaPath('data.data.0.description.blocks.0.data.text', 'desc')
|
|
|
|
->assertInertiaPath('data.data.0.mail_top.blocks.0.data.text', 'Guten Tag')
|
|
|
|
->assertInertiaPath('data.data.0.mail_bottom.blocks.0.data.text', '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')
|
2024-02-08 20:29:46 +01:00
|
|
|
->assertInertiaPath('data.data.0.participants_count', 5)
|
2024-01-01 16:43:40 +01:00
|
|
|
->assertInertiaPath('data.data.0.to', '2023-06-07')
|
2024-05-27 18:30:05 +02:00
|
|
|
->assertInertiaPath('data.data.0.is_active', true)
|
2024-05-27 18:49:11 +02:00
|
|
|
->assertInertiaPath('data.data.0.is_private', false)
|
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')
|
2024-02-08 21:04:00 +01:00
|
|
|
->assertInertiaPath('data.data.0.links.participant_index', route('form.participant.index', ['form' => $form]))
|
2024-05-27 21:08:09 +02:00
|
|
|
->assertInertiaPath('data.data.0.links.export', route('form.export', ['form' => $form]))
|
2024-01-01 16:53:32 +01: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-05-27 18:30:05 +02:00
|
|
|
->assertInertiaPath('data.meta.default.is_active', true)
|
2024-05-27 18:49:11 +02:00
|
|
|
->assertInertiaPath('data.meta.default.is_private', false)
|
2024-04-14 00:26:17 +02:00
|
|
|
->assertInertiaPath('data.meta.default.mailattachments', [])
|
2024-01-01 18:30:52 +01:00
|
|
|
->assertInertiaPath('data.meta.default.config', null)
|
|
|
|
->assertInertiaPath('data.meta.base_url', url(''))
|
2024-02-21 22:10:26 +01:00
|
|
|
->assertInertiaPath('data.meta.namiTypes.0', ['id' => 'Vorname', 'name' => 'Vorname'])
|
2024-03-15 00:39:17 +01:00
|
|
|
->assertInertiaPath('data.meta.specialTypes.0', ['id' => 'Vorname', 'name' => 'Vorname'])
|
2024-01-01 18:30:52 +01:00
|
|
|
->assertInertiaPath('data.meta.section_default.name', '');
|
2023-12-31 22:35:13 +01:00
|
|
|
}
|
2024-02-03 17:51:27 +01:00
|
|
|
|
2024-02-09 00:21:33 +01:00
|
|
|
public function testItHandlesFullTextSearch(): void
|
2024-02-03 17:51:27 +01:00
|
|
|
{
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2024-06-20 23:29:23 +02:00
|
|
|
public function testItDisplaysParentLinkForFormWithNamiFields(): void
|
|
|
|
{
|
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
|
|
|
$form = Form::factory()->fields([$this->namiField('mitglieder')])->create();
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
$this->callFilter('form.index', [])
|
|
|
|
->assertInertiaPath('data.data.0.has_nami_field', true)
|
|
|
|
->assertInertiaPath('data.data.0.links.participant_root_index', route('form.participant.index', ['form' => $form, 'parent' => -1]))
|
|
|
|
->assertInertiaPath('data.data.0.links.participant_index', route('form.participant.index', ['form' => $form, 'parent' => null]));
|
|
|
|
}
|
|
|
|
|
2024-05-27 19:47:28 +02:00
|
|
|
public function testItDisplaysRegisterUrl(): void
|
|
|
|
{
|
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
|
|
|
FormSettings::fake(['registerUrl' => 'https://example.com/form/{slug}/register']);
|
|
|
|
Form::factory()->to(now()->addYear())->name('ZEM 2024')->create();
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
$this->callFilter('form.index', [])->assertInertiaPath('data.data.0.links.frontend', 'https://example.com/form/zem-2024/register');
|
|
|
|
}
|
|
|
|
|
2024-05-27 18:30:05 +02:00
|
|
|
public function testItDoesntReturnInactiveForms(): void
|
|
|
|
{
|
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
|
|
|
Form::factory()->isActive(false)->count(1)->create();
|
|
|
|
Form::factory()->isActive(true)->count(2)->create();
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
$this->callFilter('form.index', [])->assertInertiaCount('data.data', 2);
|
|
|
|
$this->callFilter('form.index', ['inactive' => true])->assertInertiaCount('data.data', 3);
|
|
|
|
$this->callFilter('form.index', ['inactive' => false])->assertInertiaCount('data.data', 2);
|
|
|
|
}
|
|
|
|
|
2024-02-09 00:21:33 +01:00
|
|
|
public function testItOrdersByStartDateDesc(): void
|
2024-02-03 17:51:27 +01:00
|
|
|
{
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2024-02-09 00:21:33 +01:00
|
|
|
public function testItShowsPastEvents(): void
|
2024-02-03 17:51:27 +01:00
|
|
|
{
|
|
|
|
$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
|
|
|
}
|