Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Update daily view dispatching and add loop test #26

Merged
merged 3 commits into from
Jun 1, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 13 additions & 6 deletions app/Http/Controllers/AdhocSlidesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class AdhocSlidesController extends Controller
{
public function index(): Response
{
dispatch(function () {
DailyView::createForAdhocPresentation();
})->afterResponse();
$this->dispatchDailyView();

return Inertia::render('Slides');
}
Expand All @@ -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,
Expand All @@ -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();
}
}
13 changes: 8 additions & 5 deletions app/Jobs/GenerateThumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
5 changes: 5 additions & 0 deletions resources/js/lib/textFit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions resources/js/test/components/SlideView.loop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
33 changes: 30 additions & 3 deletions tests/Feature/AdhocSlidesControllerTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use App\Models\DailyView;
use App\Models\User;

describe('Index', function () {
test('adhoc slides index screen can be rendered', function () {
Expand All @@ -10,12 +11,24 @@
});

test('adhoc slides index screen generate daily view', function () {
$response = $this->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 () {
Expand All @@ -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'),
]));

Expand All @@ -46,12 +59,26 @@
});

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
]));

$this->assertDatabaseMissing(DailyView::class, [
'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'),
]);
});
});
Loading