Add test for isDirty

This commit is contained in:
philipp lang 2024-04-19 11:38:53 +02:00
parent 594c45aede
commit e08ad63313
5 changed files with 36 additions and 4 deletions

View File

@ -11,6 +11,13 @@ class IsDirtyAction
{
use AsAction;
public function rules(): array
{
return [
'config' => 'array|present',
];
}
public function handle(Form $form, ActionRequest $request): JsonResponse
{
$form->config = $request->input('config');

View File

@ -23,9 +23,9 @@ class TextField extends Field
];
}
public static function default(): string
public static function default(): ?string
{
return '';
return null;
}
public static function fake(Generator $faker): array

View File

@ -39,7 +39,7 @@ class FormtemplateFieldRequest extends RequestFactory
'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6],
'nami_type' => null,
'for_members' => true,
'hint' => '',
'hint' => null,
];
}

View File

@ -54,7 +54,7 @@ class FormtemplateIndexActionTest extends TestCase
'name' => '',
'type' => 'TextField',
'columns' => ['mobile' => 2, 'tablet' => 4, 'desktop' => 6],
'value' => '',
'value' => null,
'nami_type' => null,
'for_members' => true,
'special_type' => null,

View File

@ -0,0 +1,25 @@
<?php
namespace Tests\Feature\Form;
use App\Form\Models\Form;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class IsDirtyActionTest extends FormTestCase
{
use DatabaseTransactions;
public function testItChecksIfFormIsDirty(): void
{
$this->login()->loginNami();
$form = Form::factory()->fields([
$this->textField(),
])->create();
$this->postJson(route('form.is-dirty', ['form' => $form]), ['config' => $form->config->toArray()])->assertJsonPath('result', false);
$modifiedConfig = $form->config->toArray();
data_set($modifiedConfig, 'sections.0.name', 'mod');
$this->postJson(route('form.is-dirty', ['form' => $form]), ['config' => $modifiedConfig])->assertJsonPath('result', true);
}
}