Skip to content

Commit

Permalink
Add Placeholder Test Table, Basic Visuals Test
Browse files Browse the repository at this point in the history
  • Loading branch information
lrljoe committed Oct 17, 2023
1 parent 30b26e4 commit 18522b5
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 6 deletions.
150 changes: 150 additions & 0 deletions tests/Http/Livewire/PetsTableLoadingPlaceholder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php

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;
use Rappasoft\LaravelLivewireTables\Views\Column;
use Rappasoft\LaravelLivewireTables\Views\Columns\ImageColumn;
use Rappasoft\LaravelLivewireTables\Views\Columns\LinkColumn;
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 PetsTableLoadingPlaceholder extends DataTableComponent
{
public $model = Pet::class;

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

public function columns(): array
{
return [
Column::make('ID', 'id')
->sortable()
->setSortingPillTitle('Key')
->setSortingPillDirections('0-9', '9-0'),
Column::make('Sort')
->sortable()
->excludeFromColumnSelect(),
Column::make('Name')
->sortable()
->secondaryHeader($this->getFilterByKey('pet_name_filter'))
->footerFilter('pet_name_filter')
->searchable(),

Column::make('Age'),

Column::make('Breed', 'breed.name')
->secondaryHeaderFilter('breed')
->footer($this->getFilterByKey('breed'))
->sortable(
fn (Builder $query, string $direction) => $query->orderBy('pets.id', $direction)
)
->searchable(
fn (Builder $query, $searchTerm) => $query->orWhere('breed.name', $searchTerm)
),

Column::make('Other')
->label(function ($row, Column $column) {
return 'Other';
})
->footer(function ($rows) {
return 'Count: '.$rows->count();
}),

LinkColumn::make('Link')
->title(fn ($row) => 'Edit')
->location(fn ($row) => 'http://www.google.com')
->attributes(fn ($row) => [
'class' => 'rounded-full',
'alt' => $row->name.' Avatar',
]),
ImageColumn::make('RowImg')
->location(fn ($row) => 'test'.$row->id)
->attributes(fn ($row) => [
'class' => 'rounded-full',
'alt' => $row->name.' Avatar',
]),
Column::make('Last Visit', 'last_visit')
->sortable()
->deselected(),
];
}

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'),
];
}
}
47 changes: 41 additions & 6 deletions tests/Traits/Visuals/LoadingPlaceholderVisualsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,52 @@
namespace Rappasoft\LaravelLivewireTables\Tests\Traits\Visuals;

use Livewire\Livewire;
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable;
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTableLoadingPlaceholder;
use Rappasoft\LaravelLivewireTables\Tests\TestCase;

class LoadingPlaceholderVisualsTest extends TestCase
{
/** @test */
public function can_see_placeholder_text(): void
public function can_see_placeholder_section(): void
{
Livewire::test(PetsTable::class)
->call('setPerPageAccepted', [1])
->call('setPerPage', 1)
->assertSeeHtml('<nav role="navigation" aria-label="Pagination Navigation" class="flex items-center justify-between">');
Livewire::test(PetsTableLoadingPlaceholder::class)
->call('setPerPageAccepted', [1,5,10])
->assertSeeHtml('tr wire:key="table-loader" class="hidden d-none"')
->call('setPerPage', 5);
}

/** @test */
public function can_see_placeholder_custom_text(): void
{
Livewire::test(PetsTableLoadingPlaceholder::class)
->call('setPerPageAccepted', [1,5,10])
->assertSeeHtmlInOrder([
'<tr wire:key="table-loader" class="hidden d-none"',
'<td colspan="',
'<div class="h-min self-center align-middle text-center"',
'<div class="lds-hourglass"',
'<div>TestLoadingPlaceholderContentTestTest</div>'
])
->call('setPerPage', 5);
}

/** @test */
public function can_see_correct_placeholder_text_visually(): void
{
Livewire::test(PetsTableLoadingPlaceholder::class)
->call('setPerPageAccepted', [1,5,10])
->assertSee('TestLoadingPlaceholderContentTestTest')
->call('setPerPage', 5);
}

/** @test */
public function cannot_see_incorrect_placeholder_text_visually(): void
{
Livewire::test(PetsTableLoadingPlaceholder::class)
->call('setPerPageAccepted', [1,5,10])
->assertDontSee('TestLoadingPlaceholderContentTestTest22')
->call('setPerPage', 5);
}


}

0 comments on commit 18522b5

Please sign in to comment.