Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions tests/Http/Livewire/BaseTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Tests\Http\Livewire;

use Rappasoft\LaravelLivewireTables\DataTableComponent;

abstract class BaseTable extends DataTableComponent
{
public string $paginationTest = 'standard';

public function enableDetailedPagination(string $type = 'standard')
{
$this->setPerPageAccepted([1, 3, 5, 10, 15, 25, 50])->setPerPage(3);
$this->setPaginationMethod($type);
$this->setDisplayPaginationDetailsEnabled();

}

public function disableDetailedPagination(string $type = 'standard')
{
$this->setPerPageAccepted([1, 3, 5, 10, 15, 25, 50])->setPerPage(3);
$this->setPaginationMethod($type);
$this->setDisplayPaginationDetailsDisabled();
}

public function setPaginationTest(string $type)
{
$this->paginationTest = $type;
}

public function bootAll()
{
$view = view('livewire-tables::datatable');

$this->boot();
$this->bootedComponentUtilities();
$this->bootedManagesFilters();
$this->bootedWithColumns();
$this->bootedWithColumnSelect();
$this->booted();
$this->mountManagesFilters();
$this->mountComponentUtilities();
$this->mountWithSorting();
$this->renderAll($view);
}

public function renderAll($view = null)
{
if (is_null($view)) {
$view = view('livewire-tables::datatable');
}
$this->renderingWithColumns($view, $view->getData());
$this->renderingWithColumnSelect($view, $view->getData());
$this->renderingWithCustomisations($view, $view->getData());
$this->renderingWithData($view, $view->getData());
$this->renderingWithReordering($view, $view->getData());
$this->renderingWithPagination($view, $view->getData());
$this->render();

return $view;
}
}
25 changes: 1 addition & 24 deletions tests/Http/Livewire/BreedsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Rappasoft\LaravelLivewireTables\Tests\Http\Livewire;

use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Tests\Models\Breed;
use Rappasoft\LaravelLivewireTables\Tests\Models\Pet;
use Rappasoft\LaravelLivewireTables\Tests\Models\Species;
Expand All @@ -18,32 +17,10 @@
use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\TextFilter;

