Skip to content

Commit

Permalink
Undocumented - Filter Matches via Playlist (#1368)
Browse files Browse the repository at this point in the history
* fix: add playlist filter to matches

* test: add test for filter matches

* test: proper test for playlist filter
  • Loading branch information
iBotPeaches committed Jun 24, 2024
1 parent 9e8d231 commit fa106df
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/Livewire/GameHistoryTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use App\Livewire\Traits\HasScrimEditor;
use App\Models\Player;
use App\Models\Playlist;
use Illuminate\View\View;
use Livewire\Attributes\Url;
use Livewire\Component;
use Livewire\WithPagination;

Expand All @@ -17,6 +19,9 @@ class GameHistoryTable extends Component

public Player $player;

#[Url]
public ?string $playlist = '';

// @phpstan-ignore-next-line
public $listeners = [
'$refresh',
Expand All @@ -30,10 +35,18 @@ public function paginationView(): string

public function render(): View
{
$playlist = null;
if ($this->playlist) {
$playlist = Playlist::query()
->where('uuid', $this->playlist)
->first();
}

return view('livewire.game-history-table', [
'isScrimEditor' => $this->isScrimEditor,
'games' => $this->player
->games()
->when($playlist, fn ($query) => $query->where('playlist_id', $playlist?->id))
->with(['playlist', 'map', 'category'])
->whereNotNull('playlist_id')
->orderByDesc('occurred_at')
Expand Down
21 changes: 21 additions & 0 deletions tests/Feature/Pages/PlayerPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Models\Csr;
use App\Models\Player;
use App\Models\PlayerBan;
use App\Models\Playlist;
use App\Models\Rank;
use App\Models\ServiceRecord;
use App\Models\User;
Expand Down Expand Up @@ -180,6 +181,26 @@ public function testLoadingPlayerOverviewPage(string $gamertag): void
$response->assertSeeLivewire('update-player-panel');
}

public function testLoadingPlayerMatchesPageWithPlaylistFilter(): void
{
// Arrange
Http::fake();

$player = Player::factory()->createOne([
'gamertag' => 'gamertag',
]);

$playlist = Playlist::factory()->createOne();

// Act
$response = $this->get('/player/'.$player->url_safe_gamertag.'/matches?playlist='.$playlist->uuid);

// Assert
$response->assertStatus(Response::HTTP_OK);
$response->assertSeeLivewire('game-history-table');
$response->assertSeeLivewire('update-player-panel');
}

public function testLoadingPlayerOverviewPageWithMedalData(): void
{
// Arrange
Expand Down

0 comments on commit fa106df

Please sign in to comment.