2024-02-08 21:04:00 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Form;
|
|
|
|
|
|
|
|
use App\Form\Fields\TextField;
|
|
|
|
use App\Form\Models\Form;
|
|
|
|
use App\Form\Models\Participant;
|
2024-04-26 23:20:03 +02:00
|
|
|
use App\Form\Scopes\ParticipantFilterScope;
|
2024-02-08 23:09:51 +01:00
|
|
|
use App\Group;
|
2024-04-12 00:14:02 +02:00
|
|
|
use Carbon\Carbon;
|
2024-02-08 21:04:00 +01:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
|
2024-02-19 01:07:54 +01:00
|
|
|
class ParticipantIndexActionTest extends FormTestCase
|
2024-02-08 21:04:00 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
|
|
|
public function testItShowsParticipantsAndColumns(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
2024-02-08 23:09:51 +01:00
|
|
|
$group = Group::factory()->innerName('Stamm')->create();
|
2024-02-08 21:04:00 +01:00
|
|
|
$form = Form::factory()
|
2024-07-02 18:04:55 +02:00
|
|
|
->has(Participant::factory()->state(['member_id' => 55])->data(['vorname' => 'Max', 'select' => ['A', 'B'], 'stufe' => 'Pfadfinder', 'test1' => '', 'test2' => '', 'test3' => '', 'birthday' => '1991-04-20', 'bezirk' => $group->id]))
|
2024-06-20 00:12:15 +02:00
|
|
|
->fields([
|
|
|
|
$this->textField('vorname')->name('Vorname'),
|
|
|
|
$this->checkboxesField('select')->options(['A', 'B', 'C']),
|
|
|
|
$this->dropdownField('stufe')->options(['Wölfling', 'Jungpfadfinder', 'Pfadfinder']),
|
|
|
|
$this->textField('test1')->name('Test 1'),
|
|
|
|
$this->textField('test2')->name('Test 2'),
|
|
|
|
$this->textField('test3')->name('Test 3'),
|
|
|
|
$this->dateField('birthday')->name('Geburtsdatum'),
|
|
|
|
$this->groupField('bezirk')->name('bezirk'),
|
2024-02-08 21:04:00 +01:00
|
|
|
])
|
|
|
|
->create();
|
|
|
|
|
|
|
|
$this->callFilter('form.participant.index', [], ['form' => $form])
|
|
|
|
->assertOk()
|
2024-06-21 00:24:27 +02:00
|
|
|
->assertJsonPath('data.0.id', $form->participants->first()->id)
|
2024-02-08 21:04:00 +01:00
|
|
|
->assertJsonPath('data.0.vorname', 'Max')
|
2024-02-09 23:22:49 +01:00
|
|
|
->assertJsonPath('data.0.vorname_display', 'Max')
|
2024-02-08 21:04:00 +01:00
|
|
|
->assertJsonPath('data.0.stufe', 'Pfadfinder')
|
2024-02-08 23:09:51 +01:00
|
|
|
->assertJsonPath('data.0.bezirk', $group->id)
|
2024-07-02 18:04:55 +02:00
|
|
|
->assertJsonPath('data.0.member_id', 55)
|
2024-02-09 23:22:49 +01:00
|
|
|
->assertJsonPath('data.0.bezirk_display', 'Stamm')
|
|
|
|
->assertJsonPath('data.0.birthday_display', '20.04.1991')
|
2024-02-08 23:09:51 +01:00
|
|
|
->assertJsonPath('data.0.birthday', '1991-04-20')
|
2024-02-09 23:22:49 +01:00
|
|
|
->assertJsonPath('data.0.select', ['A', 'B'])
|
|
|
|
->assertJsonPath('data.0.select_display', 'A, B')
|
2024-04-25 21:49:31 +02:00
|
|
|
->assertJsonPath('data.0.links.destroy', route('participant.destroy', ['participant' => $form->participants->first()]))
|
2024-07-02 18:04:55 +02:00
|
|
|
->assertJsonPath('data.0.links.assign', route('participant.assign', ['participant' => $form->participants->first()]))
|
2024-02-08 21:04:00 +01:00
|
|
|
->assertJsonPath('meta.columns.0.name', 'Vorname')
|
|
|
|
->assertJsonPath('meta.columns.0.base_type', class_basename(TextField::class))
|
2024-02-08 23:09:51 +01:00
|
|
|
->assertJsonPath('meta.columns.0.id', 'vorname')
|
2024-02-09 23:22:49 +01:00
|
|
|
->assertJsonPath('meta.columns.6.display_attribute', 'birthday_display')
|
|
|
|
->assertJsonPath('meta.columns.0.display_attribute', 'vorname_display')
|
2024-02-21 22:44:52 +01:00
|
|
|
->assertJsonPath('meta.form_meta.active_columns', ['vorname', 'select', 'stufe', 'test1'])
|
2024-06-20 23:25:14 +02:00
|
|
|
->assertJsonPath('meta.has_nami_field', false)
|
2024-02-21 23:18:31 +01:00
|
|
|
->assertJsonPath('meta.links.update_form_meta', route('form.update-meta', ['form' => $form]))
|
2024-02-21 22:44:52 +01:00
|
|
|
->assertJsonPath('meta.form_meta.sorting', ['vorname', 'asc']);
|
2024-02-08 21:04:00 +01:00
|
|
|
}
|
2024-02-20 01:22:08 +01:00
|
|
|
|
2024-04-26 23:20:03 +02:00
|
|
|
public function testItShowsEmptyFilters(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
$form = Form::factory()->fields([$this->checkboxField('check')->name('Checked')])->create();
|
|
|
|
|
|
|
|
$this->callFilter('form.participant.index', [], ['form' => $form])
|
|
|
|
->assertOk()
|
|
|
|
->assertJsonPath('meta.filters.0.name', 'Checked')
|
|
|
|
->assertJsonPath('meta.filters.0.key', 'check')
|
|
|
|
->assertJsonPath('meta.filters.0.base_type', 'CheckboxField')
|
|
|
|
->assertJsonPath('meta.default_filter_value', ParticipantFilterScope::$nan);
|
|
|
|
|
|
|
|
$this->callFilter('form.participant.index', ['data' => ['check' => null]], ['form' => $form])->assertHasJsonPath('meta.filter.data.check')->assertJsonPath('meta.filter.data.check', null);
|
|
|
|
$this->callFilter('form.participant.index', ['data' => ['check' => 'A']], ['form' => $form])->assertJsonPath('meta.filter.data.check', 'A');
|
|
|
|
$this->callFilter('form.participant.index', ['data' => []], ['form' => $form])->assertJsonPath('meta.filter.data.check', ParticipantFilterScope::$nan);
|
|
|
|
}
|
|
|
|
|
2024-06-20 23:25:14 +02:00
|
|
|
public function testItDisplaysHasNamiField(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
$form = Form::factory()->fields([$this->namiField('mitglieder')])->create();
|
|
|
|
$this->callFilter('form.participant.index', [], ['form' => $form])->assertJsonPath('meta.has_nami_field', true);
|
|
|
|
}
|
|
|
|
|
2024-04-26 23:20:03 +02:00
|
|
|
public function testItFiltersParticipantsByCheckboxValue(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
$form = Form::factory()->fields([$this->checkboxField('check')])
|
|
|
|
->has(Participant::factory()->data(['check' => true])->count(1))
|
|
|
|
->has(Participant::factory()->data(['check' => false])->count(2))
|
|
|
|
->create();
|
|
|
|
|
|
|
|
$this->callFilter('form.participant.index', ['data' => ['check' => ParticipantFilterScope::$nan]], ['form' => $form])
|
|
|
|
->assertJsonCount(3, 'data');
|
|
|
|
$this->callFilter('form.participant.index', ['data' => ['check' => true]], ['form' => $form])
|
|
|
|
->assertJsonCount(1, 'data');
|
|
|
|
$this->callFilter('form.participant.index', ['data' => ['check' => false]], ['form' => $form])
|
|
|
|
->assertJsonCount(2, 'data');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItFiltersParticipantsByDropdownValue(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
$form = Form::factory()->fields([$this->dropdownField('drop')->options(['A', 'B'])])
|
|
|
|
->has(Participant::factory()->data(['drop' => null])->count(1))
|
|
|
|
->has(Participant::factory()->data(['drop' => 'A'])->count(2))
|
|
|
|
->has(Participant::factory()->data(['drop' => 'B'])->count(4))
|
|
|
|
->create();
|
|
|
|
|
|
|
|
$this->callFilter('form.participant.index', ['data' => ['drop' => ParticipantFilterScope::$nan]], ['form' => $form])
|
|
|
|
->assertJsonCount(7, 'data');
|
|
|
|
$this->callFilter('form.participant.index', ['data' => ['drop' => null]], ['form' => $form])
|
|
|
|
->assertJsonCount(1, 'data');
|
|
|
|
$this->callFilter('form.participant.index', ['data' => ['drop' => 'A']], ['form' => $form])
|
|
|
|
->assertJsonCount(2, 'data');
|
|
|
|
$this->callFilter('form.participant.index', ['data' => ['drop' => 'B']], ['form' => $form])
|
|
|
|
->assertJsonCount(4, 'data');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItFiltersParticipantsByRadioValue(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
$form = Form::factory()->fields([$this->radioField('drop')->options(['A', 'B'])])
|
|
|
|
->has(Participant::factory()->data(['drop' => null])->count(1))
|
|
|
|
->has(Participant::factory()->data(['drop' => 'A'])->count(2))
|
|
|
|
->has(Participant::factory()->data(['drop' => 'B'])->count(4))
|
|
|
|
->create();
|
|
|
|
|
|
|
|
$this->callFilter('form.participant.index', ['data' => ['drop' => ParticipantFilterScope::$nan]], ['form' => $form])
|
|
|
|
->assertJsonCount(7, 'data');
|
|
|
|
$this->callFilter('form.participant.index', ['data' => ['drop' => 'A']], ['form' => $form])
|
|
|
|
->assertJsonCount(2, 'data');
|
|
|
|
$this->callFilter('form.participant.index', ['data' => ['drop' => 'B']], ['form' => $form])
|
|
|
|
->assertJsonCount(4, 'data');
|
|
|
|
}
|
|
|
|
|
2024-02-20 01:22:08 +01:00
|
|
|
public function testItPresentsNamiField(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
$form = Form::factory()
|
|
|
|
->has(Participant::factory()->data(['mitglieder' => [['id' => 393], ['id' => 394]]]))
|
|
|
|
->has(Participant::factory()->nr(393)->data(['mitglieder' => []]))
|
|
|
|
->has(Participant::factory()->nr(394)->data(['mitglieder' => []]))
|
2024-06-20 00:12:15 +02:00
|
|
|
->fields([
|
|
|
|
$this->namiField('mitglieder'),
|
2024-02-20 01:22:08 +01:00
|
|
|
])
|
|
|
|
->create();
|
|
|
|
|
|
|
|
$this->callFilter('form.participant.index', [], ['form' => $form])
|
|
|
|
->assertJsonPath('data.0.mitglieder_display', '393, 394');
|
|
|
|
}
|
2024-04-12 00:14:02 +02:00
|
|
|
|
|
|
|
public function testItShowsRegisteredAtColumnAndAttribute(): void
|
|
|
|
{
|
|
|
|
Carbon::setTestNow(Carbon::parse('2023-03-05 06:00:00'));
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
$form = Form::factory()
|
|
|
|
->has(Participant::factory()->data(['vorname' => 'Max']))
|
2024-06-20 00:12:15 +02:00
|
|
|
->fields([
|
|
|
|
$this->textField('vorname')->name('Vorname'),
|
2024-04-12 00:14:02 +02:00
|
|
|
])
|
|
|
|
->create();
|
|
|
|
|
|
|
|
$this->callFilter('form.participant.index', [], ['form' => $form])
|
|
|
|
->assertJsonPath('data.0.vorname', 'Max')
|
|
|
|
->assertJsonPath('data.0.vorname_display', 'Max')
|
|
|
|
->assertJsonPath('data.0.created_at', '2023-03-05 06:00:00')
|
|
|
|
->assertJsonPath('data.0.created_at_display', '05.03.2023')
|
|
|
|
->assertJsonPath('meta.columns.1.name', 'Registriert am')
|
|
|
|
->assertJsonPath('meta.columns.1.id', 'created_at')
|
|
|
|
->assertJsonPath('meta.columns.1.display_attribute', 'created_at_display');
|
|
|
|
}
|
2024-06-19 23:51:20 +02:00
|
|
|
|
|
|
|
public function testItShowsOnlyParentParticipantsWhenFilterEnabled(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
$form = Form::factory()->create();
|
|
|
|
$participant = Participant::factory()
|
|
|
|
->has(Participant::factory()->for($form)->count(2), 'children')
|
|
|
|
->for($form)
|
|
|
|
->create();
|
|
|
|
|
|
|
|
$this->callFilter('form.participant.index', [], ['form' => $form])->assertJsonCount(3, 'data');
|
|
|
|
$this->callFilter('form.participant.index', [], ['form' => $form, 'parent' => -1])->assertJsonCount(1, 'data');
|
|
|
|
$this->callFilter('form.participant.index', [], ['form' => $form, 'parent' => $participant->id])->assertJsonCount(2, 'data');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItShowsChildrenCount(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
$form = Form::factory()->create();
|
|
|
|
$participant = Participant::factory()
|
|
|
|
->has(Participant::factory()->for($form)->count(2), 'children')
|
|
|
|
->for($form)
|
|
|
|
->create();
|
|
|
|
Participant::factory()->for($form)->create();
|
|
|
|
|
|
|
|
$this->callFilter('form.participant.index', [], ['form' => $form, 'parent' => -1])
|
|
|
|
->assertJsonPath('data.0.children_count', 2)
|
2024-06-20 23:25:47 +02:00
|
|
|
->assertJsonPath('data.1.children_count', 0)
|
2024-06-21 00:25:14 +02:00
|
|
|
->assertJsonPath('data.0.links.children', route('form.participant.index', ['form' => $form, 'parent' => $participant->id]))
|
2024-06-20 23:25:47 +02:00
|
|
|
->assertJsonPath('meta.current_page', 1);
|
2024-06-19 23:51:20 +02:00
|
|
|
$this->callFilter('form.participant.index', [], ['form' => $form, 'parent' => $participant->id])->assertJsonPath('data.0.children_count', 0);
|
|
|
|
}
|
2024-02-08 21:04:00 +01:00
|
|
|
}
|