-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e6088c
commit 88d55e3
Showing
11 changed files
with
401 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ | |
*/ | ||
class FeedbackFactory extends Factory | ||
{ | ||
|
||
protected $model = Feedback::class; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Livewire\Backend\Article; | ||
|
||
use App\Livewire\Backend\Article\Index; | ||
use App\Livewire\Backend\Article\IndexRow; | ||
use App\Models\Article; | ||
use App\Models\User; | ||
use Illuminate\Http\Response; | ||
use Illuminate\Support\Facades\Auth; | ||
use Livewire\Livewire; | ||
use Spatie\Permission\Models\Role; | ||
use Tests\TestCase; | ||
|
||
class IndexRowTest extends TestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$user = User::factory()->create(); | ||
$author = Role::findOrCreate('author'); | ||
$user->assignRole($author); | ||
Auth::loginUsingId($user->id); | ||
} | ||
|
||
public function testRender(): void | ||
{ | ||
$article = Article::factory()->create(); | ||
|
||
Livewire::test(IndexRow::class, ['article' => $article]) | ||
->assertStatus(Response::HTTP_OK) | ||
->assertViewIs('livewire.backend.article.index-row'); | ||
} | ||
|
||
public function testTogglePublishCanMakeUnpublish() | ||
{ | ||
$article = Article::factory()->create(['is_published' => true]); | ||
|
||
Livewire::test(IndexRow::class, ['article' => $article]) | ||
->call('togglePublish'); | ||
|
||
$this->assertDatabaseHas('articles', [ | ||
'id' => $article->id, | ||
'is_published' => false, | ||
]); | ||
} | ||
|
||
public function testTogglePublishCanMakePublish() | ||
{ | ||
$article = Article::factory()->create(['is_published' => false]); | ||
|
||
Livewire::test(IndexRow::class, ['article' => $article]) | ||
->call('togglePublish'); | ||
|
||
$this->assertDatabaseHas('articles', [ | ||
'id' => $article->id, | ||
'is_published' => true, | ||
]); | ||
} | ||
|
||
public function testDestroy() | ||
{ | ||
$article = Article::factory()->create(['is_deleted' => false]); | ||
|
||
Livewire::test(IndexRow::class, ['article' => $article]) | ||
->call('destroy') | ||
->assertDispatchedTo(Index::class, 'articleDeleted'); | ||
|
||
$this->assertDatabaseHas('articles', [ | ||
'id' => $article->id, | ||
'is_deleted' => true, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Livewire\Backend\Category; | ||
|
||
use App\Livewire\Backend\Category\IndexRow; | ||
use App\Models\Category; | ||
use Illuminate\Support\Str; | ||
use Livewire\Livewire; | ||
use Tests\TestCase; | ||
|
||
class IndexRowTest extends TestCase | ||
{ | ||
public function testRender() | ||
{ | ||
$category = Category::factory()->create(); | ||
|
||
Livewire::test(IndexRow::class, ['category' => $category]) | ||
->assertViewIs('livewire.backend.category.index-row'); | ||
} | ||
|
||
public function testToggleActiveCanActivate() | ||
{ | ||
$category = Category::factory()->create(['is_active' => false]); | ||
|
||
Livewire::test(IndexRow::class, ['category' => $category]) | ||
->call('toggleActive') | ||
->assertHasNoErrors(); | ||
|
||
$this->assertDatabaseHas('categories', [ | ||
'id' => $category->id, | ||
'is_active' => true, | ||
]); | ||
} | ||
|
||
public function testToggleActiveCanDeactivate() | ||
{ | ||
$category = Category::factory()->create(['is_active' => true]); | ||
|
||
Livewire::test(IndexRow::class, ['category' => $category]) | ||
->call('toggleActive') | ||
->assertHasNoErrors(); | ||
|
||
$this->assertDatabaseHas('categories', [ | ||
'id' => $category->id, | ||
'is_active' => false, | ||
]); | ||
} | ||
|
||
public function testDestroy() | ||
{ | ||
$category = Category::factory()->create(['is_active' => true]); | ||
|
||
Livewire::test(IndexRow::class, ['category' => $category]) | ||
->call('destroy', $category) | ||
->assertHasNoErrors(); | ||
|
||
$this->assertDatabaseMissing('categories', [ | ||
'id' => $category->id, | ||
]); | ||
} | ||
|
||
public function testStartEditing() | ||
{ | ||
$category = Category::factory()->create(['is_active' => true]); | ||
|
||
Livewire::test(IndexRow::class, ['category' => $category]) | ||
->call('startEditing') | ||
->assertHasNoErrors() | ||
->assertSet('editing', true); | ||
} | ||
|
||
public function testUpdate() | ||
{ | ||
$category = Category::factory()->create(['is_active' => true]); | ||
Livewire::test(IndexRow::class, ['category' => $category]) | ||
->set('editing', true) | ||
->set('categoryData', [ | ||
'name' => $name = Str::random(), | ||
'alias' => $alias = Str::random(), | ||
]) | ||
->call('update') | ||
->assertSet('editing', false); | ||
|
||
$this->assertDatabaseHas('categories', [ | ||
'id' => $category->id, | ||
'name' => $name, | ||
'alias' => $alias, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Livewire\Backend\Category; | ||
|
||
use App\Livewire\Backend\Category\Index; | ||
use Illuminate\Http\Response; | ||
use Illuminate\Support\Str; | ||
use Livewire\Livewire; | ||
use Tests\TestCase; | ||
|
||
class IndexTest extends TestCase | ||
{ | ||
public function testRender(): void | ||
{ | ||
Livewire::test(Index::class) | ||
->assertViewIs('livewire.backend.category.index') | ||
->assertViewHas('categories') | ||
->assertStatus(Response::HTTP_OK); | ||
} | ||
|
||
public function testStartAdding() | ||
{ | ||
Livewire::test(Index::class) | ||
->set('adding', false) | ||
->call('startAdding') | ||
->assertSet('adding', true); | ||
} | ||
|
||
public function testStore() | ||
{ | ||
Livewire::test(Index::class) | ||
->set('category', [ | ||
'name' => $name = Str::random(), | ||
'alias' => $alias = Str::random(), | ||
]) | ||
->call('store'); | ||
|
||
$this->assertDatabaseHas('categories', [ | ||
'name' => $name, | ||
'alias' => $alias, | ||
]); | ||
} | ||
} |
Oops, something went wrong.