complete story 14.5

This commit is contained in:
Naser Mansour
2026-01-09 17:18:27 +02:00
parent 88961e11b4
commit 49aeceb25c
6 changed files with 319 additions and 18 deletions
+187
View File
@@ -1,5 +1,7 @@
<?php
use App\Models\Post;
test('home page is accessible', function () {
$this->get('/')
->assertOk();
@@ -369,3 +371,188 @@ test('home page displays social innovation value in Arabic', function () {
->assertOk()
->assertSee('الابتكار الاجتماعي');
});
// Latest Posts Section Tests
test('home page does not display posts section when no published posts exist', function () {
// No posts created
$this->get('/')
->assertOk()
->assertDontSee('id="posts"', false);
});
test('home page displays posts section when published posts exist', function () {
Post::factory()->published()->count(3)->create();
$this->get('/')
->assertOk()
->assertSee('id="posts"', false);
});
test('home page displays posts section title in English', function () {
Post::factory()->published()->create();
$this->withSession(['locale' => 'en'])
->get('/')
->assertOk()
->assertSee('Latest Articles');
});
test('home page displays posts section title in Arabic', function () {
Post::factory()->published()->create();
$this->withSession(['locale' => 'ar'])
->get('/')
->assertOk()
->assertSee('أحدث المقالات');
});
test('home page displays maximum 3 latest posts', function () {
// Create 5 published posts
Post::factory()->published()->count(5)->create();
$response = $this->get('/');
$response->assertOk();
// The section should exist
$response->assertSee('id="posts"', false);
// Count the number of post cards (articles with specific class)
$content = $response->getContent();
$postCardCount = substr_count($content, 'class="bg-card p-6 rounded-lg shadow-card hover:shadow-card-hover transition-shadow"');
expect($postCardCount)->toBe(3);
});
test('home page displays post titles', function () {
$post = Post::factory()->published()->create([
'title' => ['en' => 'Test English Title', 'ar' => 'عنوان اختبار'],
]);
$this->withSession(['locale' => 'en'])
->get('/')
->assertOk()
->assertSee('Test English Title');
});
test('home page displays post titles in Arabic', function () {
$post = Post::factory()->published()->create([
'title' => ['en' => 'Test English Title', 'ar' => 'عنوان اختبار عربي'],
]);
$this->withSession(['locale' => 'ar'])
->get('/')
->assertOk()
->assertSee('عنوان اختبار عربي');
});
test('home page displays post excerpt', function () {
$post = Post::factory()->published()->create([
'body' => ['en' => 'This is a test body content for the post that should be truncated.', 'ar' => 'هذا محتوى اختبار'],
]);
$this->withSession(['locale' => 'en'])
->get('/')
->assertOk()
->assertSee('This is a test body content');
});
test('home page displays read more link in English', function () {
Post::factory()->published()->create();
$this->withSession(['locale' => 'en'])
->get('/')
->assertOk()
->assertSee('Read More');
});
test('home page displays read more link in Arabic', function () {
Post::factory()->published()->create();
$this->withSession(['locale' => 'ar'])
->get('/')
->assertOk()
->assertSee('اقرأ المزيد');
});
test('home page displays view all posts link in English', function () {
Post::factory()->published()->create();
$this->withSession(['locale' => 'en'])
->get('/')
->assertOk()
->assertSee('View All Articles');
});
test('home page displays view all posts link in Arabic', function () {
Post::factory()->published()->create();
$this->withSession(['locale' => 'ar'])
->get('/')
->assertOk()
->assertSee('عرض جميع المقالات');
});
test('home page view all posts links to posts index', function () {
Post::factory()->published()->create();
$this->get('/')
->assertOk()
->assertSee('href="'.route('posts.index').'"', false);
});
test('home page post title links to post show page', function () {
$post = Post::factory()->published()->create();
$this->get('/')
->assertOk()
->assertSee('href="'.route('posts.show', $post).'"', false);
});
test('home page only shows published posts not drafts', function () {
$publishedPost = Post::factory()->published()->create([
'title' => ['en' => 'Published Post Title', 'ar' => 'منشور'],
]);
$draftPost = Post::factory()->draft()->create([
'title' => ['en' => 'Draft Post Title', 'ar' => 'مسودة'],
]);
$this->withSession(['locale' => 'en'])
->get('/')
->assertOk()
->assertSee('Published Post Title')
->assertDontSee('Draft Post Title');
});
test('home page displays posts in order of latest published first', function () {
$oldPost = Post::factory()->published()->create([
'title' => ['en' => 'Old Post', 'ar' => 'قديم'],
'published_at' => now()->subDays(10),
]);
$newPost = Post::factory()->published()->create([
'title' => ['en' => 'New Post', 'ar' => 'جديد'],
'published_at' => now()->subDay(),
]);
$response = $this->withSession(['locale' => 'en'])->get('/');
$response->assertOk();
$content = $response->getContent();
$newPostPosition = strpos($content, 'New Post');
$oldPostPosition = strpos($content, 'Old Post');
// New post should appear before old post
expect($newPostPosition)->toBeLessThan($oldPostPosition);
});
test('home page displays post publication date', function () {
$post = Post::factory()->published()->create([
'published_at' => now()->setDate(2026, 1, 15),
]);
$this->withSession(['locale' => 'en'])
->get('/')
->assertOk()
->assertSee('15 January 2026');
});