assertSeeHtml('
| assertSeeHtml(' | call('orderBy', 'name') ->assertSet('order', 'name') ->assertSet('orderDirection', 'asc') ->call('orderBy', 'name') ->assertSet('order', 'name') ->assertSet('orderDirection', 'desc') ->call('orderBy', 'name') ->assertSet('order', null) ->assertSet('orderDirection', null); }); it('resets to ascending when a different column is clicked', function () { Livewire::test(ProductsTable::class) ->call('orderBy', 'name') ->call('orderBy', 'name') ->assertSet('orderDirection', 'desc') ->call('orderBy', 'price') ->assertSet('order', 'price') ->assertSet('orderDirection', 'asc'); }); it('exposes the direction as a SortDirection', function () { $component = Livewire::test(ProductsTable::class); expect($component->instance()->getOrderDirection())->toBeNull(); $component->call('orderBy', 'name'); expect($component->instance()->getOrderDirection())->toBe(SortDirection::Ascending); $component->call('orderBy', 'name'); expect($component->instance()->getOrderDirection())->toBe(SortDirection::Descending); }); it('marks the ordered column in the header', function () { Livewire::test(ProductsTable::class) ->assertDontSeeHtml('ordered-asc') ->assertDontSeeHtml('ordered-desc') ->call('orderBy', 'name') ->assertSeeHtml('ordered-asc') ->assertDontSeeHtml('ordered-desc') ->call('orderBy', 'name') ->assertSeeHtml('ordered-desc') ->assertDontSeeHtml('ordered-asc'); }); it('applies the direction to the query', function () { $lowest = Product::orderBy('price')->orderBy('id')->value('id'); $highest = Product::orderByDesc('price')->orderByDesc('id')->value('id'); expect($lowest)->not->toBe($highest); Livewire::test(ProductsTable::class) // A single row of a single column, so the only | is the ordered id. ->set('activeColumns', ['id']) ->set('pageSize', 1) ->call('orderBy', 'price') ->assertSeeHtml(">{$lowest} | ") ->assertDontSeeHtml(">{$highest}") ->call('orderBy', 'price') ->assertSeeHtml(">{$highest}") ->assertDontSeeHtml(">{$lowest}"); }); it('restores the order from the query string', function () { $highest = Product::orderByDesc('price')->orderByDesc('id')->value('id'); Livewire::withQueryParams(['order' => 'price', 'orderDirection' => 'desc']) ->test(ProductsTable::class) ->assertSet('orderDirection', 'desc') ->assertSeeHtml('ordered-desc') ->set('activeColumns', ['id']) ->set('pageSize', 1) ->assertSeeHtml(">{$highest}"); }); it('ignores an unrecognised direction in the query string', function () { Livewire::withQueryParams(['order' => 'price', 'orderDirection' => 'nonsense']) ->test(ProductsTable::class) ->assertOk() ->assertDontSeeHtml('ordered-asc') ->assertDontSeeHtml('ordered-desc'); }); });
|---|