-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Slot method on view class is not working (#2341)
* Added tests for all view macro functions and added new setSlot method to set a default of a component slot * Removed dubble underscore * Added withoutExceptionHandling to see why the test is failing Signed-off-by: Gertjan Roke <gertjan@2solar.nl> * Added tests to test all view functions Signed-off-by: Gertjan Roke <g.a.roke90@gmail.com> * Removed setSlot method because it should not be in this branch Signed-off-by: Gertjan Roke <g.a.roke90@gmail.com> * Fixed the failing test for the slot method Signed-off-by: Gertjan Roke <g.a.roke90@gmail.com> Co-authored-by: Gertjan Roke <gertjan@2solar.nl>
- Loading branch information
1 parent
8663232
commit b430180
Showing
7 changed files
with
100 additions
and
3 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
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,3 +1,5 @@ | ||
@component($view, $params) | ||
{!! $manager->initialDehydrate()->toInitialResponse()->effects['html']; !!} | ||
@slot($slotOrSection) | ||
{!! $manager->initialDehydrate()->toInitialResponse()->effects['html']; !!} | ||
@endslot | ||
@endcomponent |
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,90 @@ | ||
<?php | ||
|
||
namespace Tests\Unit; | ||
|
||
use Illuminate\Support\Facades\Route; | ||
use Livewire\Component; | ||
use Livewire\Livewire; | ||
|
||
class ComponentLayoutTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function can_extend_a_blade_layout() | ||
{ | ||
Livewire::component(ComponentWithExtendsLayout::class); | ||
|
||
Route::get('/foo', ComponentWithExtendsLayout::class); | ||
|
||
$this->get('/foo')->assertSee('baz'); | ||
} | ||
|
||
/** @test */ | ||
public function can_set_custom_section() | ||
{ | ||
Livewire::component(ComponentWithCustomSection::class); | ||
|
||
Route::get('/foo', ComponentWithCustomSection::class); | ||
|
||
$this->get('/foo')->assertSee('baz'); | ||
} | ||
|
||
/** @test */ | ||
public function can_set_custom_layout() | ||
{ | ||
Livewire::component(ComponentWithCustomLayout::class); | ||
|
||
Route::get('/foo', ComponentWithCustomLayout::class); | ||
|
||
$this->get('/foo')->assertSee('baz'); | ||
} | ||
|
||
/** @test */ | ||
public function can_set_custom_slot_for_a_layout() | ||
{ | ||
Livewire::component(ComponentWithCustomSlotForLayout::class); | ||
|
||
Route::get('/foo', ComponentWithCustomSlotForLayout::class); | ||
|
||
$this->withoutExceptionHandling()->get('/foo')->assertSee('baz'); | ||
} | ||
} | ||
|
||
class ComponentWithExtendsLayout extends Component | ||
{ | ||
public function render() | ||
{ | ||
return view('null-view')->extends('layouts.app-extends', [ | ||
'bar' => 'baz' | ||
]); | ||
} | ||
} | ||
|
||
class ComponentWithCustomSection extends Component | ||
{ | ||
public $name = 'baz'; | ||
|
||
public function render() | ||
{ | ||
return view('show-name')->extends('layouts.app-custom-section')->section('body'); | ||
} | ||
} | ||
|
||
class ComponentWithCustomLayout extends Component | ||
{ | ||
public function render() | ||
{ | ||
return view('null-view')->layout('layouts.app-with-bar', [ | ||
'bar' => 'baz' | ||
]); | ||
} | ||
} | ||
|
||
class ComponentWithCustomSlotForLayout extends Component | ||
{ | ||
public $name = 'baz'; | ||
|
||
public function render() | ||
{ | ||
return view('show-name')->layout('layouts.app-custom-slot')->slot('main'); | ||
} | ||
} |
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 @@ | ||
@yield('body') |
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 @@ | ||
{{ $main }} |
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,3 @@ | ||
@yield('content') | ||
|
||
{{ $bar }} |