admin = User::factory()->admin()->create(); // Ensure test pages exist Page::factory()->terms()->create(); Page::factory()->privacy()->create(); }); // =========================================== // Admin Index Page Tests // =========================================== test('admin can view legal pages list', function () { $this->actingAs($this->admin) ->get(route('admin.pages.index')) ->assertOk() ->assertSee('Terms of Service') ->assertSee('Privacy Policy'); }); test('legal pages list shows both pages', function () { $this->actingAs($this->admin); $component = Volt::test('admin.pages.index'); expect($component->viewData('pages')->count())->toBe(2); }); // =========================================== // Admin Edit Page Tests // =========================================== test('admin can view terms edit page', function () { $this->actingAs($this->admin) ->get(route('admin.pages.edit', 'terms')) ->assertOk(); }); test('admin can view privacy edit page', function () { $this->actingAs($this->admin) ->get(route('admin.pages.edit', 'privacy')) ->assertOk(); }); test('admin can edit terms of service in Arabic', function () { $page = Page::where('slug', 'terms')->first(); $this->actingAs($this->admin); Volt::test('admin.pages.edit', ['slug' => 'terms']) ->set('content_ar', '

شروط الخدمة الجديدة

') ->call('save') ->assertHasNoErrors(); expect($page->fresh()->content_ar)->toContain('شروط الخدمة الجديدة'); }); test('admin can edit terms of service in English', function () { $page = Page::where('slug', 'terms')->first(); $this->actingAs($this->admin); Volt::test('admin.pages.edit', ['slug' => 'terms']) ->set('content_en', '

New terms content

') ->call('save') ->assertHasNoErrors(); expect($page->fresh()->content_en)->toContain('New terms content'); }); test('admin can edit privacy policy in Arabic', function () { $page = Page::where('slug', 'privacy')->first(); $this->actingAs($this->admin); Volt::test('admin.pages.edit', ['slug' => 'privacy']) ->set('content_ar', '

سياسة الخصوصية الجديدة

') ->call('save') ->assertHasNoErrors(); expect($page->fresh()->content_ar)->toContain('سياسة الخصوصية الجديدة'); }); test('admin can edit privacy policy in English', function () { $page = Page::where('slug', 'privacy')->first(); $this->actingAs($this->admin); Volt::test('admin.pages.edit', ['slug' => 'privacy']) ->set('content_en', '

New privacy policy

') ->call('save') ->assertHasNoErrors(); expect($page->fresh()->content_en)->toContain('New privacy policy'); }); test('admin can preview page content', function () { $this->actingAs($this->admin); Volt::test('admin.pages.edit', ['slug' => 'terms']) ->assertSet('showPreview', false) ->call('togglePreview') ->assertSet('showPreview', true); }); test('preview modal can be closed', function () { $this->actingAs($this->admin); Volt::test('admin.pages.edit', ['slug' => 'terms']) ->call('togglePreview') ->assertSet('showPreview', true) ->call('closePreview') ->assertSet('showPreview', false); }); test('updated_at timestamp changes on save', function () { $page = Page::where('slug', 'terms')->first(); $originalTimestamp = $page->updated_at; $this->travel(1)->minute(); $this->actingAs($this->admin); Volt::test('admin.pages.edit', ['slug' => 'terms']) ->set('content_en', '

Updated content

') ->call('save'); expect($page->fresh()->updated_at)->toBeGreaterThan($originalTimestamp); }); test('html content is sanitized on save', function () { $this->actingAs($this->admin); Volt::test('admin.pages.edit', ['slug' => 'terms']) ->set('content_en', '

Safe content

') ->call('save'); $page = Page::where('slug', 'terms')->first(); expect($page->content_en)->not->toContain('