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 May 13, 2024
1 parent fec07e5 commit 268b2df
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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');

self::assertSelectorAttributeContains('p[id="content"]', 'class', 'second new');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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';

#[LiveAction]
public function click(): void
{
$this->class = 'new';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<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>
</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 268b2df

Please sign in to comment.