forked from Power-Components/livewire-powergrid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: cast value to a decimal (Power-Components#1520)
* fix: removed return type forcing for string * fix: removed return type forcing for string * feat: add Order model to run the tests * feat: add method verify value is string * feat: added Test * feat: added dropIfExists orders
- Loading branch information
Showing
6 changed files
with
110 additions
and
1 deletion.
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,30 @@ | ||
<?php | ||
|
||
namespace PowerComponents\LivewirePowerGrid\Tests\Concerns\Models; | ||
|
||
use Illuminate\Database\Eloquent\{Model, SoftDeletes}; | ||
use Illuminate\Support\Carbon; | ||
|
||
/** | ||
* @property int $id | ||
* @property string $name | ||
* @property float $price | ||
* @property float $tax | ||
* @property Carbon $created_at | ||
* @property Carbon $updated_at | ||
* @property Carbon $produced_at | ||
*/ | ||
class Order extends Model | ||
{ | ||
use SoftDeletes; | ||
|
||
protected $guarded = []; | ||
|
||
protected $table = 'orders'; | ||
|
||
protected $casts = [ | ||
'name' => 'string', | ||
'price' => 'decimal:2', | ||
'tax' => 'float', | ||
]; | ||
} |
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,45 @@ | ||
<?php | ||
use Illuminate\Database\Eloquent\Builder; | ||
use PowerComponents\LivewirePowerGrid\PowerGrid; | ||
use PowerComponents\LivewirePowerGrid\Tests\Concerns\Models\Order; | ||
|
||
use function PowerComponents\LivewirePowerGrid\Tests\Plugins\livewire; | ||
|
||
use PowerComponents\LivewirePowerGrid\{Column, PowerGridComponent, PowerGridFields}; | ||
|
||
$component = new class () extends PowerGridComponent { | ||
public function datasource(): Builder | ||
{ | ||
return Order::query(); | ||
} | ||
|
||
public function fields(): PowerGridFields | ||
{ | ||
return PowerGrid::fields() | ||
->add('name') | ||
->add('tax') | ||
->add('price') | ||
->add('price_formatted', fn (Order $model) => $model->price * 100); | ||
} | ||
|
||
public function columns(): array | ||
{ | ||
return [ | ||
Column::make('Name', 'name'), | ||
Column::make('Price', 'price_formatted', 'price'), | ||
Column::make('Tax', 'tax'), | ||
]; | ||
} | ||
}; | ||
|
||
it('can add fields', function (string $name, string|float $price, string|float $tax) use ($component) { | ||
$component = livewire($component::class); | ||
|
||
$component->assertSee($name) | ||
->assertSee($price) | ||
->assertSee($tax); | ||
})->with([ | ||
['Order 1', 1000, 127.30], | ||
['Order 2', 2000, 259.50], | ||
['Order 3', '', ''], | ||
]); |