-
-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LiveComponent] Tests class merging with whitespaces
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/LiveComponent/tests/Integration/LiveController/LiveControllerTest.php
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,32 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\LiveComponent\Tests\Integration\LiveController; | ||
|
||
use Symfony\Component\Panther\PantherTestCase; | ||
|
||
/** | ||
* @author Alexander Hofbauer <alex@derhofbauer.at> | ||
*/ | ||
class LiveControllerTest extends PantherTestCase | ||
{ | ||
public function testWhitespaceClasses(): void | ||
{ | ||
$client = self::createPantherClient(); | ||
$client->request('GET', '/whitespace-classes'); | ||
$client->clickLink('Remove class and render'); | ||
|
||
// wait required to run live_controller JS | ||
$client->waitFor('#changed', 10); | ||
|
||
self::assertSelectorAttributeContains('p#content', 'class', 'second new'); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/LiveComponent/tests/app/src/Twig/Component/WhitespaceClasses.php
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,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace App\Twig\Component; | ||
|
||
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; | ||
use Symfony\UX\LiveComponent\Attribute\LiveAction; | ||
use Symfony\UX\LiveComponent\Attribute\LiveProp; | ||
use Symfony\UX\LiveComponent\DefaultActionTrait; | ||
|
||
/** | ||
* @author Alexander Hofbauer <alex@derhofbauer.at> | ||
*/ | ||
#[AsLiveComponent('whitespace_classes')] | ||
final class WhitespaceClasses | ||
{ | ||
use DefaultActionTrait; | ||
|
||
#[LiveProp] | ||
public string $class = 'third'; | ||
|
||
#[LiveProp] | ||
public bool $changed = false; | ||
|
||
#[LiveAction] | ||
public function click(): void | ||
{ | ||
$this->class = 'new'; | ||
$this->changed = true; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/LiveComponent/tests/app/templates/components/whitespace_classes.html.twig
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,25 @@ | ||
<div{{ attributes }}> | ||
<p | ||
id="content" | ||
class=" | ||
first | ||
second | ||
{{ class }} | ||
" | ||
> | ||
<span>Class: {{ class }}</span> | ||
</p> | ||
|
||
<a | ||
href="#" | ||
data-action="live#action" | ||
data-live-action-param="click" | ||
onclick="document.querySelector('p').classList.remove('first')" | ||
> | ||
Remove class and render | ||
</a> | ||
|
||
{% if changed %} | ||
<div id="changed"></div> | ||
{% endif %} | ||
</div> |
5 changes: 5 additions & 0 deletions
5
src/LiveComponent/tests/app/templates/whitespace_classes.html.twig
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,5 @@ | ||
{% extends 'base.html.twig' %} | ||
|
||
{% block body %} | ||
<twig:whitespace_classes /> | ||
{% endblock %} |