complete story 5.3 with qa tests

This commit is contained in:
Naser Mansour
2025-12-27 01:52:42 +02:00
parent d29959d54d
commit 77d32d0dae
7 changed files with 485 additions and 49 deletions
+124 -6
View File
@@ -160,31 +160,71 @@ test('toggle publish creates audit log', function () {
expect($log->new_values['status'])->toBe('published');
});
test('admin can delete post from index', function () {
test('admin can delete post from index with confirmation modal', function () {
$post = Post::factory()->create();
$postId = $post->id;
$this->actingAs($this->admin);
Volt::test('admin.posts.index')
->call('delete', $post->id);
->call('delete', $post->id)
->assertSet('showDeleteModal', true)
->assertSet('postToDelete.id', $post->id)
->call('confirmDelete');
expect(Post::find($postId))->toBeNull();
});
test('delete post creates audit log', function () {
test('delete modal shows before deletion', function () {
$post = Post::factory()->create();
$this->actingAs($this->admin);
Volt::test('admin.posts.index')
->assertSet('showDeleteModal', false)
->call('delete', $post->id)
->assertSet('showDeleteModal', true)
->assertSet('postToDelete.id', $post->id);
// Post should still exist since we haven't confirmed
expect(Post::find($post->id))->not->toBeNull();
});
test('cancel delete closes modal and keeps post', function () {
$post = Post::factory()->create();
$this->actingAs($this->admin);
Volt::test('admin.posts.index')
->call('delete', $post->id)
->assertSet('showDeleteModal', true)
->call('cancelDelete')
->assertSet('showDeleteModal', false)
->assertSet('postToDelete', null);
expect(Post::find($post->id))->not->toBeNull();
});
test('delete post creates audit log with old values', function () {
$post = Post::factory()->create([
'title' => ['ar' => 'عنوان تجريبي', 'en' => 'Test Title'],
]);
$postId = $post->id;
$this->actingAs($this->admin);
Volt::test('admin.posts.index')
->call('delete', $post->id);
->call('delete', $post->id)
->call('confirmDelete');
expect(AdminLog::where('action', 'delete')
$log = AdminLog::where('action', 'delete')
->where('target_type', 'post')
->where('target_id', $postId)
->exists())->toBeTrue();
->first();
expect($log)->not->toBeNull()
->and($log->old_values)->toHaveKey('title')
->and($log->old_values['title']['en'])->toBe('Test Title');
});
test('pagination works correctly with per page selector', function () {
@@ -514,3 +554,81 @@ test('draft scope returns only draft posts', function () {
expect(Post::draft()->count())->toBe(1);
});
// ===========================================
// Edit Page Delete Tests
// ===========================================
test('edit page shows delete button', function () {
$post = Post::factory()->create();
$this->actingAs($this->admin)
->get(route('admin.posts.edit', $post))
->assertOk()
->assertSee(__('posts.delete_post'));
});
test('admin can delete post from edit page', function () {
$post = Post::factory()->create();
$postId = $post->id;
$this->actingAs($this->admin);
Volt::test('admin.posts.edit', ['post' => $post])
->call('delete')
->assertSet('showDeleteModal', true)
->call('confirmDelete')
->assertRedirect(route('admin.posts.index'));
expect(Post::find($postId))->toBeNull();
});
test('edit page delete shows confirmation modal', function () {
$post = Post::factory()->create();
$this->actingAs($this->admin);
Volt::test('admin.posts.edit', ['post' => $post])
->assertSet('showDeleteModal', false)
->call('delete')
->assertSet('showDeleteModal', true);
// Post should still exist since we haven't confirmed
expect(Post::find($post->id))->not->toBeNull();
});
test('edit page cancel delete closes modal', function () {
$post = Post::factory()->create();
$this->actingAs($this->admin);
Volt::test('admin.posts.edit', ['post' => $post])
->call('delete')
->assertSet('showDeleteModal', true)
->call('cancelDelete')
->assertSet('showDeleteModal', false);
expect(Post::find($post->id))->not->toBeNull();
});
test('edit page delete creates audit log', function () {
$post = Post::factory()->create([
'title' => ['ar' => 'عنوان', 'en' => 'Test Title'],
]);
$postId = $post->id;
$this->actingAs($this->admin);
Volt::test('admin.posts.edit', ['post' => $post])
->call('delete')
->call('confirmDelete');
$log = AdminLog::where('action', 'delete')
->where('target_type', 'post')
->where('target_id', $postId)
->first();
expect($log)->not->toBeNull()
->and($log->old_values)->toHaveKey('title')
->and($log->old_values['title']['en'])->toBe('Test Title');
});