-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow creation of a new option on-the-fly (#8)
- Loading branch information
Showing
11 changed files
with
309 additions
and
58 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
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,41 @@ | ||
<?php | ||
|
||
namespace SertxuDeveloper\LivewireCombobox\Tests; | ||
|
||
use Livewire\Livewire; | ||
use SertxuDeveloper\LivewireCombobox\Tests\Components\AllowCreationCombobox; | ||
use SertxuDeveloper\LivewireCombobox\Tests\Models\Post; | ||
|
||
class AllowCreationComboboxTest extends TestCase | ||
{ | ||
public function test_can_create_new_models(): void { | ||
Post::factory()->count(3)->create(); | ||
|
||
$component = Livewire::test(AllowCreationCombobox::class, [ | ||
'name' => 'posts', | ||
'label' => 'Posts', | ||
])->set('search', 'Another Post'); | ||
|
||
$component->assertSuccessful() | ||
->assertSee('Posts') | ||
->assertSee('Create <b>Another Post</b>', false) | ||
->assertNotEmitted('selected-posts') | ||
->assertNotEmitted('cleared-posts'); | ||
|
||
$this->assertDatabaseCount('posts', 3); | ||
|
||
$component->call('create'); | ||
|
||
$post = Post::query()->where('title', 'Another Post')->first(); | ||
|
||
$component->assertEmitted('selected-posts') | ||
->assertNotEmitted('cleared-posts') | ||
->assertSet('selected', $post); | ||
|
||
$this->assertDatabaseCount('posts', 4); | ||
|
||
$this->assertDatabaseHas('posts', [ | ||
'title' => 'Another Post', | ||
]); | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
namespace SertxuDeveloper\LivewireCombobox\Tests\Components; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use SertxuDeveloper\LivewireCombobox\Components\Combobox; | ||
use SertxuDeveloper\LivewireCombobox\Tests\Models\Post; | ||
|
||
class AllowCreationCombobox extends Combobox | ||
{ | ||
/** @var class-string<Model> The model to be used. */ | ||
public string $model = Post::class; | ||
|
||
/** If the combobox should be able to create new models. */ | ||
public bool $canCreate = true; | ||
|
||
/** The column to be shown as the label. */ | ||
public string $labelColumn = 'title'; | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace SertxuDeveloper\LivewireCombobox\Tests\Components; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use SertxuDeveloper\LivewireCombobox\Components\Combobox; | ||
use SertxuDeveloper\LivewireCombobox\Tests\Models\User; | ||
|
||
class DontKeepSelectionCombobox extends Combobox | ||
{ | ||
/** @var class-string<Model> The model to be used. */ | ||
public string $model = User::class; | ||
|
||
/** If set to false, will not keep the selection, useful if you want to make a list. */ | ||
public bool $keepSelection = false; | ||
} |
Oops, something went wrong.