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 e115aeb commit 93353e1
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 <[email protected]>
*
* 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 <[email protected]>
*/
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 <[email protected]>
*
* 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 <[email protected]>
*/
#[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 93353e1

Please sign in to comment.