-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LiveComponent] fix required select not initialized
- Loading branch information
Showing
6 changed files
with
91 additions
and
2 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
30 changes: 30 additions & 0 deletions
30
src/LiveComponent/tests/Fixtures/Factory/CategoryFixtureEntityFactory.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,30 @@ | ||
<?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\Fixtures\Factory; | ||
|
||
use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\CategoryFixtureEntity; | ||
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory; | ||
|
||
final class CategoryFixtureEntityFactory extends PersistentProxyObjectFactory | ||
{ | ||
protected function defaults(): array|callable | ||
{ | ||
return [ | ||
'name' => self::faker()->name(), | ||
]; | ||
} | ||
|
||
public static function class(): string | ||
{ | ||
return CategoryFixtureEntity::class; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
namespace Symfony\UX\LiveComponent\Tests\Fixtures\Form; | ||
|
||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | ||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
|
@@ -22,6 +23,7 @@ | |
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
use Symfony\Component\Validator\Constraints\Length; | ||
use Symfony\UX\LiveComponent\Tests\Fixtures\Entity\CategoryFixtureEntity; | ||
|
||
/** | ||
* @author Jakub Caban <[email protected]> | ||
|
@@ -41,6 +43,20 @@ public function buildForm(FormBuilderInterface $builder, array $options) | |
'foo' => 1, | ||
'bar' => 2, | ||
], | ||
'required' => false, | ||
]) | ||
->add('choice_required_with_placeholder', ChoiceType::class, [ | ||
'choices' => [ | ||
'bar' => 2, | ||
'foo' => 1, | ||
], | ||
'placeholder' => 'foo', | ||
]) | ||
->add('choice_required_without_placeholder', ChoiceType::class, [ | ||
'choices' => [ | ||
'bar' => 2, | ||
'foo' => 1, | ||
], | ||
]) | ||
->add('choice_expanded', ChoiceType::class, [ | ||
'choices' => [ | ||
|
@@ -64,6 +80,10 @@ public function buildForm(FormBuilderInterface $builder, array $options) | |
], | ||
'multiple' => true, | ||
]) | ||
->add('entity', EntityType::class, [ | ||
'class' => CategoryFixtureEntity::class, | ||
'choice_label' => 'name', | ||
]) | ||
->add('checkbox', CheckboxType::class) | ||
->add('checkbox_checked', CheckboxType::class) | ||
->add('file', FileType::class) | ||
|
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 |
---|---|---|
|
@@ -17,13 +17,16 @@ | |
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
use Symfony\UX\LiveComponent\Test\InteractsWithLiveComponents; | ||
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\Component2; | ||
use Symfony\UX\LiveComponent\Tests\Fixtures\Factory\CategoryFixtureEntityFactory; | ||
use Zenstruck\Foundry\Test\ResetDatabase; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
final class InteractsWithLiveComponentsTest extends KernelTestCase | ||
{ | ||
use InteractsWithLiveComponents; | ||
use ResetDatabase; | ||
|
||
public function testCanRenderInitialData(): void | ||
{ | ||
|
@@ -172,6 +175,7 @@ public function testActingAs(): void | |
|
||
public function testCanSubmitForm(): void | ||
{ | ||
CategoryFixtureEntityFactory::createMany(5); | ||
$testComponent = $this->createLiveComponent('form_with_many_different_fields_type'); | ||
|
||
$response = $testComponent->submitForm(['form' => ['text' => 'foobar']])->response(); | ||
|
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 |
---|---|---|
|
@@ -13,14 +13,21 @@ | |
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\UX\LiveComponent\Tests\Fixtures\Component\FormComponentWithManyDifferentFieldsType; | ||
use Symfony\UX\LiveComponent\Tests\Fixtures\Factory\CategoryFixtureEntityFactory; | ||
use Zenstruck\Foundry\Test\ResetDatabase; | ||
|
||
/** | ||
* @author Jakub Caban <[email protected]> | ||
*/ | ||
class ComponentWithFormTest extends KernelTestCase | ||
{ | ||
use ResetDatabase; | ||
|
||
public function testFormValues(): void | ||
{ | ||
$category = CategoryFixtureEntityFactory::createMany(5); | ||
$id = $category[0]->getId(); | ||
|
||
$formFactory = self::getContainer()->get('form.factory'); | ||
$component = new FormComponentWithManyDifferentFieldsType($formFactory); | ||
$component->initialData = [ | ||
|
@@ -36,9 +43,12 @@ public function testFormValues(): void | |
'textarea' => '', | ||
'range' => '', | ||
'choice' => '', | ||
'choice_required_with_placeholder' => '', | ||
'choice_required_without_placeholder' => '2', | ||
'choice_expanded' => '', | ||
'choice_multiple' => ['2'], | ||
'select_multiple' => ['2'], | ||
'entity' => (string) $id, | ||
'checkbox' => null, | ||
'checkbox_checked' => '1', | ||
'file' => '', | ||
|