Skip to content

Commit

Permalink
#183: Test coverage increased
Browse files Browse the repository at this point in the history
  • Loading branch information
alimranahmed committed Aug 7, 2024
1 parent cbc3163 commit df389b0
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 1 deletion.
1 change: 0 additions & 1 deletion app/Livewire/Backend/Comment/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,5 @@ public function submitReply(): void
public function delete(Comment $comment): void
{
$comment->delete();
$this->comment->refresh();
}
}
75 changes: 75 additions & 0 deletions tests/Feature/Livewire/Backend/Comment/ShowTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace Tests\Feature\Livewire\Backend\Comment;

use App\Livewire\Backend\Comment\Show;
use App\Models\Article;
use App\Models\Comment;
use App\Models\User;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\Auth;
use Livewire\Livewire;
use Tests\TestCase;

class ShowTest extends TestCase
{
use WithFaker;

protected Comment $comment;

protected User $user;

protected Article $article;

public function setUp(): void
{
parent::setUp();
$this->user = User::factory()->create();
Auth::login($this->user);

$this->article = Article::factory()->create([
'user_id' => $this->user->id,
]);
$this->comment = Comment::factory()->create([
'article_id' => $this->article->id,
'user_id' => $this->user->id,
]);
}

public function testRender()
{
Livewire::test(Show::class, ['comment' => $this->comment])
->assertOk()
->assertViewIs('livewire.backend.comment.show');
}

public function testSubmitReply()
{
Livewire::test(Show::class, ['comment' => $this->comment])
->set('reply', [
'content' => $replyContent = $this->faker()->paragraph(),
])
->call('submitReply')
->assertOk()
->assertHasNoErrors();

$this->assertDatabaseHas('comments', [
'parent_comment_id' => $this->comment->id,
'article_id' => $this->article->id,
'user_id' => $this->user->id,
'content' => $replyContent,
]);
}

public function testDelete()
{
Livewire::test(Show::class, ['comment' => $this->comment])
->call('delete', $this->comment)
->assertOk()
->assertHasNoErrors();

$this->assertDatabaseMissing('comments', [
'id' => $this->comment->id,
]);
}
}
40 changes: 40 additions & 0 deletions tests/Feature/Livewire/Backend/Keyword/IndexTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Tests\Feature\Livewire\Backend\Keyword;

use App\Livewire\Backend\Keyword\Index;
use App\Models\Article;
use App\Models\Keyword;
use Livewire\Livewire;
use Tests\TestCase;

class IndexTest extends TestCase
{
public function testRender()
{
Livewire::test(Index::class)
->assertOk()
->assertViewIs('livewire.backend.keyword.index')
->assertViewHas('keywords');
}

public function testDelete()
{
$keyword = Keyword::factory()->create();
$article = Article::factory()->create();
$article->keywords()->attach($keyword);

Livewire::test(Index::class)
->call('delete', $keyword)
->assertOk()
->assertHasNoErrors();

$this->assertDatabaseMissing('keywords', [
'id' => $keyword->id,
]);

$this->assertDatabaseHas('articles', [
'id' => $article->id,
]);
}
}
18 changes: 18 additions & 0 deletions tests/Feature/Livewire/Backend/Subscriber/IndexTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Tests\Feature\Livewire\Backend\Subscriber;

use App\Livewire\Backend\Subscriber\Index;
use Livewire\Livewire;
use Tests\TestCase;

class IndexTest extends TestCase
{
public function testRender()
{
Livewire::test(Index::class)
->assertOk()
->assertViewIs('livewire.backend.subscriber.index')
->assertViewHas('subscribers');
}
}

0 comments on commit df389b0

Please sign in to comment.