This commit is contained in:
2026-02-21 19:26:48 +01:00
parent 7648e7d426
commit e4e0bdf8f1
53 changed files with 747 additions and 176 deletions

View File

@@ -0,0 +1,61 @@
<?php
namespace Tests\Feature;
use App\Models\Artwork;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Tests\TestCase;
class DashboardFavoritesTest extends TestCase
{
use RefreshDatabase;
public function test_guest_is_redirected_from_favorites(): void
{
$this->get('/dashboard/favorites')->assertRedirect('/login');
}
public function test_authenticated_user_sees_favourites_and_can_remove(): void
{
$user = User::factory()->create();
$art = Artwork::factory()->create(['user_id' => $user->id, 'title' => 'Fav Artwork']);
$favTable = Schema::hasTable('user_favorites') ? 'user_favorites' : (Schema::hasTable('favourites') ? 'favourites' : null);
if (! $favTable) {
$this->markTestSkipped('No favorites table available in schema');
return;
}
// insert using whichever timestamp column exists on the fav table
$col = null;
foreach (['datum', 'created_at', 'created', 'date'] as $c) {
if (Schema::hasColumn($favTable, $c)) {
$col = $c;
break;
}
}
$insert = [
'user_id' => $user->id,
'artwork_id' => $art->id,
];
if ($col) {
$insert[$col] = now();
}
DB::table($favTable)->insert($insert);
$this->actingAs($user)
->get(route('dashboard.favorites'))
->assertOk()
->assertSee('Fav Artwork');
$this->actingAs($user)
->delete(route('dashboard.favorites.destroy', ['artwork' => $art->id]))
->assertRedirect(route('dashboard.favorites'));
$this->assertDatabaseMissing($favTable, ['user_id' => $user->id, 'artwork_id' => $art->id]);
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace Tests\Feature;
use App\Models\Artwork;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class DashboardGalleryTest extends TestCase
{
use RefreshDatabase;
public function test_guest_is_redirected_from_dashboard_gallery(): void
{
$this->get('/dashboard/gallery')->assertRedirect('/login');
}
public function test_authenticated_user_sees_gallery(): void
{
$user = User::factory()->create();
$art = Artwork::factory()->create(['user_id' => $user->id, 'title' => 'Test Artwork']);
$this->actingAs($user)
->get(route('dashboard.gallery'))
->assertOk()
->assertSee('My Gallery')
->assertSee('Test Artwork');
}
}

21
tests/e2e/gallery.spec.ts Normal file
View File

@@ -0,0 +1,21 @@
import { test, expect } from '@playwright/test';
test('public /browse shows 5 (or more) columns on large screen', async ({ page }) => {
// use a very wide viewport to emulate a large desktop where 5 columns should fit
await page.setViewportSize({ width: 2000, height: 1200 });
await page.goto('/browse');
await page.waitForSelector('[data-gallery-grid]');
// hide sidebar and force gallery width so we can assert column layout in CI
await page.addStyleTag({ content: 'aside#sidebar{display:none !important} main{width:100% !important} [data-gallery-grid].force-5{grid-template-columns: repeat(5, minmax(0,1fr)) !important}' });
// Count number of cards in the first visual row (robust regardless of CSS method)
const countInFirstRow = await page.$$eval('[data-gallery-grid] > .nova-card', (cards) => {
if (!cards || cards.length === 0) return 0;
const rects = cards.map(c => c.getBoundingClientRect());
const firstTop = rects[0].top;
return rects.filter(r => Math.abs(r.top - firstTop) < 2).length;
});
console.log('cards in first row:', countInFirstRow);
expect(countInFirstRow).toBeGreaterThanOrEqual(5);
});