Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing tests for WithCustomisations #2104

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 47 additions & 6 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ protected function setupBasicTable()
$this->basicTable->bootedWithColumnSelect();
$this->basicTable->bootedWithSecondaryHeader();
$this->basicTable->booted();
$this->basicTable->renderingWithPagination($view, []);
$this->basicTable->renderingWithColumns($view, $view->getData());
$this->basicTable->renderingWithColumnSelect($view, $view->getData());
$this->basicTable->renderingWithCustomisations($view, $view->getData());
$this->basicTable->renderingWithData($view, $view->getData());
$this->basicTable->renderingWithFooter($view, $view->getData());
$this->basicTable->renderingWithReordering($view, $view->getData());
$this->basicTable->renderingWithPagination($view, $view->getData());
$this->basicTable->render();
}

Expand All @@ -118,7 +124,14 @@ protected function setupEventsTable()
$this->eventsTable->bootedWithColumnSelect();
$this->eventsTable->bootedWithSecondaryHeader();
$this->eventsTable->booted();
$this->eventsTable->renderingWithPagination($view, []);
$this->eventsTable->renderingWithColumns($view, $view->getData());
$this->eventsTable->renderingWithColumnSelect($view, $view->getData());
$this->eventsTable->renderingWithCustomisations($view, $view->getData());
$this->eventsTable->renderingWithData($view, $view->getData());
$this->eventsTable->renderingWithFooter($view, $view->getData());
$this->eventsTable->renderingWithReordering($view, $view->getData());
$this->eventsTable->renderingWithPagination($view, $view->getData());

$this->eventsTable->render();
}

Expand All @@ -133,7 +146,13 @@ protected function setupBreedsTable()
$this->breedsTable->bootedWithColumnSelect();
$this->breedsTable->bootedWithSecondaryHeader();
$this->breedsTable->booted();
$this->breedsTable->renderingWithPagination($view, []);
$this->breedsTable->renderingWithColumns($view, $view->getData());
$this->breedsTable->renderingWithColumnSelect($view, $view->getData());
$this->breedsTable->renderingWithCustomisations($view, $view->getData());
$this->breedsTable->renderingWithData($view, $view->getData());
$this->breedsTable->renderingWithFooter($view, $view->getData());
$this->breedsTable->renderingWithReordering($view, $view->getData());
$this->breedsTable->renderingWithPagination($view, $view->getData());
$this->breedsTable->render();
}

Expand All @@ -148,7 +167,13 @@ protected function setupPetOwnerTable()
$this->petOwnerTable->bootedWithColumnSelect();
$this->petOwnerTable->bootedWithSecondaryHeader();
$this->petOwnerTable->booted();
$this->petOwnerTable->renderingWithPagination($view, []);
$this->petOwnerTable->renderingWithColumns($view, $view->getData());
$this->petOwnerTable->renderingWithColumnSelect($view, $view->getData());
$this->petOwnerTable->renderingWithCustomisations($view, $view->getData());
$this->petOwnerTable->renderingWithData($view, $view->getData());
$this->petOwnerTable->renderingWithFooter($view, $view->getData());
$this->petOwnerTable->renderingWithReordering($view, $view->getData());
$this->petOwnerTable->renderingWithPagination($view, $view->getData());
$this->petOwnerTable->render();
}

Expand All @@ -163,7 +188,13 @@ protected function setupSpeciesTable()
$this->speciesTable->bootedWithColumnSelect();
$this->speciesTable->bootedWithSecondaryHeader();
$this->speciesTable->booted();
$this->speciesTable->renderingWithPagination($view, []);
$this->speciesTable->renderingWithColumns($view, $view->getData());
$this->speciesTable->renderingWithColumnSelect($view, $view->getData());
$this->speciesTable->renderingWithCustomisations($view, $view->getData());
$this->speciesTable->renderingWithData($view, $view->getData());
$this->speciesTable->renderingWithFooter($view, $view->getData());
$this->speciesTable->renderingWithReordering($view, $view->getData());
$this->speciesTable->renderingWithPagination($view, $view->getData());
$this->speciesTable->render();
}

Expand All @@ -179,7 +210,13 @@ protected function setupUnpaginatedTable()
$this->unpaginatedTable->bootedWithColumnSelect();
$this->unpaginatedTable->bootedWithSecondaryHeader();
$this->unpaginatedTable->booted();
$this->unpaginatedTable->renderingWithPagination($view, []);
$this->unpaginatedTable->renderingWithColumns($view, $view->getData());
$this->unpaginatedTable->renderingWithColumnSelect($view, $view->getData());
$this->unpaginatedTable->renderingWithCustomisations($view, $view->getData());
$this->unpaginatedTable->renderingWithData($view, $view->getData());
$this->unpaginatedTable->renderingWithFooter($view, $view->getData());
$this->unpaginatedTable->renderingWithReordering($view, $view->getData());
$this->unpaginatedTable->renderingWithPagination($view, $view->getData());
$this->unpaginatedTable->render();

}
Expand All @@ -202,6 +239,10 @@ public function getEnvironmentSetUp($app): void
config()->set('view.cache', false);
config()->set('view.compiled', realpath(storage_path('framework/views')).'/'.rand(0, 100));
// config()->set('livewire-tables.use_json_translations', true);
$app['config']->set('view.paths', [
__DIR__.'/views',
resource_path('views'),
]);

