diff --git a/app/Filament/Resources/PresentationResource/Pages/EditPresentation.php b/app/Filament/Resources/PresentationResource/Pages/EditPresentation.php index e81c75e..a8b08cb 100644 --- a/app/Filament/Resources/PresentationResource/Pages/EditPresentation.php +++ b/app/Filament/Resources/PresentationResource/Pages/EditPresentation.php @@ -55,13 +55,13 @@ protected function getHeaderActions(): array return; } - // Note: If in the future we implement a websocket server, - // then we can implement an initial notification like this. - // - // Notification::make() - // ->title('Hang tight for just a sec, your thumbnail is being generated.') - // ->info() - // ->send(); + Notification::make() + ->title( + 'Hang tight, your thumbnail is being generated in ' + .'the background. Please refresh your browser in 5-10 ' + .'seconds.' + )->info() + ->send(); GenerateThumbnail::dispatch( presentation: $record, diff --git a/app/Http/Controllers/AdhocSlidesController.php b/app/Http/Controllers/AdhocSlidesController.php index f777f53..222f7f3 100644 --- a/app/Http/Controllers/AdhocSlidesController.php +++ b/app/Http/Controllers/AdhocSlidesController.php @@ -10,9 +10,7 @@ class AdhocSlidesController extends Controller { public function index(): Response { - dispatch(function () { - DailyView::createForAdhocPresentation(); - })->afterResponse(); + $this->dispatchDailyView(); return Inertia::render('Slides'); } @@ -23,9 +21,7 @@ public function show(string $slides): Response abort(404); } - dispatch(function () use ($slides) { - DailyView::createForAdhocPresentation(slug: $slides); - })->afterResponse(); + $this->dispatchDailyView(slug: $slides); return Inertia::render('Slides', [ 'slides' => $slides, @@ -45,4 +41,15 @@ private function isValidBase64String(string $value): bool return false; } + + private function dispatchDailyView(?string $slug = null): void + { + if (auth()->user()?->isAdministrator() ?? false) { + return; + } + + dispatch( + fn () => DailyView::createForAdhocPresentation(slug: $slug) + )->afterResponse(); + } } diff --git a/app/Jobs/GenerateThumbnail.php b/app/Jobs/GenerateThumbnail.php index 10b8916..50891af 100644 --- a/app/Jobs/GenerateThumbnail.php +++ b/app/Jobs/GenerateThumbnail.php @@ -57,10 +57,13 @@ public function handle(): void $this->presentation->clearMediaCollection('thumbnail'); $this->presentation->addMedia($tempPath)->toMediaCollection('thumbnail'); - Notification::make() - ->title('Thumbnail successfully generated. Refresh your page to view the new thumbnail.') - ->broadcast($this->user) - ->success() - ->send(); + // Note: If in the future we implement a websocket server, + // then we can implement a completed notification like this. + // + // Notification::make() + // ->title('Thumbnail successfully generated. Refresh your page to view the new thumbnail.') + // ->broadcast($this->user) + // ->success() + // ->send(); } } diff --git a/resources/js/lib/textFit.js b/resources/js/lib/textFit.js index 94fa3b5..8f6363f 100644 --- a/resources/js/lib/textFit.js +++ b/resources/js/lib/textFit.js @@ -36,6 +36,11 @@ var defaultSettings = { export default function textFit(els, options) { + // Vitest doesn't always play nicely with textFit + if (process.env.NODE_ENV === 'test') { + return; + } + if (!options) options = {}; // Extend options. diff --git a/resources/js/test/components/SlideView.loop.test.ts b/resources/js/test/components/SlideView.loop.test.ts index 5503859..83b67da 100644 --- a/resources/js/test/components/SlideView.loop.test.ts +++ b/resources/js/test/components/SlideView.loop.test.ts @@ -51,3 +51,17 @@ test('loopInterval is not cleared on invalid key press', async () => { expect(spy).toHaveBeenCalledTimes(0); }); + +test('slide increments with loop timer', async () => { + vi.useFakeTimers(); + + const wrapper = mountWrapper(); + + expect(slideStore.index).toBe(1); + + vi + .advanceTimersToNextTimer() // Font load interval + .advanceTimersToNextTimer(); + + expect(slideStore.index).toBe(2); +}); diff --git a/tests/Feature/AdhocSlidesControllerTest.php b/tests/Feature/AdhocSlidesControllerTest.php index 8450079..75b6d45 100644 --- a/tests/Feature/AdhocSlidesControllerTest.php +++ b/tests/Feature/AdhocSlidesControllerTest.php @@ -1,6 +1,7 @@ get(route('home')); + $this->get(route('home')); $this->assertDatabaseHas(DailyView::class, [ 'adhoc_slug' => null, ]); }); + + test('adhoc slides index screen does not generate daily view for admin user', function () { + $admin = User::factory()->admin()->create(); + + $this + ->actingAs($admin) + ->get(route('home')); + + $this->assertDatabaseMissing(DailyView::class, [ + 'adhoc_slug' => null, + ]); + }); }); describe('Show', function () { @@ -36,7 +49,7 @@ }); test('adhoc slides show screen generate daily view', function () { - $response = $this->get(route('adhoc-slides.show', [ + $this->get(route('adhoc-slides.show', [ 'slides' => base64_encode('foo'), ])); @@ -46,7 +59,7 @@ }); test('adhoc slides show screen will not generate daily view with invalid slug', function () { - $response = $this->get(route('adhoc-slides.show', [ + $this->get(route('adhoc-slides.show', [ 'slides' => 'foo', // Not base64 encoded ])); @@ -54,4 +67,18 @@ 'adhoc_slug' => 'foo', ]); }); + + test('adhoc slides show screen does not generate daily view for admin user', function () { + $admin = User::factory()->admin()->create(); + + $this + ->actingAs($admin) + ->get(route('adhoc-slides.show', [ + 'slides' => base64_encode('foo'), + ])); + + $this->assertDatabaseMissing(DailyView::class, [ + 'adhoc_slug' => base64_encode('foo'), + ]); + }); });