Add presenter for nami field
This commit is contained in:
parent
5f47729bb6
commit
5f48b4e64d
|
@ -4,10 +4,10 @@ namespace App\Form\Fields;
|
||||||
|
|
||||||
use App\Form\Models\Form;
|
use App\Form\Models\Form;
|
||||||
use App\Form\Models\Participant;
|
use App\Form\Models\Participant;
|
||||||
|
use App\Form\Presenters\NamiPresenter;
|
||||||
|
use App\Form\Presenters\Presenter;
|
||||||
use App\Member\Member;
|
use App\Member\Member;
|
||||||
use Faker\Generator;
|
use Faker\Generator;
|
||||||
use Generator as LazyGenerator;
|
|
||||||
use Illuminate\Validation\Factory;
|
|
||||||
|
|
||||||
class NamiField extends Field
|
class NamiField extends Field
|
||||||
{
|
{
|
||||||
|
@ -129,4 +129,9 @@ class NamiField extends Field
|
||||||
$form->participants()->create(['data' => $data, 'mitgliedsnr' => $memberData['id']]);
|
$form->participants()->create(['data' => $data, 'mitgliedsnr' => $memberData['id']]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPresenter(): Presenter
|
||||||
|
{
|
||||||
|
return app(NamiPresenter::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Form\Presenters;
|
||||||
|
|
||||||
|
class NamiPresenter extends Presenter
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ?array<int, array{id: int}> $value
|
||||||
|
*/
|
||||||
|
public function present($value): string
|
||||||
|
{
|
||||||
|
return collect(array_column($value, 'id'))->implode(', ');
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ use App\Form\Fields\TextField;
|
||||||
use App\Form\Models\Form;
|
use App\Form\Models\Form;
|
||||||
use App\Form\Models\Participant;
|
use App\Form\Models\Participant;
|
||||||
use App\Group;
|
use App\Group;
|
||||||
|
use App\Member\Member;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
class ParticipantIndexActionTest extends FormTestCase
|
class ParticipantIndexActionTest extends FormTestCase
|
||||||
|
@ -51,4 +52,22 @@ class ParticipantIndexActionTest extends FormTestCase
|
||||||
->assertJsonPath('meta.columns.0.display_attribute', 'vorname_display')
|
->assertJsonPath('meta.columns.0.display_attribute', 'vorname_display')
|
||||||
->assertJsonPath('meta.active_columns', ['vorname', 'select', 'stufe', 'test1']);
|
->assertJsonPath('meta.active_columns', ['vorname', 'select', 'stufe', 'test1']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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' => []]))
|
||||||
|
->sections([
|
||||||
|
FormtemplateSectionRequest::new()->fields([
|
||||||
|
$this->namiField('mitglieder'),
|
||||||
|
]),
|
||||||
|
])
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$this->callFilter('form.participant.index', [], ['form' => $form])
|
||||||
|
->assertJsonPath('data.0.mitglieder_display', '393, 394');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue