Files
ghassanandClaude Opus 4.7 fa4e09ad62 test(phase-2): perf and DOM regression tests + delete 300 lines of dead CSS
Seven feature tests covering:
- the per-card edit modal is gone (id="editVideoModal{slug}" and the
  .cute-edit-modal class),
- owner sees Edit/Delete and no Report/Not-interested,
- non-owner sees Report/Not-interested and no Edit/Delete,
- card thumbnail img carries width/height and loading="lazy",
- feedMore returns JSON with items + next_cursor + has_more,
- feedMore rejects unknown filters by returning an empty slice,
- comments component ships the reply <template>, not inline forms.

While wiring these up I also deleted the 300-line .cute-edit-modal CSS
block that was still shipping in card-styles.blade.php even though its
markup was removed in the previous commit — the CSS was pointing at
IDs that no longer exist.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2026-10-21 00:54:55 +03:00

176 lines
6.5 KiB
PHP

<?php
namespace Tests\Feature;
use App\Http\Middleware\VerifyCsrfToken;
use App\Models\User;
use App\Models\Video;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
/**
* Phase 2 — Performance and DOM. Guards against regressions in the shared
* edit modal, owner-only menu items, thumbnail layout-shift attrs, and the
* cursor-paginated feed endpoint.
*/
class Phase2PerfTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
putenv('DB_CONNECTION=sqlite');
putenv('DB_DATABASE=:memory:');
$_ENV['DB_CONNECTION'] = 'sqlite';
$_ENV['DB_DATABASE'] = ':memory:';
parent::setUp();
$this->withoutMiddleware([
VerifyCsrfToken::class,
\Illuminate\Session\Middleware\AuthenticateSession::class,
]);
}
// ─── Shared edit modal: per-card copy is gone ─────
public function test_video_card_does_not_render_a_per_card_edit_modal(): void
{
[$user, $video] = $this->makeUserAndVideo();
$this->actingAs($user);
$html = view('components.video-card', ['video' => $video])->render();
// The dead per-card modal used id="editVideoModal{slug}" and the class
// "cute-edit-modal". If either reappears, we're back to shipping 100
// extra lines per card.
$this->assertStringNotContainsString('editVideoModal' . $video->getRouteKey(), $html);
$this->assertStringNotContainsString('cute-edit-modal', $html);
}
// ─── Owner-only menu items ────────────────────────
public function test_owner_sees_edit_delete_items_in_card_menu(): void
{
[$owner, $video] = $this->makeUserAndVideo();
$this->actingAs($owner);
$html = view('components.video-card', ['video' => $video])->render();
$this->assertStringContainsString('openEditVideoModal', $html);
$this->assertStringContainsString('showDeleteModal', $html);
$this->assertStringNotContainsString('notInterested', $html);
$this->assertStringNotContainsString('dontRecommendChannel', $html);
$this->assertStringNotContainsString('reportVideo', $html);
}
public function test_non_owner_sees_report_items_but_not_edit(): void
{
[$owner, $video] = $this->makeUserAndVideo();
$viewer = User::factory()->create([
'username' => 'v'.substr(bin2hex(random_bytes(4)), 0, 8),
]);
$this->actingAs($viewer);
$html = view('components.video-card', ['video' => $video])->render();
$this->assertStringNotContainsString('openEditVideoModal', $html);
$this->assertStringNotContainsString('showDeleteModal', $html);
$this->assertStringContainsString('notInterested', $html);
$this->assertStringContainsString('reportVideo', $html);
}
// ─── Thumbnail layout-shift attributes ────────────
public function test_thumbnail_image_has_width_and_height(): void
{
[$user, $video] = $this->makeUserAndVideo();
$this->actingAs($user);
$html = view('components.video-card', ['video' => $video])->render();
$this->assertMatchesRegularExpression(
'/<img[^>]*width="320"[^>]*height="180"/i',
$html,
'Thumbnail img must carry explicit width/height so the browser reserves layout space.'
);
$this->assertStringContainsString('loading="lazy"', $html);
}
// ─── Cursor-paginated feed endpoint ───────────────
public function test_feed_more_returns_json_with_cards_and_next_cursor(): void
{
$user = User::factory()->create([
'username' => 'f'.substr(bin2hex(random_bytes(4)), 0, 8),
]);
// Twice the page size so the cursor must advance.
for ($i = 0; $i < 30; $i++) {
Video::create([
'user_id' => $user->id,
'title' => 'Vid ' . $i,
'description' => '',
'filename' => "users/x/videos/y{$i}/video.mp4",
'path' => "users/x/videos/y{$i}/video.mp4",
'type' => 'generic',
'visibility' => 'public',
'status' => 'ready',
'share_token' => bin2hex(random_bytes(8)),
]);
}
$r = $this->getJson(route('videos.feed.more', ['filter' => 'all']));
$r->assertOk();
$r->assertJsonStructure(['items', 'next_cursor', 'has_more']);
$this->assertTrue($r->json('has_more'), 'With 30 videos and a 24-page size, has_more must be true.');
$this->assertNotEmpty($r->json('next_cursor'));
$this->assertStringContainsString('yt-video-card', (string) $r->json('items'));
}
public function test_feed_more_unknown_filter_returns_empty_slice(): void
{
$this->getJson(route('videos.feed.more', ['filter' => 'nonsense']))
->assertOk()
->assertJson(['items' => '', 'has_more' => false]);
}
// ─── Lazy reply-form template present ─────────────
public function test_comments_component_ships_the_reply_template_not_inline_forms(): void
{
[$user, $video] = $this->makeUserAndVideo();
\App\Models\Comment::create([
'user_id' => $user->id,
'video_id' => $video->id,
'body' => 'top-level comment',
]);
$this->actingAs($user);
$html = view('components.video-comments', ['video' => $video])->render();
$this->assertStringContainsString('id="ytc-reply-form-tpl"', $html);
$this->assertStringContainsString('ytc-reply-slot', $html);
}
// ─── Helpers ──────────────────────────────────────
private function makeUserAndVideo(): array
{
$user = User::factory()->create([
'username' => 'u'.substr(bin2hex(random_bytes(4)), 0, 8),
]);
$video = Video::create([
'user_id' => $user->id,
'title' => 'Test video',
'description'=> 'Hello',
'filename' => 'users/x/videos/y/video.mp4',
'path' => 'users/x/videos/y/video.mp4',
'type' => 'generic',
'visibility' => 'public',
'status' => 'ready',
'share_token' => bin2hex(random_bytes(8)),
]);
return [$user, $video];
}
}