From 0e4bbb3e4b46599c456ef15ce633fc1280df8e2c Mon Sep 17 00:00:00 2001 From: Felipe Dalcin Date: Wed, 14 Feb 2024 15:03:10 -0500 Subject: [PATCH 1/2] fix: sort by `null` first with ascending order --- src/Views/AssignBooksTable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Views/AssignBooksTable.php b/src/Views/AssignBooksTable.php index d92f274e..f29e91ba 100644 --- a/src/Views/AssignBooksTable.php +++ b/src/Views/AssignBooksTable.php @@ -219,7 +219,7 @@ protected function getBooks(array $request): LengthAwarePaginator ->when($order, function (Builder $query, string $order) use ($direction) { if ($order === 'institution') { $query->orderByRaw( - $direction === 'asc' ? 'institution IS NULL' : 'institution IS NOT NULL' + $direction === 'asc' ? 'institution IS NOT NULL' : 'institution IS NULL' ); } From e0f6dd11fb6ee80419086c876cc4785803e5190a Mon Sep 17 00:00:00 2001 From: Felipe Dalcin Date: Wed, 14 Feb 2024 15:12:17 -0500 Subject: [PATCH 2/2] fix: tests --- tests/Feature/Views/AssignBooksTableTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/Feature/Views/AssignBooksTableTest.php b/tests/Feature/Views/AssignBooksTableTest.php index 60c72d78..616f736a 100644 --- a/tests/Feature/Views/AssignBooksTableTest.php +++ b/tests/Feature/Views/AssignBooksTableTest.php @@ -311,8 +311,8 @@ public function it_displays_information_sorted_by_name_in_descending_order(): vo $this->assertCount(2, $books); - $this->assertEquals('Fake Book', $books->first()->title); - $this->assertEquals('Another Fake Book', $books->last()->title); + $this->assertEquals('Another Fake Book', $books->first()->title); + $this->assertEquals('Fake Book', $books->last()->title); $_REQUEST['orderby'] = 'institution'; $_REQUEST['order'] = 'desc'; @@ -323,8 +323,8 @@ public function it_displays_information_sorted_by_name_in_descending_order(): vo $this->assertCount(2, $books); - $this->assertEquals('Another Fake Book', $books->first()->title); - $this->assertEquals('Fake Book', $books->last()->title); + $this->assertEquals('Fake Book', $books->first()->title); + $this->assertEquals('Another Fake Book', $books->last()->title); } /** @@ -343,8 +343,8 @@ public function it_displays_information_sorted_by_institution_in_ascending_order $this->assertCount(2, $books); - $this->assertEquals('Fake Book', $books->first()->title); - $this->assertEquals('Another Fake Book', $books->last()->title); + $this->assertEquals('Another Fake Book', $books->first()->title); + $this->assertEquals('Fake Book', $books->last()->title); } /** @@ -363,8 +363,8 @@ public function it_displays_information_sorted_by_institution_in_descending_orde $this->assertCount(2, $books); - $this->assertEquals('Another Fake Book', $books->first()->title); - $this->assertEquals('Fake Book', $books->last()->title); + $this->assertEquals('Fake Book', $books->first()->title); + $this->assertEquals('Another Fake Book', $books->last()->title); } protected function fakeBook(array $attributes = []): object