opnform/tests/Feature/Forms/CreateDynamicSelectOptionTe...

29 lines
1.0 KiB
PHP
Raw Permalink Normal View History

2022-09-20 19:59:52 +00:00
<?php
2024-02-23 10:54:12 +00:00
2022-09-20 19:59:52 +00:00
use Tests\Helpers\FormSubmissionDataFactory;
it('can submit form with dyanamic select option', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$form = $this->createForm($user, $workspace);
2024-02-23 10:54:12 +00:00
2022-09-20 19:59:52 +00:00
$selectionsPreData = [];
$form->properties = collect($form->properties)->map(function ($property) use (&$selectionsPreData) {
2024-02-23 10:54:12 +00:00
if (in_array($property['type'], ['select', 'multi_select'])) {
$property['allow_creation'] = true;
$selectionsPreData[$property['id']] = ($property['type'] == 'select') ? 'New single select - '.time() : ['New multi select - '.time()];
2022-09-20 19:59:52 +00:00
}
2024-02-23 10:54:12 +00:00
2022-09-20 19:59:52 +00:00
return $property;
})->toArray();
$form->update();
$formData = FormSubmissionDataFactory::generateSubmissionData($form, $selectionsPreData);
$this->postJson(route('forms.answer', $form->slug), $formData)
->assertSuccessful()
->assertJson([
'type' => 'success',
2024-02-23 10:54:12 +00:00
'message' => 'Form submission saved.',
2022-09-20 19:59:52 +00:00
]);
2024-02-23 10:54:12 +00:00
});