complete story 5.5 with qa tests

This commit is contained in:
Naser Mansour
2025-12-27 02:16:05 +02:00
parent 6eef462732
commit e7c9284557
6 changed files with 477 additions and 27 deletions
+152
View File
@@ -153,3 +153,155 @@ test('individual post page displays content in current locale', function () {
->assertSee('عنوان عربي')
->assertSee('محتوى عربي');
});
// Search functionality tests
test('search input is displayed on posts listing page', function () {
$this->withSession(['locale' => 'en'])
->get(route('posts.index'))
->assertOk()
->assertSee('Search posts...');
});
test('search filters posts by English title', function () {
Post::factory()->published()->create([
'title' => ['en' => 'Legal Rights Guide', 'ar' => 'دليل الحقوق القانونية'],
]);
Post::factory()->published()->create([
'title' => ['en' => 'Tax Information', 'ar' => 'معلومات ضريبية'],
]);
app()->setLocale('en');
// Title is highlighted, so we check for parts that won't be in the mark tag
// "Legal" will be in <mark>, "Rights Guide" will be after
Livewire\Volt\Volt::test('pages.posts.index')
->set('search', 'Legal')
->assertSee('Rights Guide') // Part after the highlighted word
->assertSee('Legal') // The highlighted word (inside <mark>)
->assertDontSee('Tax Information');
});
test('search filters posts by Arabic title', function () {
Post::factory()->published()->create([
'title' => ['en' => 'Legal Rights Guide', 'ar' => 'دليل الحقوق القانونية'],
]);
Post::factory()->published()->create([
'title' => ['en' => 'Tax Information', 'ar' => 'معلومات ضريبية'],
]);
app()->setLocale('ar');
// Search for "الحقوق" (rights) - should find first post only
$component = Livewire\Volt\Volt::test('pages.posts.index')
->set('search', 'الحقوق');
// Check we have results (not "no results")
$html = $component->html();
expect(str_contains($html, 'تم العثور'))->toBeTrue('Should show found results message');
// Check the highlighted word appears
$component->assertSee('الحقوق') // The highlighted word
->assertDontSee('ضريبية'); // Part of second post
});
test('search filters posts by body content', function () {
Post::factory()->published()->create([
'title' => ['en' => 'First Article', 'ar' => 'المقال الأول'],
'body' => ['en' => 'This discusses property law topics.', 'ar' => 'هذا يناقش مواضيع قانون الملكية.'],
]);
Post::factory()->published()->create([
'title' => ['en' => 'Second Article', 'ar' => 'المقال الثاني'],
'body' => ['en' => 'This is about family matters.', 'ar' => 'هذا يتعلق بشؤون الأسرة.'],
]);
app()->setLocale('en');
// Searching body content - title doesn't contain 'property' so won't be highlighted
Livewire\Volt\Volt::test('pages.posts.index')
->set('search', 'property')
->assertSee('First Article') // This title has no highlight since match is in body
->assertDontSee('Second Article');
});
test('search shows no results message when no matches found', function () {
Post::factory()->published()->create([
'title' => ['en' => 'Test Post', 'ar' => 'مقال اختبار'],
]);
app()->setLocale('en');
Livewire\Volt\Volt::test('pages.posts.index')
->set('search', 'nonexistent')
->assertSee('No results found');
});
test('search only searches published posts', function () {
Post::factory()->draft()->create([
'title' => ['en' => 'Draft Article', 'ar' => 'مقال مسودة'],
]);
Post::factory()->published()->create([
'title' => ['en' => 'Published Article', 'ar' => 'مقال منشور'],
]);
app()->setLocale('en');
// Search for "Article" - both have it in title, but only published should appear
// "Article" will be highlighted in "Published Article"
Livewire\Volt\Volt::test('pages.posts.index')
->set('search', 'Article')
->assertSee('Published') // Part of the title without highlight
->assertSee('Article') // The highlighted word
->assertDontSee('Draft');
});
test('clear search button resets search and shows all posts', function () {
Post::factory()->published()->create([
'title' => ['en' => 'Alpha Article', 'ar' => 'المقال الأول'],
]);
Post::factory()->published()->create([
'title' => ['en' => 'Beta Article', 'ar' => 'المقال الثاني'],
]);
app()->setLocale('en');
Livewire\Volt\Volt::test('pages.posts.index')
->set('search', 'Alpha')
->assertSee('Alpha') // Highlighted in "Alpha Article"
->assertDontSee('Beta')
->call('clearSearch')
->assertSet('search', '')
->assertSee('Alpha Article') // No highlighting after clear
->assertSee('Beta Article');
});
test('search is case insensitive', function () {
Post::factory()->published()->create([
'title' => ['en' => 'UPPERCASE TITLE', 'ar' => 'عنوان كبير'],
]);
app()->setLocale('en');
// Search lowercase "uppercase" should find "UPPERCASE TITLE"
// Note: "uppercase" will be highlighted (case preserved in original)
Livewire\Volt\Volt::test('pages.posts.index')
->set('search', 'uppercase')
->assertSee('UPPERCASE') // The highlighted word
->assertSee('TITLE'); // Rest of title
});
test('search resets pagination', function () {
Post::factory()->count(15)->published()->create();
Post::factory()->published()->create([
'title' => ['en' => 'Special Searchable Post', 'ar' => 'مقال قابل للبحث خاص'],
]);
$component = Livewire\Volt\Volt::test('pages.posts.index');
// Navigate to page 2
$component->call('gotoPage', 2);
// Set search - should reset to page 1
$component->set('search', 'Special')
->assertSet('paginators.page', 1);
});