generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
103 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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace Tonysm\TurboLaravel\Tests\Http; | ||
|
||
use Illuminate\Support\Facades\View; | ||
use Tonysm\TurboLaravel\Tests\TestCase; | ||
|
||
class ResponseMacrosTest extends TestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
View::addNamespace('test-stubs', __DIR__ . '/stubs/'); | ||
} | ||
|
||
/** @test */ | ||
public function streams_model_on_create() | ||
{ | ||
$testModel = TestModel::create(['name' => 'test']); | ||
|
||
$expected = <<<html | ||
<turbo-stream target="test_models" action="append"> | ||
<template> | ||
<div id="test_model_{$testModel->id}">hello</div> | ||
</template> | ||
</turbo-stream> | ||
html; | ||
|
||
$resp = response()->turboStream($testModel); | ||
|
||
$this->assertEquals($expected, trim($resp->getContent())); | ||
$this->assertEquals('text/html; turbo-stream', $resp->headers->get('Content-Type')); | ||
} | ||
|
||
/** @test */ | ||
public function streams_model_on_update() | ||
{ | ||
$testModel = TestModel::create(['name' => 'test'])->fresh(); | ||
|
||
$expected = <<<html | ||
<turbo-stream target="test_model_{$testModel->id}" action="replace"> | ||
<template> | ||
<div id="test_model_{$testModel->id}">hello</div> | ||
</template> | ||
</turbo-stream> | ||
html; | ||
|
||
$resp = response()->turboStream($testModel); | ||
|
||
$this->assertEquals($expected, trim($resp->getContent())); | ||
$this->assertEquals('text/html; turbo-stream', $resp->headers->get('Content-Type')); | ||
} | ||
|
||
/** @test */ | ||
public function streams_model_on_delete() | ||
{ | ||
$testModel = tap(TestModel::create(['name' => 'test']))->delete(); | ||
|
||
$expected = <<<html | ||
<turbo-stream target="test_model_{$testModel->id}" action="remove"></turbo-stream> | ||
html; | ||
|
||
$resp = response()->turboStream($testModel); | ||
|
||
$this->assertEquals($expected, trim($resp->getContent())); | ||
$this->assertEquals('text/html; turbo-stream', $resp->headers->get('Content-Type')); | ||
} | ||
|
||
/** @test */ | ||
public function streams_custom_view() | ||
{ | ||
$testModel = TestModel::create(['name' => 'test']); | ||
|
||
$expected = <<<html | ||
<div id="test_model_{$testModel->id}">hello</div> | ||
html; | ||
|
||
$resp = response()->turboStreamView(View::file(__DIR__ . '/stubs/_test_model.blade.php', [ | ||
'testModel' => $testModel, | ||
])); | ||
|
||
$this->assertEquals($expected, trim($resp->getContent())); | ||
$this->assertEquals('text/html; turbo-stream', $resp->headers->get('Content-Type')); | ||
} | ||
} | ||
|
||
class TestModel extends \Tonysm\TurboLaravel\Tests\TestModel | ||
{ | ||
public function hotwirePartialName() | ||
{ | ||
return "test-stubs::_test_model"; | ||
} | ||
} |
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 @@ | ||
<div id="@domid($testModel)">hello</div> |