Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add failing test for x-model on checkboxes inside conditional #5454

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/Browser/AlpineV3/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Browser\AlpineV3;

use Livewire\Livewire;
use Tests\Browser\Alpine\Test as V2Test;

class Test extends V2Test
Expand All @@ -12,4 +13,17 @@ public function setUp(): void

parent::setUp();
}

public function test_alpine_registers_correct_number_of_listeners_for_x_model_checkbox_on_livewire_change()
{
$this->browse(function ($browser) {
Livewire::visit($browser, XModelComponent::class)
->waitForLivewire()
->click('@show')
->click('@plz-check-me-caleb')
->assertSeeIn('@alpineChecksLength', 1)
->assertSeeIn('@alpineChecksValue', '1')
;
});
}
}
31 changes: 31 additions & 0 deletions tests/Browser/AlpineV3/XModelComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Tests\Browser\AlpineV3;

use Livewire\Component as BaseComponent;

class XModelComponent extends BaseComponent
{
public $show = false;

public function render()
{
return
<<<'HTML'
<div>
<div x-data="{ checks: [] }">
<button dusk="show" wire:click="$toggle('show')">Toggle Options</button>

<div>
@if ($show)
<input dusk="plz-check-me-caleb" type="checkbox" x-model.number="checks" value="1" /> Check me
@endif
</div>

<div>Checks value: <span dusk="alpineChecksValue" x-text="checks"></span></div>
<div>Number of checks: <span dusk="alpineChecksLength" x-text="checks.length"></span></div>
</div>
</div>
HTML;
}
}
2 changes: 1 addition & 1 deletion tests/Browser/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<meta name="csrf-token" content="{{ csrf_token() }}">

@if (config('use_alpine_v3'))
<script src="https://unpkg.com/alpinejs@3.11.0/dist/cdn.min.js" defer></script>
<script src="https://unpkg.com/alpinejs@3.12.0/dist/cdn.min.js" defer></script>
@else
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.8.2/dist/alpine.min.js" defer></script>
@endif
Expand Down