-
-
Notifications
You must be signed in to change notification settings - Fork 312
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
cc414dc
commit e2ca326
Showing
18 changed files
with
270 additions
and
13 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
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
43 changes: 43 additions & 0 deletions
43
src/LiveComponent/assets/test/controller/dispatch-event.test.ts
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,43 @@ | ||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import {createTest, initComponent, shutdownTests} from '../tools'; | ||
|
||
describe('LiveController Event Dispatching Tests', () => { | ||
afterEach(() => { | ||
shutdownTests() | ||
}); | ||
|
||
it('dispatches events sent from an AJAX request', async () => { | ||
const test = await createTest({ }, (data: any) => ` | ||
<div ${initComponent(data, { | ||
name: 'simple-component', | ||
})}>Simple Component!</div> | ||
`); | ||
|
||
let eventCalled = false; | ||
test.element.addEventListener('fooEvent', (event: any) => { | ||
eventCalled = true; | ||
expect(event.detail).toEqual({ foo: 'bar' }); | ||
}); | ||
|
||
test.expectsAjaxCall() | ||
.willReturn(() => ` | ||
<div ${initComponent({}, { browserDispatch: [ | ||
{ event: 'fooEvent', payload: { foo: 'bar' } } | ||
]} | ||
)}>Simple Component!</div> | ||
`); | ||
|
||
await test.component.render(); | ||
expect(eventCalled).toBe(true); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -14,11 +14,13 @@ | |
use Symfony\Contracts\Service\Attribute\Required; | ||
|
||
/** | ||
* Trait with shortcut methods useful for live components. | ||
* | ||
* @author Ryan Weaver <[email protected]> | ||
* | ||
* @experimental | ||
*/ | ||
trait ComponentEmitsTrait | ||
trait ComponentToolsTrait | ||
{ | ||
private LiveResponder $liveResponder; | ||
|
||
|
@@ -45,4 +47,9 @@ public function emitSelf(string $eventName, array $data = []): void | |
{ | ||
$this->liveResponder->emitSelf($eventName, $data); | ||
} | ||
|
||
public function dispatchBrowserEvent(string $eventName, array $payload = []): void | ||
{ | ||
$this->liveResponder->dispatchBrowserEvent($eventName, $payload); | ||
} | ||
} |
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.