Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.

Commit 9a3ef90

Browse files
committed
Test for default values when using libraries
1 parent 80fb069 commit 9a3ef90

File tree

8 files changed

+679
-602
lines changed

8 files changed

+679
-602
lines changed

app/app/Http/Controllers/FormComponentsController.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ public function libraries()
7171
return view('form.components.libraries', ['countries' => $this->countries()]);
7272
}
7373

74+
public function libraryDefaults()
75+
{
76+
return view('form.components.libraryDefaults', [
77+
'defaults' => [
78+
'biography' => 'Voluptate ea culpa proident proident qui nostrud non ea irure ullamco in non reprehenderit.',
79+
'country' => 'NL',
80+
'countries' => ['BE', 'NL'],
81+
'date' => '2022-07-22',
82+
'time' => '13:37',
83+
'datetime' => '2022-07-22 13:37',
84+
'daterange' => '2022-07-22 to 2022-08-22',
85+
],
86+
'countries' => $this->countries(),
87+
]);
88+
}
89+
7490
public function custom()
7591
{
7692
return view('form.components.custom', ['countries' => $this->countries()]);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@extends('layout')
2+
3+
@section('content')
4+
5+
FormComponents
6+
7+
<div class="max-w-sm mx-auto px-4">
8+
<x-splade-form
9+
class="space-y-4"
10+
:action="route('form.components.submit')"
11+
:default="$defaults"
12+
>
13+
<x-splade-textarea name="biography" placeholder="Your Bio" autosize />
14+
15+
<x-splade-select name="country" :options="$countries" placeholder="Select your country" choices />
16+
<p class="mb-4" v-if="form.country">Selected country: <span v-text="form.country"></span></p>
17+
18+
<x-splade-select name="countries[]" :options="$countries" placeholder="Select your countries" multiple choices />
19+
<p class="mb-4" v-if="form.countries.length">Selected countries: <span v-text="form.countries.join(', ')"></span></p>
20+
21+
<x-splade-input placeholder="Date" name="date" date />
22+
<x-splade-input placeholder="Time" name="time" time />
23+
<x-splade-input placeholder="Datetime" name="datetime" date time />
24+
<x-splade-input placeholder="Date Range" name="daterange" date range />
25+
26+
<x-splade-submit />
27+
</x-splade-form>
28+
</div>
29+
30+
@endsection

app/routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777

7878
Route::get('form/components/simple', [FormComponentsController::class, 'simple'])->name('form.components.simple');
7979
Route::get('form/components/libraries', [FormComponentsController::class, 'libraries'])->name('form.components.libraries');
80+
Route::get('form/components/libraryDefaults', [FormComponentsController::class, 'libraryDefaults'])->name('form.components.libraryDefaults');
8081
Route::get('form/components/custom', [FormComponentsController::class, 'custom'])->name('form.components.custom');
8182
Route::get('form/components/defaults', [FormComponentsController::class, 'defaults'])->name('form.components.defaults');
8283
Route::get('form/components/defaultJson', [FormComponentsController::class, 'defaultJson'])->name('form.components.defaultJson');

app/tests/Browser/Form/LibrariesTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@
88

99
class LibrariesTest extends DuskTestCase
1010
{
11+
/** @test */
12+
public function it_select_the_default_values()
13+
{
14+
$this->browse(function (Browser $browser) {
15+
$browser->visit('form/components/libraryDefaults')
16+
->waitForText('FormComponents')
17+
->assertInputValue('biography', 'Voluptate ea culpa proident proident qui nostrud non ea irure ullamco in non reprehenderit.')
18+
->assertSeeIn('div[data-select-name="country"] .choices__item--selectable', 'Netherlands')
19+
->assertSeeIn('div[data-select-name="countries[]"] .choices__list--multiple', 'Belgium')
20+
->assertSeeIn('div[data-select-name="countries[]"] .choices__list--multiple', 'Netherlands')
21+
->assertInputValue('date', '2022-07-22')
22+
->assertInputValue('time', '13:37')
23+
->assertInputValue('datetime', '2022-07-22 13:37')
24+
->assertInputValue('daterange', '2022-07-22 to 2022-08-22');
25+
});
26+
}
27+
1128
/** @test */
1229
public function it_can_autosize_the_textarea()
1330
{

0 commit comments

Comments
 (0)