class BreedsTable extends DataTableComponent
class BreedsTable extends BaseTable
{
public $model = Breed::class;

public string $paginationTest = 'standard';

public function enableDetailedPagination(string $type = 'standard')
{
$this->setPerPageAccepted([1, 3, 5, 10, 15, 25, 50])->setPerPage(3);
$this->setPaginationMethod($type);
$this->setDisplayPaginationDetailsEnabled();

}

public function disableDetailedPagination(string $type = 'standard')
{
$this->setPerPageAccepted([1, 3, 5, 10, 15, 25, 50])->setPerPage(3);
$this->setPaginationMethod($type);
$this->setDisplayPaginationDetailsDisabled();
}

public function setPaginationTest(string $type)
{
$this->paginationTest = $type;
}

public function configure(): void
{
$this->setPrimaryKey('id');
Expand Down
25 changes: 2 additions & 23 deletions tests/Http/Livewire/FailingTables/BrokenSecondaryHeaderTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,16 @@

use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\BaseTable;
use Rappasoft\LaravelLivewireTables\Tests\Models\{Breed,Pet,Species};
use Rappasoft\LaravelLivewireTables\Views\Column;
use Rappasoft\LaravelLivewireTables\Views\Columns\{ImageColumn,LinkColumn};
use Rappasoft\LaravelLivewireTables\Views\Filters\{DateFilter,DateTimeFilter,MultiSelectDropdownFilter,MultiSelectFilter,NumberFilter,SelectFilter,TextFilter};

class BrokenSecondaryHeaderTable extends DataTableComponent
class BrokenSecondaryHeaderTable extends BaseTable
{
public $model = Pet::class;

public string $paginationTest = 'standard';

public function enableDetailedPagination(string $type = 'standard')
{
$this->setPerPageAccepted([1, 3, 5, 10, 15, 25, 50])->setPerPage(3);
$this->setPaginationMethod($type);
$this->setDisplayPaginationDetailsEnabled();

}

public function disableDetailedPagination(string $type = 'standard')
{
$this->setPerPageAccepted([1, 3, 5, 10, 15, 25, 50])->setPerPage(3);
$this->setPaginationMethod($type);
$this->setDisplayPaginationDetailsDisabled();
}

public function setPaginationTest(string $type)
{
$this->paginationTest = $type;
}

public function configure(): void
{
$this->setPrimaryKey('id');
Expand Down
3 changes: 2 additions & 1 deletion tests/Http/Livewire/FailingTables/NoBuildMethodTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\BaseTable;
use Rappasoft\LaravelLivewireTables\Tests\Models\Breed;
use Rappasoft\LaravelLivewireTables\Tests\Models\Species;
use Rappasoft\LaravelLivewireTables\Views\Column;
Expand All @@ -17,7 +18,7 @@
use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\TextFilter;

class NoBuildMethodTable extends DataTableComponent
class NoBuildMethodTable extends BaseTable
{
public function configure(): void
{
Expand Down
83 changes: 2 additions & 81 deletions tests/Http/Livewire/FailingTables/NoColumnsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,95 +2,16 @@

namespace Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\FailingTables;

use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Tests\Models\Breed;
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable;
use Rappasoft\LaravelLivewireTables\Tests\Models\Pet;
use Rappasoft\LaravelLivewireTables\Tests\Models\Species;
use Rappasoft\LaravelLivewireTables\Views\Filters\DateFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\DateTimeFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\MultiSelectDropdownFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\MultiSelectFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\NumberFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\TextFilter;

class NoColumnsTable extends DataTableComponent
class NoColumnsTable extends PetsTable
{
public $model = Pet::class;

public function configure(): void
{
$this->setPrimaryKey('id');
}

public function columns(): array
{
return [
];
}

public function filters(): array
{
return [
MultiSelectFilter::make('Breed')
->options(
Breed::query()
->orderBy('name')
->get()
->keyBy('id')
->map(fn ($breed) => $breed->name)
->toArray()
)
->filter(function (Builder $builder, array $values) {
return $builder->whereIn('breed_id', $values);
}),
MultiSelectDropdownFilter::make('Species')
->options(
Species::query()
->orderBy('name')
->get()
->keyBy('id')
->map(fn ($species) => $species->name)
->toArray()
)
->filter(function (Builder $builder, array $values) {
return $builder->whereIn('species_id', $values);
}),
NumberFilter::make('Breed ID', 'breed_id_filter')
->filter(function (Builder $builder, string $value) {
return $builder->where('breed_id', '=', $value);
}),

TextFilter::make('Pet Name', 'pet_name_filter')
->filter(function (Builder $builder, string $value) {
return $builder->where('pets.name', '=', $value);
}),

DateFilter::make('Last Visit After Date', 'last_visit_date_filter')
->filter(function (Builder $builder, string $value) {
return $builder->whereDate('pets.last_visit', '=>', $value);
}),

DateTimeFilter::make('Last Visit Before DateTime', 'last_visit_datetime_filter')
->filter(function (Builder $builder, string $value) {
return $builder->whereDate('pets.last_visit', '<=', $value);
}),

SelectFilter::make('Breed SelectFilter', 'breed_select_filter')
->options(
Breed::query()
->orderBy('name')
->get()
->keyBy('id')
->map(fn ($breed) => $breed->name)
->toArray()
)
->filter(function (Builder $builder, string $value) {
return $builder->where('breed_id', $value);
})
->setCustomFilterLabel('livewire-tables::tests.testFilterLabel')
->setFilterPillBlade('livewire-tables::tests.testFilterPills'),
];
}
}
3 changes: 2 additions & 1 deletion tests/Http/Livewire/FailingTables/NoPrimaryKeyTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\BaseTable;
use Rappasoft\LaravelLivewireTables\Tests\Models\Breed;
use Rappasoft\LaravelLivewireTables\Tests\Models\Pet;
use Rappasoft\LaravelLivewireTables\Tests\Models\Species;
Expand All @@ -18,7 +19,7 @@
use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\TextFilter;

class NoPrimaryKeyTable extends DataTableComponent
class NoPrimaryKeyTable extends BaseTable
{
public $model = Pet::class;

Expand Down
25 changes: 1 addition & 24 deletions tests/Http/Livewire/PetsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\App;
use Livewire\Attributes\On;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Tests\Models\Breed;
use Rappasoft\LaravelLivewireTables\Tests\Models\Pet;
use Rappasoft\LaravelLivewireTables\Tests\Models\Species;
Expand All @@ -20,37 +19,15 @@
use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\TextFilter;

class PetsTable extends DataTableComponent
class PetsTable extends BaseTable
{
public $model = Pet::class;

public string $paginationTest = 'standard';

public function changeLocale(string $locale)
{
App::setLocale($locale);
}

public function enableDetailedPagination(string $type = 'standard')
{
$this->setPerPageAccepted([1, 3, 5, 10, 15, 25, 50])->setPerPage(3);
$this->setPaginationMethod($type);
$this->setDisplayPaginationDetailsEnabled();

}

public function disableDetailedPagination(string $type = 'standard')
{
$this->setPerPageAccepted([1, 3, 5, 10, 15, 25, 50])->setPerPage(3);
$this->setPaginationMethod($type);
$this->setDisplayPaginationDetailsDisabled();
}

public function setPaginationTest(string $type)
{
$this->paginationTest = $type;
}

public function configure(): void
{
$this->setPrimaryKey('id');
Expand Down
Loading
Loading