-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
09a38ed
commit ae6f279
Showing
7 changed files
with
191 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
namespace Leuverink\Bundle\Tests\Browser; | ||
|
||
use Leuverink\Bundle\Tests\DuskTestCase; | ||
|
||
// Pest & Workbench Dusk don't play nicely together | ||
// We need to fall back to PHPUnit syntax. | ||
|
||
class AlpineIntegrationTest extends DuskTestCase | ||
{ | ||
/** @test */ | ||
public function it_can_bootstrap_alpine_via_import() | ||
{ | ||
$browser = $this->blade(<<< 'HTML' | ||
<x-import module="~/bootstrap/alpine" /> | ||
<div | ||
id="component" | ||
x-text="message" | ||
x-data="{ | ||
message: 'Hello World!' | ||
}" | ||
></div> | ||
HTML); | ||
|
||
// Doesn't raise console errors | ||
$this->assertEmpty($browser->driver->manage()->getLog('browser')); | ||
|
||
$browser->assertSeeIn('#component', 'Hello World!'); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_bootstrap_plugins_via_import() | ||
{ | ||
$browser = $this->blade(<<< 'HTML' | ||
<x-import module="~/bootstrap/alpine" /> | ||
<div | ||
id="component" | ||
x-text="message" | ||
x-data="{ | ||
message: 'Hello World!' | ||
}" | ||
></div> | ||
HTML); | ||
|
||
// Doesn't raise console errors | ||
$this->assertEmpty($browser->driver->manage()->getLog('browser')); | ||
|
||
$browser->assertSeeIn('#component', 'Hello World!'); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_use_other_imports_inside_x_init_directive() | ||
{ | ||
$browser = $this->blade(<<< 'HTML' | ||
<x-import module="~/bootstrap/alpine" /> | ||
<x-import module="lodash/filter" as="filter" /> | ||
<div | ||
id="component" | ||
x-init=" | ||
const filter = await _import('lodash', 'filter'); | ||
let data = [ | ||
{ 'name': 'Foo', 'active': false }, | ||
{ 'name': 'Hello World!', 'active': true } | ||
]; | ||
// Filter only active | ||
let filtered = filter(data, o => o.active) | ||
$el.innerHTML = filtered[0].name | ||
" | ||
></div> | ||
HTML); | ||
|
||
// Doesn't raise console errors | ||
$this->assertEmpty($browser->driver->manage()->getLog('browser')); | ||
|
||
$browser->assertSeeIn('#component', 'Hello World!'); | ||
|
||
} | ||
|
||
/** @test */ | ||
public function it_can_use_other_imports_inside_x_data_directive() | ||
{ | ||
$browser = $this->blade(<<< 'HTML' | ||
<x-import module="~/bootstrap/alpine" /> | ||
<x-import module="lodash/filter" as="filter" /> | ||
<div | ||
id="component" | ||
x-data=" | ||
async init() { | ||
const filter = await _import('lodash', 'filter'); | ||
let data = [ | ||
{ 'name': 'Foo', 'active': false }, | ||
{ 'name': 'Hello World!', 'active': true } | ||
]; | ||
// Filter only active | ||
let filtered = filter(data, o => o.active) | ||
$el.innerHTML = filtered[0].name | ||
} | ||
" | ||
></div> | ||
HTML); | ||
|
||
// Doesn't raise console errors | ||
$this->assertEmpty($browser->driver->manage()->getLog('browser')); | ||
|
||
$browser->assertSeeIn('#component', 'Hello World!'); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,6 +1,8 @@ | ||
{ | ||
"devDependencies": { | ||
"bun": "^1.0.21", | ||
"lodash": "^4.17.21" | ||
"lodash": "^4.17.21", | ||
"alpinejs": "^3.13.3", | ||
"@alpinejs/persist": "^3.13.3" | ||
} | ||
} |
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,3 @@ | ||
export default function(message) { | ||
export default function alert(message) { | ||
alert(message) | ||
} |
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,10 @@ | ||
import Alpine from "alpinejs"; | ||
import persist from '@alpinejs/persist' | ||
|
||
Alpine.plugin(persist) | ||
|
||
export default (() => { | ||
window.Alpine = Alpine; | ||
|
||
Alpine.start(); | ||
})(); |
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,7 @@ | ||
import Alpine from "alpinejs"; | ||
|
||
export default (() => { | ||
window.Alpine = Alpine; | ||
|
||
Alpine.start(); | ||
})(); |