-
-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature-testing' of https://github.com/DeltaSystems/lar…
…avel-livewire-tables into DeltaSystems-feature-testing
- Loading branch information
Showing
10 changed files
with
344 additions
and
13 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
Binary file not shown.
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,75 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Tests; | ||
|
||
use Illuminate\Contracts\Pagination\LengthAwarePaginator; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Rappasoft\LaravelLivewireTables\DataTableComponent; | ||
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable; | ||
|
||
class DataTableComponentTest extends TestCase | ||
{ | ||
protected DataTableComponent $table; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->table = $table = new PetsTable(); | ||
} | ||
|
||
/** @test */ | ||
public function bootstrap_test_datatable() | ||
{ | ||
$this->assertInstanceOf(DataTableComponent::class, $this->table); | ||
} | ||
|
||
/** @test */ | ||
public function test_query() | ||
{ | ||
$query = $this->table->query(); | ||
|
||
$this->assertInstanceOf(Builder::class, $query); | ||
} | ||
|
||
/** @test */ | ||
public function test_columns() | ||
{ | ||
$columns = $this->table->columns(); | ||
|
||
$this->assertIsArray($columns); | ||
$this->assertCount(5, $columns); | ||
} | ||
|
||
/** @test */ | ||
public function test_rows() | ||
{ | ||
$rows = $this->table->rows; | ||
|
||
$this->assertInstanceOf(LengthAwarePaginator::class, $rows); | ||
$this->assertEquals(5, $this->table->getRowsProperty()->total()); | ||
} | ||
|
||
/** @test */ | ||
public function test_search_filter() | ||
{ | ||
$this->table->filters['search'] = 'Cartman'; | ||
$this->assertEquals(1, $this->table->getRowsProperty()->total()); | ||
} | ||
|
||
/** @test */ | ||
public function test_search_filter_reset() | ||
{ | ||
$this->table->filters['search'] = 'Cartman'; | ||
$this->table->resetFilters(); | ||
$this->assertEquals(1, $this->table->rows->total()); | ||
} | ||
|
||
/** @test */ | ||
public function test_search_filter_remove() | ||
{ | ||
$this->table->filters['search'] = 'Cartman'; | ||
$this->table->removeFilter('search'); | ||
$this->assertEquals(5, $this->table->rows->total()); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Tests\Http\Livewire; | ||
|
||
use Illuminate\Database\Eloquent\Builder; | ||
use Rappasoft\LaravelLivewireTables\DataTableComponent; | ||
use Rappasoft\LaravelLivewireTables\Tests\Models\Pet; | ||
use Rappasoft\LaravelLivewireTables\Views\Column; | ||
|
||
class PetsTable extends DataTableComponent | ||
{ | ||
/** | ||
* @return Builder | ||
*/ | ||
public function query() : Builder | ||
{ | ||
return Pet::query()->when($this->getFilter('search'), function (Builder $query, $search) { | ||
$query->where('name', 'like', '%'.$search.'%'); | ||
}); | ||
} | ||
|
||
public function columns(): array | ||
{ | ||
return [ | ||
Column::make('Name', 'name'), | ||
Column::make('Age', 'age'), | ||
Column::make('Last Visit', 'last_visit'), | ||
Column::make('Species', 'species.name'), | ||
Column::make('Breed', 'breed.name'), | ||
]; | ||
} | ||
} |
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 Rappasoft\LaravelLivewireTables\Tests\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* @property int $id | ||
* @property string $name | ||
* @property int $species_id | ||
*/ | ||
class Breed extends Model | ||
{ | ||
/** | ||
* The table associated with the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $table = 'breeds'; | ||
|
||
/** | ||
* The primary key for the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $primaryKey = 'id'; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
public $timestamps = false; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'id', | ||
'name', | ||
'species_id', | ||
]; | ||
} |
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,65 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Tests\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* @property int $id | ||
* @property string $name | ||
* @property string $age | ||
* @property string $last_visit | ||
* @property int $species_id | ||
* @property int $breed_id | ||
*/ | ||
class Pet extends Model | ||
{ | ||
/** | ||
* The table associated with the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $table = 'pets'; | ||
|
||
/** | ||
* The primary key for the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $primaryKey = 'id'; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
public $timestamps = false; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'id', | ||
'name', | ||
'age', | ||
'last_visit', | ||
'species_id', | ||
'breed_id', | ||
]; | ||
|
||
/** | ||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo|Species[] | ||
*/ | ||
public function species() | ||
{ | ||
return $this->belongsTo(Species::class); | ||
} | ||
|
||
/** | ||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo|Breed[] | ||
*/ | ||
public function breeds() | ||
{ | ||
return $this->belongsTo(Breed::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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Tests\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* @property int $id | ||
* @property string $name | ||
*/ | ||
class Species extends Model | ||
{ | ||
/** | ||
* The table associated with the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $table = 'species'; | ||
|
||
/** | ||
* The primary key for the model. | ||
* | ||
* @var string | ||
*/ | ||
protected $primaryKey = 'id'; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
public $timestamps = false; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'id', | ||
'name', | ||
]; | ||
} |
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
Binary file not shown.