forked from livewire/livewire
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow page composition through Route::livewire
- Loading branch information
1 parent
0ecabb0
commit 4554501
Showing
3 changed files
with
67 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
@extends($layout) | ||
|
||
@section($section) | ||
@livewire($component, ...$componentOptions) | ||
@foreach($components as $component => $componentOptions) | ||
@livewire($component, ...$componentOptions) | ||
@endforeach | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Tests; | ||
|
||
use Livewire\Livewire; | ||
use Livewire\Component; | ||
use Illuminate\Support\Facades\Route; | ||
|
||
class PageCompositionTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function composes_page_with_a_single_component() | ||
{ | ||
Livewire::component('foo', ComposableComponent::class); | ||
|
||
Route::livewire('/test/{name}', 'foo')->middleware('web'); | ||
|
||
$this | ||
->get('/test/name-from-route') | ||
->assertSee('wire:name="foo"') | ||
->assertSeeText('name-from-route'); | ||
} | ||
|
||
/** @test */ | ||
public function composes_page_with_multiple_components() | ||
{ | ||
Livewire::component('foo', ComposableComponent::class); | ||
Livewire::component('bar', ComposableComponent::class); | ||
|
||
Route::livewire('/test/{name}', ['foo', 'bar'])->middleware('web'); | ||
|
||
$this | ||
->get('/test/name-from-route') | ||
->assertSeeInOrder(['wire:name="foo"', 'wire:name="bar"']) | ||
->assertSeeText('name-from-route'); | ||
} | ||
} | ||
|
||
class ComposableComponent extends Component | ||
{ | ||
public function mount(string $name) | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
public function render() | ||
{ | ||
return app('view')->make('show-name')->with('name', $this->name); | ||
} | ||
} |