Skip to content

Commit

Permalink
test: add tests for copy and view presentation actions
Browse files Browse the repository at this point in the history
  • Loading branch information
alkrauss48 committed Sep 4, 2024
1 parent ef040af commit 8276e6b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ protected function getHeaderActions(): array
->label('Save changes')
->action('save'),
Actions\ActionGroup::make([
Actions\Action::make('View')
Actions\Action::make('view')
->label('View')
->color('gray')
->url(fn (Presentation $record): string => route('presentations.show', [
'user' => $record->user->username,
'slug' => $record->slug,
]))
->icon('heroicon-o-arrow-top-right-on-square')
->openUrlInNewTab(),
CopyAction::make('Copy Share URL')
CopyAction::make('copyShareUrl')
->label('Copy Share URL')
->disabled(fn (Presentation $record) => ! $record->is_published)
->color('gray')
Expand Down
38 changes: 38 additions & 0 deletions tests/Filament/PresentationResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,42 @@

Queue::assertNotPushed(GenerateThumbnail::class);
});

it('can view the presentation', function () {
$record = Model::factory()->create([
'user_id' => $this->nonAdmin->id,
]);

livewire(EditResource::class, [
'record' => $record->getRouteKey(),
])
->assertActionHasUrl('view', route('presentations.show', [
'user' => $record->user->username,
'slug' => $record->slug,
]))
->assertActionShouldOpenUrlInNewTab('view');
});

it('can copy the share url of a published presentation', function () {
$record = Model::factory()->create([
'user_id' => $this->nonAdmin->id,
]);

livewire(EditResource::class, [
'record' => $record->getRouteKey(),
])
->assertActionEnabled('copyShareUrl');
});

it('can not copy the share url of a draft presentation', function () {
$record = Model::factory()->create([
'user_id' => $this->nonAdmin->id,
'is_published' => false,
]);

livewire(EditResource::class, [
'record' => $record->getRouteKey(),
])
->assertActionDisabled('copyShareUrl');
});
});

0 comments on commit 8276e6b

Please sign in to comment.