Skip to content

Commit

Permalink
Add nested module test
Browse files Browse the repository at this point in the history
  • Loading branch information
ifox committed Jul 6, 2020
1 parent cd50ea9 commit b2c2b01
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions tests/integration/ModulesCategoriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace A17\Twill\Tests\Integration;

use App\Models\Category;

class ModulesCategoriesTest extends ModulesTestBase
{
public function testCanDisplayModuleInNavigation()
Expand Down Expand Up @@ -37,4 +39,75 @@ public function testCanShowCategoriesIndex()
count(json_decode($this->content(), true)['tableData'])
);
}

public function testCanReorderCategories()
{
$this->createCategory(2);

$category1 = Category::ordered()
->get()
->first();

$category2 = Category::orderBy('position', 'desc')
->first();

$this->assertEquals(1, $category1->position);
$this->assertEquals(2, $category2->position);

$this->request('/twill/categories/reorder', 'POST', [
'ids' => [
[
'id' => $category2->id,
'children' => [],
],
[
'id' => $category1->id,
'children' => [],
],
],
])->assertStatus(200);

$this->assertNothingWrongHappened();

$category1->refresh();
$category2->refresh();

$this->assertEquals(1, $category1->position);
$this->assertEquals(0, $category2->position);
}

public function testCanNestCategories()
{
$this->createCategory(2);

$category1 = Category::ordered()
->get()
->first();

$category2 = Category::orderBy('position', 'desc')
->first();

$this->request('/twill/categories/reorder', 'POST', [
'ids' => [
[
'id' => $category2->id,
'children' => [
[
'id' => $category1->id,
'children' => [],
],
],
],
],
])->assertStatus(200);

$this->assertNothingWrongHappened();

$category1->refresh();
$category2->refresh();

$this->assertTrue($category2->isAncestorOf($category1));
$this->assertEquals(0, $category1->position);
$this->assertEquals($category2->title, $category1->parent->title);
}
}

0 comments on commit b2c2b01

Please sign in to comment.