-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from chrisrhymes/feature/pagination-views
Added pagination views and tests
- Loading branch information
Showing
10 changed files
with
312 additions
and
0 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
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,48 @@ | ||
<div> | ||
@if ($paginator->hasPages()) | ||
<nav class="pagination"> | ||
|
||
{{-- Previous Page Link --}} | ||
@if ($paginator->onFirstPage()) | ||
<a class="pagination-previous" aria-disabled="true" disabled> | ||
@lang('pagination.previous') | ||
</a> | ||
@else | ||
<a class="pagination-previous" wire:click="previousPage" wire:loading.attr="disabled" wire:key="previousPage"> | ||
@lang('pagination.previous') | ||
</a> | ||
@endif | ||
|
||
{{-- Next Page Link --}} | ||
@if ($paginator->hasMorePages()) | ||
<a class="pagination-next" wire:click="nextPage" wire:loading.attr="disabled" wire:key="nextPage"> | ||
@lang('pagination.next') | ||
</a> | ||
@else | ||
<a class="pagination-next" aria-disabled="true" disabled> | ||
@lang('pagination.next') | ||
</a> | ||
@endif | ||
|
||
<ul class="pagination-list"> | ||
@foreach ($elements as $element) | ||
|
||
@if (is_string($element)) | ||
<li><span class="pagination-ellipsis">…</span></li> | ||
@endif | ||
|
||
@if (is_array($element)) | ||
@foreach ($element as $page => $url) | ||
@if ($page == $paginator->currentPage()) | ||
<li><a class="pagination-link is-current" aria-label="Goto page {{ $page }}">{{ $page }}</a></li> | ||
@else | ||
<li><a wire:click="goToPage({{ $page }})" wire:key="goToPage{{ $page }}" class="pagination-link" aria-label="Goto page {{ $page }}">{{ $page }}</a></li> | ||
@endif | ||
@endforeach | ||
@endif | ||
@endforeach | ||
</ul> | ||
|
||
</nav> | ||
@endif | ||
</div> |
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,29 @@ | ||
<div> | ||
@if ($paginator->hasPages()) | ||
<nav class="pagination"> | ||
|
||
{{-- Previous Page Link --}} | ||
@if ($paginator->onFirstPage()) | ||
<a class="pagination-previous" aria-disabled="true" disabled> | ||
@lang('pagination.previous') | ||
</a> | ||
@else | ||
<a class="pagination-previous" wire:click="previousPage" wire:loading.attr="disabled" wire:key="previousPage"> | ||
@lang('pagination.previous') | ||
</a> | ||
@endif | ||
|
||
{{-- Next Page Link --}} | ||
@if ($paginator->hasMorePages()) | ||
<a class="pagination-next" wire:click="nextPage" wire:loading.attr="disabled" wire:key="nextPage"> | ||
@lang('pagination.next') | ||
</a> | ||
@else | ||
<a class="pagination-next" aria-disabled="true" disabled> | ||
@lang('pagination.next') | ||
</a> | ||
@endif | ||
|
||
</nav> | ||
@endif | ||
</div> |
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,36 @@ | ||
@if ($paginator->hasPages()) | ||
<nav class="pagination is-centered" role="navigation" aria-label="pagination"> | ||
|
||
@if ($paginator->onFirstPage()) | ||
<a class="pagination-previous" disabled>Previous</a> | ||
@else | ||
<a class="pagination-previous" href="{{ $paginator->previousPageUrl() }}">Previous</a> | ||
@endif | ||
|
||
@if ($paginator->hasMorePages()) | ||
<a class="pagination-next" href="{{ $paginator->nextPageUrl() }}">Next Page</a> | ||
@else | ||
<a class="pagination-next" disabled>Next Page</a> | ||
@endif | ||
|
||
<ul class="pagination-list"> | ||
@foreach ($elements as $element) | ||
|
||
@if (is_string($element)) | ||
<li><span class="pagination-ellipsis">…</span></li> | ||
@endif | ||
|
||
@if (is_array($element)) | ||
@foreach ($element as $page => $url) | ||
@if ($page == $paginator->currentPage()) | ||
<li><a class="pagination-link is-current" aria-label="Goto page {{ $page }}">{{ $page }}</a></li> | ||
@else | ||
<li><a href="{{ $url }}" class="pagination-link" aria-label="Goto page {{ $page }}">{{ $page }}</a></li> | ||
@endif | ||
@endforeach | ||
@endif | ||
@endforeach | ||
</ul> | ||
|
||
</nav> | ||
@endif |
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,17 @@ | ||
@if ($paginator->hasPages()) | ||
<nav class="pagination is-centered" role="navigation" aria-label="pagination"> | ||
|
||
@if ($paginator->onFirstPage()) | ||
<a class="pagination-previous" disabled>Previous</a> | ||
@else | ||
<a class="pagination-previous" href="{{ $paginator->previousPageUrl() }}">Previous</a> | ||
@endif | ||
|
||
@if ($paginator->hasMorePages()) | ||
<a class="pagination-next" href="{{ $paginator->nextPageUrl() }}">Next Page</a> | ||
@else | ||
<a class="pagination-next" disabled>Next Page</a> | ||
@endif | ||
|
||
</nav> | ||
@endif |
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,29 @@ | ||
<?php | ||
|
||
namespace Tests; | ||
|
||
use Tests\Models\User; | ||
|
||
class DBTestCase extends TestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
User::create([ | ||
'name' => 'Dave', | ||
'email' => 'dave@example.com', | ||
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', | ||
]); | ||
User::create([ | ||
'name' => 'George', | ||
'email' => 'george@example.com', | ||
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', | ||
]); | ||
} | ||
|
||
protected function defineDatabaseMigrations() | ||
{ | ||
$this->loadLaravelMigrations(); | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
namespace Tests\Models; | ||
|
||
use Illuminate\Contracts\Auth\Authenticatable; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class User extends Model implements Authenticatable | ||
{ | ||
use HasFactory; | ||
|
||
protected $table = 'users'; | ||
|
||
protected $guarded = []; | ||
|
||
protected $fillable = ['id', 'name', 'email', 'password']; | ||
|
||
public function getAuthIdentifierName() | ||
{ | ||
return 'id'; | ||
} | ||
|
||
public function getAuthIdentifier() | ||
{ | ||
$name = $this->getAuthIdentifierName(); | ||
|
||
return $this->attributes[$name]; | ||
} | ||
|
||
public function getAuthPassword() | ||
{ | ||
return $this->attributes['password']; | ||
} | ||
|
||
public function getRememberToken() | ||
{ | ||
return 'token'; | ||
} | ||
|
||
public function setRememberToken($value) | ||
{ | ||
} | ||
|
||
public function getRememberTokenName() | ||
{ | ||
return 'tokenName'; | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace Tests\Views; | ||
|
||
use Tests\DBTestCase; | ||
use Tests\Models\User; | ||
|
||
class PaginationTest extends DBTestCase | ||
{ | ||
/** @test */ | ||
public function it_renders_pagination() | ||
{ | ||
$view = $this->blade( | ||
'{{ $users->links("bbui::pagination") }}', | ||
['users' => User::paginate(1)] | ||
); | ||
|
||
$view->assertSee('<nav class="pagination is-centered" role="navigation" aria-label="pagination">', false); | ||
$view->assertSee('Goto page 1'); | ||
$view->assertSee('Goto page 2'); | ||
$view->assertSee('pagination-previous'); | ||
$view->assertSee('pagination-next'); | ||
} | ||
|
||
/** @test */ | ||
public function it_does_not_render_pagination_when_not_needed() | ||
{ | ||
$view = $this->blade( | ||
'{{ $users->links("bbui::pagination") }}', | ||
['users' => User::paginate(3)] | ||
); | ||
|
||
$view->assertDontSee('<nav class="pagination is-centered" role="navigation" aria-label="pagination">', false); | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace Tests\Views; | ||
|
||
use Tests\DBTestCase; | ||
use Tests\Models\User; | ||
|
||
class SimplePaginationTest extends DBTestCase | ||
{ | ||
/** @test */ | ||
public function it_renders_pagination() | ||
{ | ||
$view = $this->blade( | ||
'{{ $users->links("bbui::simple-pagination") }}', | ||
['users' => User::paginate(1)] | ||
); | ||
|
||
$view->assertSee('<nav class="pagination is-centered" role="navigation" aria-label="pagination">', false); | ||
$view->assertDontSee('Goto page 1'); | ||
$view->assertDontSee('Goto page 2'); | ||
$view->assertSee('pagination-previous'); | ||
$view->assertSee('pagination-next'); | ||
} | ||
|
||
/** @test */ | ||
public function it_does_not_render_pagination_when_not_needed() | ||
{ | ||
$view = $this->blade( | ||
'{{ $users->links("bbui::simple-pagination") }}', | ||
['users' => User::paginate(3)] | ||
); | ||
|
||
$view->assertDontSee('<nav class="pagination is-centered" role="navigation" aria-label="pagination">', false); | ||
} | ||
} |