This commit is contained in:
2026-03-20 21:17:26 +01:00
parent 1a62fcb81d
commit 29c3ff8572
229 changed files with 13147 additions and 2577 deletions

View File

@@ -0,0 +1,111 @@
<?php
declare(strict_types=1);
use App\Models\Artwork;
use App\Models\ArtworkComment;
use App\Models\DashboardPreference;
use App\Models\Notification;
use App\Models\User;
use Illuminate\Support\Facades\DB;
it('embeds dashboard overview counts for the authenticated user', function () {
$user = User::factory()->create([
'email_verified_at' => now(),
]);
$follower = User::factory()->create();
$followed = User::factory()->create();
$commenter = User::factory()->create();
$artwork = Artwork::factory()->create([
'user_id' => $user->id,
'is_approved' => true,
'is_public' => true,
'published_at' => now()->subDay(),
]);
DB::table('user_followers')->insert([
[
'user_id' => $user->id,
'follower_id' => $follower->id,
'created_at' => now(),
],
[
'user_id' => $followed->id,
'follower_id' => $user->id,
'created_at' => now(),
],
]);
DB::table('artwork_favourites')->insert([
'user_id' => $user->id,
'artwork_id' => $artwork->id,
'created_at' => now(),
'updated_at' => now(),
]);
Notification::query()->create([
'user_id' => $user->id,
'type' => 'comment',
'data' => [
'message' => 'Unread dashboard notification',
'url' => '/dashboard/notifications',
],
'read_at' => null,
]);
ArtworkComment::factory()->create([
'artwork_id' => $artwork->id,
'user_id' => $commenter->id,
'content' => 'Unread dashboard comment',
'raw_content' => 'Unread dashboard comment',
'rendered_content' => '<p>Unread dashboard comment</p>',
'is_approved' => true,
]);
$response = $this->actingAs($user)->get('/dashboard');
$response->assertOk()->assertSee('data-overview=', false);
$overview = $response->viewData('dashboard_overview');
$preferences = $response->viewData('dashboard_preferences');
expect($overview)->toMatchArray([
'artworks' => 1,
'stories' => 0,
'followers' => 1,
'following' => 1,
'favorites' => 1,
'notifications' => $user->unreadNotifications()->count(),
'received_comments' => 1,
]);
expect($preferences)->toMatchArray([
'pinned_spaces' => [],
]);
});
it('embeds saved pinned dashboard spaces for the authenticated user', function () {
$user = User::factory()->create([
'email_verified_at' => now(),
]);
DashboardPreference::query()->create([
'user_id' => $user->id,
'pinned_spaces' => [
'/dashboard/notifications',
'/studio',
],
]);
$response = $this->actingAs($user)->get('/dashboard');
$response->assertOk();
expect($response->viewData('dashboard_preferences'))->toMatchArray([
'pinned_spaces' => [
'/dashboard/notifications',
'/studio',
],
]);
});

View File

@@ -0,0 +1,67 @@
<?php
declare(strict_types=1);
use App\Models\DashboardPreference;
use App\Models\User;
it('persists sanitized pinned dashboard spaces for the authenticated user', function () {
$user = User::factory()->create([
'email_verified_at' => now(),
]);
$response = $this->actingAs($user)->putJson('/api/dashboard/preferences/shortcuts', [
'pinned_spaces' => [
'/dashboard/notifications',
'/dashboard/notifications',
'/dashboard/comments/received',
'/not-allowed',
'/studio',
],
]);
$response
->assertOk()
->assertJson([
'data' => [
'pinned_spaces' => [
'/dashboard/notifications',
'/dashboard/comments/received',
'/studio',
],
],
]);
expect(DashboardPreference::query()->find($user->id)?->pinned_spaces)->toBe([
'/dashboard/notifications',
'/dashboard/comments/received',
'/studio',
]);
});
it('allows clearing all pinned dashboard spaces for the authenticated user', function () {
$user = User::factory()->create([
'email_verified_at' => now(),
]);
DashboardPreference::query()->create([
'user_id' => $user->id,
'pinned_spaces' => [
'/dashboard/notifications',
],
]);
$response = $this->actingAs($user)->putJson('/api/dashboard/preferences/shortcuts', [
'pinned_spaces' => [],
]);
$response
->assertOk()
->assertJson([
'data' => [
'pinned_spaces' => [],
],
]);
expect(DashboardPreference::query()->find($user->id)?->pinned_spaces)->toBe([]);
});

View File

@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
use App\Models\Notification;
use App\Models\User;
it('renders the dashboard notifications page for an authenticated user', function () {
$user = User::factory()->create();
Notification::query()->create([
'user_id' => $user->id,
'type' => 'comment',
'data' => [
'type' => 'comment',
'message' => 'Someone commented on your artwork',
'url' => '/dashboard/comments/received',
],
'read_at' => null,
]);
$response = $this->actingAs($user)->get('/dashboard/notifications');
$response
->assertOk()
->assertSee('Notifications', false)
->assertSee('Someone commented on your artwork', false)
->assertSee('Unread', false);
});

View File

@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
use App\Models\Artwork;
use App\Models\ArtworkComment;
use App\Models\User;
use App\Services\ReceivedCommentsInboxService;
use Illuminate\Support\Carbon;
it('tracks unread received comments and clears them when the inbox is opened', function () {
Carbon::setTestNow('2026-03-19 12:00:00');
$owner = User::factory()->create();
$commenter = User::factory()->create();
$artwork = Artwork::factory()->create([
'user_id' => $owner->id,
'is_approved' => true,
'is_public' => true,
'published_at' => now()->subDay(),
]);
$firstComment = ArtworkComment::factory()->create([
'artwork_id' => $artwork->id,
'user_id' => $commenter->id,
'content' => 'First unread comment',
'raw_content' => 'First unread comment',
'rendered_content' => '<p>First unread comment</p>',
'is_approved' => true,
'created_at' => now()->subMinute(),
'updated_at' => now()->subMinute(),
]);
$service = app(ReceivedCommentsInboxService::class);
expect($service->unreadCountForUser($owner))->toBe(1);
$this->actingAs($owner)
->get('/dashboard/comments/received')
->assertOk()
->assertSee('Marked 1 new comment as read', false);
$this->assertDatabaseHas('user_received_comment_reads', [
'user_id' => $owner->id,
'artwork_comment_id' => $firstComment->id,
]);
expect($service->unreadCountForUser($owner))->toBe(0);
Carbon::setTestNow('2026-03-19 12:05:00');
ArtworkComment::factory()->create([
'artwork_id' => $artwork->id,
'user_id' => $commenter->id,
'content' => 'Second unread comment',
'raw_content' => 'Second unread comment',
'rendered_content' => '<p>Second unread comment</p>',
'is_approved' => true,
'created_at' => now(),
'updated_at' => now(),
]);
expect($service->unreadCountForUser($owner))->toBe(1);
Carbon::setTestNow();
});