Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Filament/Resources/MediaEventResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static function table(Table $table): Table
{
return $table
->defaultSort('occurred_at', 'desc')
->defaultPaginationPageOption(50)
->defaultPaginationPageOption(10)
->columns([
Tables\Columns\TextColumn::make('mediaEventType.name')
->sortable(),
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Resources/MediaResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function table(Table $table): Table
{
return $table
->defaultSort('updated_at', 'desc')
->defaultPaginationPageOption(50)
->defaultPaginationPageOption(10)
->columns([
Tables\Columns\TextColumn::make('created_at')
->dateTime()
Expand Down
1 change: 1 addition & 0 deletions app/Filament/Resources/NoteResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static function form(Form $form): Form
public static function table(Table $table): Table
{
return $table
->defaultSort('updated_at', 'desc')
->columns([
Tables\Columns\TextColumn::make('slug'),
Tables\Columns\TextColumn::make('title')->lineClamp(50),
Expand Down
2 changes: 1 addition & 1 deletion app/Providers/Filament/AdminPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function panel(Panel $panel): Panel
->path('admin')
->login()
->colors([
'primary' => Color::Amber,
'primary' => Color::Emerald,
])
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
Expand Down
1 change: 1 addition & 0 deletions app/Queries/Media/BacklogQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function execute(): Collection
->leftJoin('media_events', 'media_events.media_id', '=', 'media.id')

->select(
'media.id as id',
'media.title as title',
'creators.name as creator',
'media_types.name as type',
Expand Down
1 change: 1 addition & 0 deletions app/Queries/Media/InProgressQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function execute(): Collection
});

$query->select(
'media.id as id',
'media.title as title',
'creators.name as creator',
'media_types.name as type',
Expand Down
1 change: 1 addition & 0 deletions app/Queries/Media/LogbookQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function execute(): Collection
->leftJoin('creators', 'media.creator_id', '=', 'creators.id')

->select(
'media.id as id',
'media.title as title',
'creators.name as creator',
'media_types.name as type',
Expand Down
8 changes: 8 additions & 0 deletions resources/views/components/media/item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@
{{ $item->creator }}
</div>
<x-media.note :item="$item" />
@can("administrate")
<a
class="link link-neutral text-xs text-gray-600"
href="{{ route("filament.admin.resources.media.edit", $item->id) }}"
>
Edit
</a>
@endcan
</div>
35 changes: 35 additions & 0 deletions tests/Feature/Http/Filament/Media/EditMediaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use App\Models\Media;
use App\Models\User;
use Tests\TestCase;

test('anonymous user not allowed', function () {
/** @var TestCase $this */
$media = Media::factory()->create();

$response = $this->get(route('filament.admin.resources.media.edit', $media));

$response->assertRedirect(route('filament.admin.auth.login'));
});

test('regular user not allowed', function () {
/** @var TestCase $this */
$user = User::factory()->create();
$media = Media::factory()->create();

$response = $this->actingAs($user)->get(route('filament.admin.resources.media.edit', $media));

$response->assertStatus(403);
});

test('Visible to admin', function () {
/** @var TestCase $this */
$media = Media::factory()->create(['title' => 'The Hobbit']);
$user = User::factory()->admin()->create();

$response = $this->actingAs($user)->get(route('filament.admin.resources.media.edit', $media));

$response->assertStatus(200);
$response->assertSeeText('Edit Media');
});
22 changes: 22 additions & 0 deletions tests/Feature/Livewire/Media/MediaPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use App\Models\Creator;
use App\Models\Media;
use App\Models\MediaEvent;
use App\Models\User;
use Illuminate\Support\Carbon;
use Livewire\Livewire;

Expand Down Expand Up @@ -106,5 +107,26 @@
->assertDontSee('Reading Book');
});

describe('admin edit link', function () {
test('guest user cannot set it', function () {
Livewire::test(MediaPage::class)
->assertDontSee('Edit');
});

test('regular users cannot set it', function () {
$this->actingAs(User::factory(['is_admin' => false])->create());

Livewire::test(MediaPage::class)
->assertDontSee('Edit');
});

test('admins can see it', function () {
$this->actingAs(User::factory(['is_admin' => true])->create());

Livewire::test(MediaPage::class)
->assertSee('Edit');
});
});

// TODO: Test filtering
});
7 changes: 5 additions & 2 deletions tests/Feature/Queries/Media/BacklogQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,25 @@
->create(['title' => 'Abandoned Media']);

// Create additional media with no events
Media::factory(['created_at' => Carbon::parse('2023-01-08')])
$backlogBook = Media::factory(['created_at' => Carbon::parse('2023-01-08')])
->book()
->for(Creator::factory(['name' => 'Author 4']))
->create(['title' => 'Backlog Book']);

Media::factory(['created_at' => Carbon::parse('2023-01-05')])
$backlogMovie = Media::factory(['created_at' => Carbon::parse('2023-01-05')])
->movie()
->create(['title' => 'Backlog Movie']);

$result = (new BacklogQuery)->execute();

expect($result)->toHaveCount(2);

expect($result->first()->id)->toBe($backlogBook->id);
expect($result->first()->title)->toBe('Backlog Book');
expect($result->first()->creator)->toBe('Author 4');
expect($result->first()->type)->toBe('book');
expect(Carbon::parse($result->first()->occurred_at)->format('Y F d'))->toBe('2023 January 08');

expect($result->last()->title)->toBe('Backlog Movie');
expect($result->last()->id)->toBe($backlogMovie->id);
});
8 changes: 6 additions & 2 deletions tests/Feature/Queries/Media/InProgressQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Support\Carbon;

test('example', function () {
Media::factory()
$inProgressBook = Media::factory()
->book()
->has(MediaEvent::factory()->started()->at(Carbon::parse('2024-12-29')), 'events')
// Leave Creator ID null to validate left join from media to creators
Expand All @@ -27,13 +27,17 @@
->game()
->create(['title' => 'Backlogged Game']);

Media::factory()
$inProgressTvShow = Media::factory()
->show()
->has(MediaEvent::factory()->started()->at(Carbon::parse('2025-01-01')), 'events')
->create(['title' => 'In Progress TV Show']);

$result = (new InProgressQuery)->execute();
$this->assertCount(2, $result);

$this->assertEquals('In Progress TV Show', $result->first()->title);
$this->assertEquals($inProgressTvShow->id, $result->first()->id);

$this->assertEquals('In Progress Book', $result->last()->title);
$this->assertEquals($inProgressBook->id, $result->last()->id);
});
3 changes: 2 additions & 1 deletion tests/Feature/Queries/Media/LogbookQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

test('1 item', function () {
/** @var TestCase $this */
Media::factory()
$media = Media::factory()
->book()
->for(Creator::factory(['name' => 'J.R.R. Tolkien']))
->has(MediaEvent::factory()->finished()->state(['occurred_at' => '2023-02-07']), 'events')
Expand All @@ -21,6 +21,7 @@
expect($result)->toHaveCount(1);

$first = $result->first();
expect($first->id)->toBe($media->id);
expect($first->title)->toBe('The Hobbit');
expect($first->creator)->toBe('J.R.R. Tolkien');
expect($first->type)->toBe('book');
Expand Down