$app['config']->set('app.env', 'testing');
$app['config']->set('database.default', 'sqlite');
Expand Down
178 changes: 178 additions & 0 deletions tests/Unit/Traits/WithCustomisationsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Traits;

use Livewire\Component;
use Livewire\Features\SupportPageComponents\PageComponentConfig;
use Livewire\Livewire;
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable;
use Rappasoft\LaravelLivewireTables\Tests\TestCase;

final class WithCustomisationsTest extends TestCase
{
public function test_can_use_as_nested(): void
{
$test = Livewire::test([new class extends Component
{
public function render()
{
return <<<'HTML'
<div>
<div>ParentComponentTest</div>
<div> <livewire:child /></div>
</div>
HTML;
}
},
'child' => new class extends PetsTable
{
public function configure(): void
{
parent::configure();
$this->setLayout('livewire-tables::tests.layout1');

}
},
])
->assertSee('ParentComponentTest')
->assertSee('Cartman');

}

public function test_can_use_as_full_page(): void
{
$temp = new class extends PetsTable
{
public function configure(): void
{
parent::configure();

$this->setLayout('livewire-tables::tests.layout1');

}
};
$view = view('livewire-tables::datatable');

$temp->boot();
$temp->bootedComponentUtilities();
$temp->bootedWithData();
$temp->bootedWithColumns();
$temp->bootedWithColumnSelect();
$temp->bootedWithSecondaryHeader();
$temp->booted();
$temp->renderingWithColumns($view, $view->getData());
$temp->renderingWithColumnSelect($view, $view->getData());
$temp->renderingWithCustomisations($view, $view->getData());
$temp->renderingWithData($view, $view->getData());
$temp->renderingWithFooter($view, $view->getData());
$temp->renderingWithReordering($view, $view->getData());
$temp->renderingWithPagination($view, $view->getData());
$temp->render();
$layoutConfig = $view->getData()['layoutConfig'];

$this->assertSame($temp->getLayout(), $layoutConfig->view);
}

public function test_can_set_custom_section(): void
{
$temp = new class extends PetsTable
{
public function configure(): void
{
parent::configure();

$this->setSection('test-section-1');

}
};
$view = view('livewire-tables::datatable');

$temp->boot();
$temp->bootedComponentUtilities();
$temp->bootedWithData();
$temp->bootedWithColumns();
$temp->bootedWithColumnSelect();
$temp->bootedWithSecondaryHeader();
$temp->booted();
$temp->renderingWithColumns($view, $view->getData());
$temp->renderingWithColumnSelect($view, $view->getData());
$temp->renderingWithCustomisations($view, $view->getData());
$temp->renderingWithData($view, $view->getData());
$temp->renderingWithFooter($view, $view->getData());
$temp->renderingWithReordering($view, $view->getData());
$temp->renderingWithPagination($view, $view->getData());
$temp->render();
$layoutConfig = $view->getData()['layoutConfig'];

$this->assertSame($temp->getSection(), $layoutConfig->slotOrSection);
}

public function test_can_set_custom_slot(): void
{
$temp = new class extends PetsTable
{
public function configure(): void
{
parent::configure();

$this->setSlot('test-slot-1');

}
};
$view = view('livewire-tables::datatable');

$temp->boot();
$temp->bootedComponentUtilities();
$temp->bootedWithData();
$temp->bootedWithColumns();
$temp->bootedWithColumnSelect();
$temp->bootedWithSecondaryHeader();
$temp->booted();
$temp->renderingWithColumns($view, $view->getData());
$temp->renderingWithColumnSelect($view, $view->getData());
$temp->renderingWithCustomisations($view, $view->getData());
$temp->renderingWithData($view, $view->getData());
$temp->renderingWithFooter($view, $view->getData());
$temp->renderingWithReordering($view, $view->getData());
$temp->renderingWithPagination($view, $view->getData());
$temp->render();
$layoutConfig = $view->getData()['layoutConfig'];

$this->assertSame($temp->getSlot(), $layoutConfig->slotOrSection);
}

public function test_can_set_custom_extends(): void
{
$temp = new class extends PetsTable
{
public function configure(): void
{
parent::configure();

$this->setExtends('test-extends-1');

}
};
$view = view('livewire-tables::datatable');

$temp->boot();
$temp->bootedComponentUtilities();
$temp->bootedWithData();
$temp->bootedWithColumns();
$temp->bootedWithColumnSelect();
$temp->bootedWithSecondaryHeader();
$temp->booted();
$temp->renderingWithColumns($view, $view->getData());
$temp->renderingWithColumnSelect($view, $view->getData());
$temp->renderingWithCustomisations($view, $view->getData());
$temp->renderingWithData($view, $view->getData());
$temp->renderingWithFooter($view, $view->getData());
$temp->renderingWithReordering($view, $view->getData());
$temp->renderingWithPagination($view, $view->getData());
$temp->render();
$layoutConfig = $view->getData()['layoutConfig'];
$this->assertSame('extends', $layoutConfig->type);
$this->assertSame($temp->getExtends(), $layoutConfig->view);
$this->assertSame('content', $layoutConfig->slotOrSection);
}
}
13 changes: 13 additions & 0 deletions tests/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<html>
<head>
<meta name="csrf-token" content="{{ csrf_token() }}">
</head>
<body>
Laravel Testing Layout
<div>
{{ $slot }}
</div>
</body>
</html>