Skip to content

Commit

Permalink
[LiveComponent] Tests class merging with whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
aleho committed Jun 11, 2024
1 parent 61a269d commit dc0e05c
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
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');
}
}
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;
}
}
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends 'base.html.twig' %}

{% block body %}
<twig:whitespace_classes />
{% endblock %}

0 comments on commit dc0e05c

Please sign in to comment.