Skip to content

Commit

Permalink
add swap test
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed May 11, 2022
1 parent 3d341b7 commit 56f9dff
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tests/admin/traits/SortableTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function testSorting()
'user3' => [
'id' => 3,
'title' => 2,
'firstname' => 'Is',
'lastname' => 'Deleted',
'firstname' => 'James',
'lastname' => 'Doe',
'email' => 'deleted@luya.io',
'password' => 'nohash',
'is_deleted' => 0,
Expand All @@ -51,10 +51,21 @@ public function testSorting()
]
]);

$q = UserStub::find()->asArray()->all();
$this->createAdminNgRestLogFixture();


// ensures the sort index title = 3 is the last item, which is array index 2
$q = UserStub::find()->asArray()->all();
$this->assertSame('Jane', $q[2]['firstname']);

// get last model (jane) and move to new position
$modelLast = UserStub::findOne(['id' => 2]);
$modelLast->title = 1;
$modelLast->save(true, ['title']);

// ensures the sort index title = 3 is the last item, which is now since jane has swap to first position James
$q = UserStub::find()->asArray()->all();
$this->assertSame('James', $q[2]['firstname']);
}
}

Expand Down

0 comments on commit 56f9dff

Please sign in to comment.