Add prevention items
This commit is contained in:
parent
0d76b3cc5f
commit
b01ff9a677
app
tests/Feature/Form
|
@ -5,6 +5,7 @@ namespace App\Form\Resources;
|
||||||
use App\Form\Models\Form;
|
use App\Form\Models\Form;
|
||||||
use App\Form\Models\Participant;
|
use App\Form\Models\Participant;
|
||||||
use App\Form\Scopes\ParticipantFilterScope;
|
use App\Form\Scopes\ParticipantFilterScope;
|
||||||
|
use App\Prevention\Enums\Prevention;
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
@ -28,6 +29,7 @@ class ParticipantResource extends JsonResource
|
||||||
'created_at_display' => $this->created_at->format('d.m.Y'),
|
'created_at_display' => $this->created_at->format('d.m.Y'),
|
||||||
'children_count' => $this->children_count,
|
'children_count' => $this->children_count,
|
||||||
'member_id' => $this->member_id,
|
'member_id' => $this->member_id,
|
||||||
|
'prevention_items' => $this->member ? Prevention::items($this->member->preventions()) : [],
|
||||||
'links' => [
|
'links' => [
|
||||||
'assign' => route('participant.assign', ['participant' => $this->getModel()]),
|
'assign' => route('participant.assign', ['participant' => $this->getModel()]),
|
||||||
'destroy' => route('participant.destroy', ['participant' => $this->getModel()]),
|
'destroy' => route('participant.destroy', ['participant' => $this->getModel()]),
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
namespace App\Prevention\Enums;
|
namespace App\Prevention\Enums;
|
||||||
|
|
||||||
|
use App\Member\Member;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
enum Prevention
|
enum Prevention
|
||||||
{
|
{
|
||||||
case EFZ;
|
case EFZ;
|
||||||
|
@ -18,4 +21,31 @@ enum Prevention
|
||||||
static::VK => 'Verhaltenskodex',
|
static::VK => 'Verhaltenskodex',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tooltip(bool $value): string
|
||||||
|
{
|
||||||
|
return $this->text() . ' ' . ($value ? 'vorhanden' : 'nicht vorhanden');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function letter(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
static::EFZ => 'F',
|
||||||
|
static::PS => 'P',
|
||||||
|
static::MOREPS => 'A',
|
||||||
|
static::VK => 'V',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, self> $preventions
|
||||||
|
*/
|
||||||
|
public static function items(array $preventions)
|
||||||
|
{
|
||||||
|
return collect(static::cases())->map(fn ($case) => [
|
||||||
|
'letter' => $case->letter(),
|
||||||
|
'value' => !in_array($case, $preventions),
|
||||||
|
'tooltip' => $case->tooltip(!in_array($case, $preventions)),
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ use App\Form\Models\Form;
|
||||||
use App\Form\Models\Participant;
|
use App\Form\Models\Participant;
|
||||||
use App\Form\Scopes\ParticipantFilterScope;
|
use App\Form\Scopes\ParticipantFilterScope;
|
||||||
use App\Group;
|
use App\Group;
|
||||||
|
use App\Member\Member;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
|
@ -207,4 +208,18 @@ class ParticipantIndexActionTest extends FormTestCase
|
||||||
->assertJsonPath('meta.current_page', 1);
|
->assertJsonPath('meta.current_page', 1);
|
||||||
$this->callFilter('form.participant.index', [], ['form' => $form, 'parent' => $participant->id])->assertJsonPath('data.0.children_count', 0);
|
$this->callFilter('form.participant.index', [], ['form' => $form, 'parent' => $participant->id])->assertJsonPath('data.0.children_count', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItShowsPreventionState(): void
|
||||||
|
{
|
||||||
|
$this->login()->loginNami()->withoutExceptionHandling();
|
||||||
|
$participant = Participant::factory()->data(['vorname' => 'Max'])
|
||||||
|
->for(Member::factory()->defaults()->state(['efz' => null]))
|
||||||
|
->for(Form::factory())
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$this->callFilter('form.participant.index', [], ['form' => $participant->form])
|
||||||
|
->assertJsonPath('data.0.prevention_items.0.letter', 'F')
|
||||||
|
->assertJsonPath('data.0.prevention_items.0.value', false)
|
||||||
|
->assertJsonPath('data.0.prevention_items.0.tooltip', 'erweitertes Führungszeugnis nicht vorhanden');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue