admin = User::factory()->admin()->create(); }); // =========================================== // Index Page Tests // =========================================== test('admin can view posts index', function () { $this->actingAs($this->admin) ->get(route('admin.posts.index')) ->assertOk(); }); test('admin can see list of posts', function () { $post = Post::factory()->create([ 'title' => ['ar' => 'عنوان عربي', 'en' => 'English Title'], ]); $this->actingAs($this->admin); app()->setLocale('en'); // Check the post appears in the view $this->get(route('admin.posts.index')) ->assertOk() ->assertSee('English Title'); }); test('posts list shows status badges', function () { Post::factory()->draft()->create(); Post::factory()->published()->create(); $this->actingAs($this->admin); $component = Volt::test('admin.posts.index'); expect($component->viewData('posts')->total())->toBe(2); }); test('admin can filter posts by status', function () { Post::factory()->draft()->create(); Post::factory()->published()->create(); $this->actingAs($this->admin); $component = Volt::test('admin.posts.index') ->set('statusFilter', 'draft'); expect($component->viewData('posts')->total())->toBe(1); expect($component->viewData('posts')->first()->status)->toBe(PostStatus::Draft); }); test('admin can search posts by title', function () { Post::factory()->create(['title' => ['ar' => 'عنوان أول', 'en' => 'First Post']]); Post::factory()->create(['title' => ['ar' => 'عنوان ثاني', 'en' => 'Second Post']]); $this->actingAs($this->admin); $component = Volt::test('admin.posts.index') ->set('search', 'First'); expect($component->viewData('posts')->total())->toBe(1); }); // =========================================== // Create Page Tests // =========================================== test('admin can view post creation form', function () { $this->actingAs($this->admin) ->get(route('admin.posts.create')) ->assertOk(); }); test('admin can create post with valid bilingual content', function () { $this->actingAs($this->admin); Volt::test('admin.posts.create') ->set('title_ar', 'عنوان المقال') ->set('title_en', 'Article Title') ->set('body_ar', '
محتوى المقال
') ->set('body_en', 'Article content
') ->call('saveDraft') ->assertHasNoErrors(); expect(Post::where('title->en', 'Article Title')->exists())->toBeTrue(); }); test('create post fails with missing required fields', function () { $this->actingAs($this->admin); Volt::test('admin.posts.create') ->set('title_ar', '') ->set('title_en', 'Title') ->set('body_ar', 'content') ->set('body_en', 'content') ->call('save') ->assertHasErrors(['title_ar']); }); test('save draft preserves draft status', function () { $this->actingAs($this->admin); Volt::test('admin.posts.create') ->set('title_ar', 'عنوان') ->set('title_en', 'Title') ->set('body_ar', 'محتوى') ->set('body_en', 'Content') ->call('saveDraft'); expect(Post::first()->status)->toBe(PostStatus::Draft); }); test('publish changes status to published', function () { $this->actingAs($this->admin); Volt::test('admin.posts.create') ->set('title_ar', 'عنوان') ->set('title_en', 'Title') ->set('body_ar', 'محتوى') ->set('body_en', 'Content') ->call('publish'); expect(Post::first()->status)->toBe(PostStatus::Published); expect(Post::first()->published_at)->not->toBeNull(); }); test('HTML sanitization removes script tags but keeps allowed formatting', function () { $this->actingAs($this->admin); Volt::test('admin.posts.create') ->set('title_ar', 'عنوان') ->set('title_en', 'Title') ->set('body_ar', 'نص
') ->set('body_en', 'Safe
Bold') ->call('saveDraft'); $post = Post::first(); expect($post->body['en'])->not->toContain('