complete story 5.3 with qa tests
This commit is contained in:
@@ -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');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user