-
-
Notifications
You must be signed in to change notification settings - Fork 364
[LiveComponent] Add a new helper to interact with forms in functional tests #1992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is beautiful! I thought adding this would be much more complex!
@@ -3659,7 +3659,7 @@ uses Symfony's test client to render and make requests to your components:: | |||
|
|||
// call live action with file uploads | |||
$testComponent | |||
->save('processUpload', files: ['file' => new UploadedFile(...)]); | |||
->call('processUpload', files: ['file' => new UploadedFile(...)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well spotted!
@@ -3672,6 +3672,10 @@ uses Symfony's test client to render and make requests to your components:: | |||
->set('count', 99) | |||
; | |||
|
|||
// Submit form data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should create an entire block "Test LiveComponent with Forms" (or something like that), wdyt ?
If "no", i think some comment to precise what is "form" and "save" here could avoid some missunderstandings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As Test helper is only one block, I didn't want to change that. But I understand that my array is a bit confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep as it is..
Who knows, mabe if you add other nice helpers... we will be forced to add a dedicated block ? :))
|
||
foreach ($values as $key => $value) { | ||
if (\is_array($value)) { | ||
$result += $this->flattenFormValues($value, $prefix.$key.'.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No difference array_is_list / map ? (geniune question)
Does this work with fields accepting multiple values ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know how to use array_is_list
here. With array_map
I can't handle keys.
Yes, I was a little undecided to not add a test for that method. At first I've thinked to add a public static method in Symfony\UX\LiveComponent\Util\LiveFormUtility
which could be easily tested. But I don't know if it make sence as it will be created only for test purpose.
But this will work.
public function testFlatten(): void
{
$data = [
'foo' => ['bar' => 'baz'],
'collection' => ['one', 'two', 'three'],
'collection_with_sub' => [
'sub_one' => ['child_one', 'child_two'],
'sub_two' => ['child_three', 'key' => 'child_four'],
],
];
$this->assertSame([
'foo.bar' => 'baz',
'collection.0' => 'one',
'collection.1' => 'two',
'collection.2' => 'three',
'collection_with_sub.sub_one.0' => 'child_one',
'collection_with_sub.sub_one.1' => 'child_two',
'collection_with_sub.sub_two.0' => 'child_three',
'collection_with_sub.sub_two.key' => 'child_four',
], TestLiveComponent::flattenFormValues($data));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good for me then, thank you for taking time to answer :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
71be401
to
b23eaee
Compare
So great, thanks @yoye! |
Add a new method in
TestLiveComponent
to interact with live components that contains forms. Submitted data must be passed as an array like you'll do withKernelBrowser
.