This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test + improved Vue props object merger
- Loading branch information
1 parent
d8b898c
commit f920f04
Showing
22 changed files
with
211 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace App\View\Components; | ||
|
||
use Closure; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\View\Component; | ||
use ProtoneMedia\SpladeCore\Attributes\VueProp; | ||
|
||
class ToVueProp extends Component | ||
{ | ||
#[VueProp] | ||
public mixed $mixed = 'foo'; | ||
|
||
#[VueProp] | ||
public string $string = 'foo'; | ||
|
||
#[VueProp] | ||
public string $defaultString = 'foo'; | ||
|
||
#[VueProp] | ||
public ?string $nullableString = null; | ||
|
||
/** | ||
* Create a new component instance. | ||
*/ | ||
public function __construct( | ||
#[VueProp] public int $int, | ||
#[VueProp] public bool $bool, | ||
#[VueProp] public array $array, | ||
#[VueProp] public object $object, | ||
#[VueProp] public ?int $nullableInt = null, | ||
#[VueProp] public ?bool $nullableBool = null, | ||
#[VueProp] public ?array $nullableArray = null, | ||
#[VueProp] public ?object $nullableObject = null, | ||
#[VueProp] public int $defaultInt = 1, | ||
#[VueProp] public bool $defaultBool = true, | ||
#[VueProp] public array $defaultArray = ['foo'], | ||
#[VueProp] public array|bool|string $multipleTypes = ['foo'], | ||
) { | ||
} | ||
|
||
/** | ||
* Get the view / contents that represent the component. | ||
*/ | ||
public function render(): View|Closure|string | ||
{ | ||
return view('components.to-vue-prop'); | ||
} | ||
} |
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,19 @@ | ||
<script setup></script> | ||
<div> | ||
<p>Mixed: <span v-text="mixed" /></p> | ||
<p>String: <span v-text="string" /></p> | ||
<p>Default String: <span v-text="defaultString" /></p> | ||
<p>Nullable String: <span v-text="nullableString" /></p> | ||
<p>Int: <span v-text="int" /></p> | ||
<p>Bool: <span v-text="bool" /></p> | ||
<p>Array: <span v-text="array" /></p> | ||
<p>Object: <span v-text="object" /></p> | ||
<p>Nullable Int: <span v-text="nullableInt" /></p> | ||
<p>Nullable Bool: <span v-text="nullableBool" /></p> | ||
<p>Nullable Array: <span v-text="nullableArray" /></p> | ||
<p>Nullable Object: <span v-text="nullableObject" /></p> | ||
<p>Default Int: <span v-text="defaultInt" /></p> | ||
<p>Default Bool: <span v-text="defaultBool" /></p> | ||
<p>Default Array: <span v-text="defaultArray" /></p> | ||
<p>Multiple Types: <span v-text="multipleTypes" /></p> | ||
</div> |
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,8 @@ | ||
<x-layout> | ||
<x-to-vue-prop | ||
:int="1" | ||
:bool="false" | ||
:array="['foo', 'bar']" | ||
:object="(object) ['foo' => 'bar']" | ||
/> | ||
</x-layout> |
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,33 @@ | ||
<?php | ||
|
||
namespace Tests\Browser; | ||
|
||
use Laravel\Dusk\Browser; | ||
use Tests\DuskTestCase; | ||
|
||
class ToVuePropTest extends DuskTestCase | ||
{ | ||
/** @test */ | ||
public function it_can_pass_blade_props_as_vue_rops() | ||
{ | ||
$this->browse(function (Browser $browser) { | ||
$browser->visit('/to-vue-prop') | ||
->waitForText('Splade Core demo app') | ||
->assertSee('Mixed: foo') | ||
->assertSee('String: foo') | ||
->assertSee('Default String: foo') | ||
->assertSee('Nullable String:') | ||
->assertSee('Int: 1') | ||
->assertSee('Bool: false') | ||
->assertSee('Array: { "foo": "bar" }') | ||
->assertSee('Object: { "foo": "bar" }') | ||
->assertSee('Nullable Int:') | ||
->assertSee('Nullable Bool:') | ||
->assertSee('Nullable Array:') | ||
->assertSee('Nullable Object:') | ||
->assertSee('Default Int: 1') | ||
->assertSee('Default Bool: true') | ||
->assertSee('Default Array: [ "foo" ]'); | ||
}); | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
app/tests/Unit/Console/__snapshots__/BuildComponentsTest__it_builds_the_components__1.vue
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
2 changes: 1 addition & 1 deletion
2
app/tests/Unit/Console/__snapshots__/BuildComponentsTest__it_builds_the_components__10.vue
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
2 changes: 1 addition & 1 deletion
2
app/tests/Unit/Console/__snapshots__/BuildComponentsTest__it_builds_the_components__11.vue
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
33 changes: 33 additions & 0 deletions
33
app/tests/Unit/Console/__snapshots__/BuildComponentsTest__it_builds_the_components__12.vue
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,33 @@ | ||
<script setup> | ||
import { GenericSpladeComponent } from '@protonemedia/laravel-splade-core' | ||
import { h } from 'vue' | ||
const props = defineProps({ | ||
spladeBridge: Object, | ||
spladeTemplateId: String, | ||
mixed: { default: 'foo' }, | ||
string: { type: String, default: 'foo' }, | ||
defaultString: { type: String, default: 'foo' }, | ||
nullableString: { type: String, default: null }, | ||
int: { type: Number, default: null }, | ||
bool: { type: Boolean, default: null }, | ||
array: { type: Array, default: null }, | ||
object: { type: Object, default: null }, | ||
nullableInt: { type: Number, default: null }, | ||
nullableBool: { type: Boolean, default: null }, | ||
nullableArray: { type: Array, default: null }, | ||
nullableObject: { type: Object, default: null }, | ||
defaultInt: { type: Number, default: 1 }, | ||
defaultBool: { type: Boolean, default: true }, | ||
defaultArray: { type: Array, default: JSON.parse('[\u0022foo\u0022]') }, | ||
multipleTypes: { type: [Array, String, Boolean], default: JSON.parse('[\u0022foo\u0022]') }, | ||
}) | ||
const spladeRender = h({ | ||
name: 'SpladeComponentToVuePropRender', | ||
components: { GenericSpladeComponent }, | ||
template: spladeTemplates[props.spladeTemplateId], | ||
data: () => { | ||
return { ...props } | ||
}, | ||
}) | ||
</script> | ||
<template><spladeRender /></template> |
2 changes: 1 addition & 1 deletion
2
app/tests/Unit/Console/__snapshots__/BuildComponentsTest__it_builds_the_components__2.vue
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
2 changes: 1 addition & 1 deletion
2
app/tests/Unit/Console/__snapshots__/BuildComponentsTest__it_builds_the_components__3.vue
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
2 changes: 1 addition & 1 deletion
2
app/tests/Unit/Console/__snapshots__/BuildComponentsTest__it_builds_the_components__4.vue
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
2 changes: 1 addition & 1 deletion
2
app/tests/Unit/Console/__snapshots__/BuildComponentsTest__it_builds_the_components__5.vue
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
2 changes: 1 addition & 1 deletion
2
app/tests/Unit/Console/__snapshots__/BuildComponentsTest__it_builds_the_components__6.vue
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
2 changes: 1 addition & 1 deletion
2
app/tests/Unit/Console/__snapshots__/BuildComponentsTest__it_builds_the_components__7.vue
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
2 changes: 1 addition & 1 deletion
2
app/tests/Unit/Console/__snapshots__/BuildComponentsTest__it_builds_the_components__8.vue
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
2 changes: 1 addition & 1 deletion
2
app/tests/Unit/Console/__snapshots__/BuildComponentsTest__it_builds_the_components__9.vue
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
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
Oops, something went wrong.