mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
feat: add trmnl catalog paginator
This commit is contained in:
parent
3250bb0402
commit
7f97114f6e
2 changed files with 134 additions and 13 deletions
|
|
@ -214,3 +214,73 @@ it('previews a recipe with async fetch', function (): void {
|
|||
->assertSee('Preview Weather Chum Updated')
|
||||
->assertSee('New bio');
|
||||
});
|
||||
|
||||
it('supports pagination and loading more recipes', function (): void {
|
||||
Http::fake([
|
||||
'usetrmnl.com/recipes.json?sort-by=newest&page=1' => Http::response([
|
||||
'data' => [
|
||||
[
|
||||
'id' => 1,
|
||||
'name' => 'Recipe Page 1',
|
||||
'icon_url' => null,
|
||||
'screenshot_url' => null,
|
||||
'author_bio' => null,
|
||||
'stats' => ['installs' => 1, 'forks' => 0],
|
||||
],
|
||||
],
|
||||
'next_page_url' => '/recipes.json?page=2',
|
||||
], 200),
|
||||
'usetrmnl.com/recipes.json?sort-by=newest&page=2' => Http::response([
|
||||
'data' => [
|
||||
[
|
||||
'id' => 2,
|
||||
'name' => 'Recipe Page 2',
|
||||
'icon_url' => null,
|
||||
'screenshot_url' => null,
|
||||
'author_bio' => null,
|
||||
'stats' => ['installs' => 2, 'forks' => 0],
|
||||
],
|
||||
],
|
||||
'next_page_url' => null,
|
||||
], 200),
|
||||
]);
|
||||
|
||||
Livewire::withoutLazyLoading();
|
||||
|
||||
Volt::test('catalog.trmnl')
|
||||
->assertSee('Recipe Page 1')
|
||||
->assertDontSee('Recipe Page 2')
|
||||
->assertSee('Load next page')
|
||||
->call('loadMore')
|
||||
->assertSee('Recipe Page 1')
|
||||
->assertSee('Recipe Page 2')
|
||||
->assertDontSee('Load next page');
|
||||
});
|
||||
|
||||
it('resets pagination when search term changes', function (): void {
|
||||
Http::fake([
|
||||
'usetrmnl.com/recipes.json?sort-by=newest&page=1' => Http::sequence()
|
||||
->push([
|
||||
'data' => [['id' => 1, 'name' => 'Initial 1']],
|
||||
'next_page_url' => '/recipes.json?page=2',
|
||||
])
|
||||
->push([
|
||||
'data' => [['id' => 3, 'name' => 'Initial 1 Again']],
|
||||
'next_page_url' => null,
|
||||
]),
|
||||
'usetrmnl.com/recipes.json?search=weather&sort-by=newest&page=1' => Http::response([
|
||||
'data' => [['id' => 2, 'name' => 'Weather Result']],
|
||||
'next_page_url' => null,
|
||||
]),
|
||||
]);
|
||||
|
||||
Livewire::withoutLazyLoading();
|
||||
|
||||
Volt::test('catalog.trmnl')
|
||||
->assertSee('Initial 1')
|
||||
->call('loadMore')
|
||||
->set('search', 'weather')
|
||||
->assertSee('Weather Result')
|
||||
->assertDontSee('Initial 1')
|
||||
->assertSet('page', 1);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue