|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Rappasoft\LaravelLivewireTables\Tests; |
| 4 | + |
| 5 | +use Illuminate\Contracts\Pagination\LengthAwarePaginator; |
| 6 | +use Illuminate\Support\Collection; |
| 7 | +use Rappasoft\LaravelLivewireTables\DataTableComponent; |
| 8 | +use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\CatsTable; |
| 9 | + |
| 10 | +class RelationshipDataTableComponentTest extends TestCase |
| 11 | +{ |
| 12 | + protected DataTableComponent $table; |
| 13 | + |
| 14 | + public function setUp(): void |
| 15 | + { |
| 16 | + parent::setUp(); |
| 17 | + |
| 18 | + $this->table = new CatsTable(); |
| 19 | + } |
| 20 | + |
| 21 | + /** @test */ |
| 22 | + public function bootstrap_test_datatable(): void |
| 23 | + { |
| 24 | + $this->assertInstanceOf(DataTableComponent::class, $this->table); |
| 25 | + } |
| 26 | + |
| 27 | + /** @test */ |
| 28 | + public function columns(): void |
| 29 | + { |
| 30 | + $columns = $this->table->columns(); |
| 31 | + |
| 32 | + $this->assertCount(5, $columns); |
| 33 | + } |
| 34 | + |
| 35 | + /** @test */ |
| 36 | + public function rows(): void |
| 37 | + { |
| 38 | + $rows = $this->table->rows; |
| 39 | + |
| 40 | + $this->assertInstanceOf(LengthAwarePaginator::class, $rows); |
| 41 | + $this->assertEquals(2, $this->table->getRowsProperty()->total()); |
| 42 | + } |
| 43 | + |
| 44 | + /** @test */ |
| 45 | + public function pagination_default(): void |
| 46 | + { |
| 47 | + $this->assertInstanceOf(LengthAwarePaginator::class, $this->table->rows); |
| 48 | + $this->assertEquals(10, $this->table->perPage); |
| 49 | + $this->assertTrue($this->table->paginationEnabled); |
| 50 | + $this->assertTrue($this->table->showPerPage); |
| 51 | + } |
| 52 | + |
| 53 | + /** @test */ |
| 54 | + public function pagination(): void |
| 55 | + { |
| 56 | + $this->table->perPage = 1; |
| 57 | + $this->assertEquals(1, $this->table->rows->currentPage()); |
| 58 | + $this->assertEquals(1, $this->table->rows->count()); |
| 59 | + $this->assertEquals(2, $this->table->rows->lastPage()); |
| 60 | + } |
| 61 | + |
| 62 | + /** @test */ |
| 63 | + public function pagination_disabled(): void |
| 64 | + { |
| 65 | + $this->table->paginationEnabled = false; |
| 66 | + $this->table->perPage = 2; |
| 67 | + $this->assertInstanceOf(Collection::class, $this->table->rows); |
| 68 | + $this->assertCount(2, $this->table->rows); |
| 69 | + } |
| 70 | + |
| 71 | + /** @test */ |
| 72 | + public function search_filter(): void |
| 73 | + { |
| 74 | + $this->table->filters['search'] = 'Cartman'; |
| 75 | + $this->assertEquals(1, $this->table->getRowsProperty()->total()); |
| 76 | + } |
| 77 | + |
| 78 | + /** @test */ |
| 79 | + public function search_filter_reset(): void |
| 80 | + { |
| 81 | + $this->table->filters['search'] = 'Cartman'; |
| 82 | + $this->table->resetFilters(); |
| 83 | + $this->assertEquals(1, $this->table->rows->total()); |
| 84 | + } |
| 85 | + |
| 86 | + /** @test */ |
| 87 | + public function search_filter_remove(): void |
| 88 | + { |
| 89 | + $this->table->filters['search'] = 'Cartman'; |
| 90 | + $this->table->removeFilter('search'); |
| 91 | + $this->assertEquals(2, $this->table->rows->total()); |
| 92 | + } |
| 93 | + |
| 94 | + /** @test */ |
| 95 | + public function search_filter_callback(): void |
| 96 | + { |
| 97 | + $this->table->filters['search'] = '22'; |
| 98 | + $this->assertEquals(1, $this->table->getRowsProperty()->total()); |
| 99 | + } |
| 100 | +} |
0 commit comments