diff --git a/app/Member/FilterScope.php b/app/Member/FilterScope.php index c39d6799..2112c48f 100644 --- a/app/Member/FilterScope.php +++ b/app/Member/FilterScope.php @@ -2,8 +2,11 @@ namespace App\Member; +use App\Activity; +use App\Group; use App\Invoice\BillKind; use App\Lib\Filter; +use App\Subactivity; use Illuminate\Support\Collection; use Laravel\Scout\Builder; use Spatie\LaravelData\Attributes\MapInputName; @@ -139,6 +142,9 @@ class FilterScope extends Filter */ protected function possibleValuesForMembership(array $membership): Collection { + $membership['group_ids'] = count($membership['group_ids']) === 0 ? Group::pluck('id')->toArray() : $membership['group_ids']; + $membership['activity_ids'] = count($membership['activity_ids']) === 0 ? Activity::pluck('id')->toArray() : $membership['activity_ids']; + $membership['subactivity_ids'] = count($membership['subactivity_ids']) === 0 ? Subactivity::pluck('id')->toArray() : $membership['subactivity_ids']; return $this->combinations($membership['group_ids'], $membership['activity_ids'], $membership['subactivity_ids']) ->map(fn ($combination) => collect($combination)->implode('|')); } diff --git a/tests/EndToEnd/MemberIndexTest.php b/tests/EndToEnd/MemberIndexTest.php index 639d0eee..4ac08fc1 100644 --- a/tests/EndToEnd/MemberIndexTest.php +++ b/tests/EndToEnd/MemberIndexTest.php @@ -199,6 +199,26 @@ class MemberIndexTest extends EndToEndTestCase ]])->assertInertiaCount('data.data', 1); } + public function testGroupOfMembershipsFilterCanBeEmpty(): void + { + $this->withoutExceptionHandling()->login()->loginNami(); + $mitglied = Activity::factory()->create(); + $woelfling = Subactivity::factory()->create(); + $group = Group::factory()->create(); + Member::factory()->defaults()->has(Membership::factory()->for($mitglied)->for($woelfling)->for($group))->create(); + + sleep(1); + $this->callFilter('member.index', ['memberships' => [ + ['group_ids' => [], 'activity_ids' => [$mitglied->id], 'subactivity_ids' => [$woelfling->id]], + ]])->assertInertiaCount('data.data', 1); + $this->callFilter('member.index', ['memberships' => [ + ['group_ids' => [$group->id], 'activity_ids' => [], 'subactivity_ids' => [$woelfling->id]], + ]])->assertInertiaCount('data.data', 1); + $this->callFilter('member.index', ['memberships' => [ + ['group_ids' => [$group->id], 'activity_ids' => [$mitglied->id], 'subactivity_ids' => []], + ]])->assertInertiaCount('data.data', 1); + } + public function testItFiltersForSearchButNotForPayments(): void { $this->withoutExceptionHandling()->login()->loginNami();